Horde3D
http://horde3d.org/forums/

How to show resource loadings progress [NEEDS IMPROVEMENT]
http://horde3d.org/forums/viewtopic.php?f=1&t=688
Page 1 of 2

Author:  Siavash [ 03.04.2009, 09:32 ]
Post subject:  How to show resource loadings progress [NEEDS IMPROVEMENT]

Is it possible to show the progress of resource loading? I mean something like bytes loaded or number of loaded resources.

Author:  Volker [ 03.04.2009, 14:14 ]
Post subject:  Re: How to show resource loadings progress

You may add a callback or something like that into the Horde3DUtils::loadResourcesFromDisk or write your own custom loading code.

Author:  Siavash [ 03.04.2009, 15:58 ]
Post subject:  Re: How to show resource loadings progress

Do you mean something like this :
Code:
   float loadedResPercent;
   
   DLLEXP float getLoadedResPercent()
   {
      return loadedResPercent;
   }

   DLLEXP bool loadResourcesFromDisk( const char *contentDir )
   {
      bool result = true;
      string dir;
      vector< string > dirs;

      // Split path string
      ...
      
      // Get the first resource that needs to be loaded
      int res = Horde3D::queryUnloadedResource( 0 );

      /////////////////////////////////////////////////////////
      // Get the total resource count /////////////////////////
      /////////////////////////////////////////////////////////

      int resCount = 0;
      int loadedResCount =0;
      loadedResPercent = 0;

      while ( Horde3D::queryUnloadedResource( resCount ) )
      {
         resCount++;
      }
      
      resCount = 100 / resCount;

      /////////////////////////////////////////////////////////
      // Get the total resource count /////////////////////////
      /////////////////////////////////////////////////////////
      
      ...
         
         loadedResPercent = loadedResCount * resCount;
         
         // Get next unloaded resource
         res = Horde3D::queryUnloadedResource( 0 );
         loadedResCount++;
      }

      return result;
   }
then how to assign a callback to getLoadedResPercent()?

Author:  Volker [ 03.04.2009, 16:11 ]
Post subject:  Re: How to show resource loadings progress

You have to define a function pointer and pass a pointer to the callback function to loadResourcesFromDisk.

Something like this:
Code:
typedef void (*cbPercent)( int percent );

void callback( int percent )
{
    printf(" %d percent done \n", percent );
}

Horde3DUtils::loadResourcesFromDisk( ".", &callback );


In this case you have to change the signature of loadResourcesFromDisk to
Code:
Horde3DUtils::loadResourcesFromDisk(const char *contentDir, cbPercent funcPtr )

Author:  Siavash [ 03.04.2009, 16:14 ]
Post subject:  Re: How to show resource loadings progress

thanks a lot :D

Author:  SpOOky [ 03.04.2009, 16:23 ]
Post subject:  Re: How to show resource loadings progress [SOLVED]

This is interesting. Would it make its way into horde3d?

Author:  marciano [ 05.04.2009, 12:21 ]
Post subject:  Re: How to show resource loadings progress [SOLVED]

Having a good loading screen is a bit tricky. Just counting the number of unloaded resources will make the progress bar jump back since a loaded resource can have new dependencies. I think the only reliable way is to store a list of all required resources (e.g. for a level) somewhere in a custom text file.

Author:  Siavash [ 05.04.2009, 16:09 ]
Post subject:  Re: How to show resource loadings progress [SOLVED]

marciano wrote:
Having a good loading screen is a bit tricky. Just counting the number of unloaded resources will make the progress bar jump back since a loaded resource can have new dependencies. I think the only reliable way is to store a list of all required resources (e.g. for a level) somewhere in a custom text file.
Unforunately it's a little tedious to store a list of all required resources [manually] in a text file. Perhaps you have a top secret tricky way 8)

Author:  Volker [ 05.04.2009, 17:06 ]
Post subject:  Re: How to show resource loadings progress [SOLVED]

The project is open source, so all secrets are open :-)
As marciano already pointed out, a problem may be the dependencies of resources being loaded. So if you load a scene graph resource, the materials, models, etc. referenced by the scene graph are not known before. And if you trace down all resource dependencies you have at least the scene graph resources loaded already.

Author:  Siavash [ 05.04.2009, 20:09 ]
Post subject:  Re: How to show resource loadings progress [SOLVED]

So we can't count the total resources in code :
Code:
      int resCount = 0;

      while ( Horde3D::queryUnloadedResource( resCount ) )
      {
         resCount++;
      }
     
      resCount = 100 / resCount;
and unfortunately this piece of code would give us the wrong value !?

Author:  swiftcoder [ 06.04.2009, 01:07 ]
Post subject:  Re: How to show resource loadings progress [SOLVED]

Volker wrote:
The project is open source, so all secrets are open :-)
As marciano already pointed out, a problem may be the dependencies of resources being loaded. So if you load a scene graph resource, the materials, models, etc. referenced by the scene graph are not known before. And if you trace down all resource dependencies you have at least the scene graph resources loaded already.
Realistically, the xml files take almost no time to parse, so one only needs to track the number of models, textures and animations. Perhaps it would make sense to separate resource loading into two passes: the first loads all xml files, and thus computes the complete dependency tree, while the second pass loads all the models/animations/textures.

Author:  Siavash [ 06.04.2009, 15:24 ]
Post subject:  Re: How to show resource loadings progress [SOLVED]

swiftcoder wrote:
Realistically, the xml files take almost no time to parse, so one only needs to track the number of models, textures and animations. Perhaps it would make sense to separate resource loading into two passes: the first loads all xml files, and thus computes the complete dependency tree, while the second pass loads all the models/animations/textures.
Yes, I'm agree with you. This is the best approach to solve this problem.

Author:  DarkAngel [ 09.04.2009, 05:18 ]
Post subject:  Re: How to show resource loadings progress [NEEDS IMPROVEMENT]

An alternative that I've seen is to simply load the level in the game, and log all of the resources that get loaded.
A full dependency list is then generated from this log.

If the level is modified, then this step needs to be repeated (e.g. by the level designer).

In the project that I saw this technique used on, this log was also used to optimise packed resources (the order that the resource files are stored in the "pack file" was re-arranged to minimise DVD seeking).

Author:  Siavash [ 09.04.2009, 06:09 ]
Post subject:  Re: How to show resource loadings progress [NEEDS IMPROVEMENT]

Wow, good idea ! I'll have a try.

Author:  DarkAngel [ 09.04.2009, 07:38 ]
Post subject:  Re: How to show resource loadings progress [NEEDS IMPROVEMENT]

TBH, swiftcoder's idea is more robust, but this method could probably be implemented without any changes to Horde.

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/