Page 1 of 1

ResourceBackgroundQueue Tutorial

Posted: Thu Dec 11, 2008 3:46 pm
by Moohasha
Not really a "feature" request, but not really Help either. I would like to use ResourceBackgroundQueue to load resources in the background, but don't know how, and looking through the forums it looks like it's easy to make obvious mistakes trying to use it (like not compiling Ogre with OGRE_THREAD_SUPPORT defined.) It would be very helpful if there was a tutorial on the wiki or something about loading resources in the background.
Oh, I guess I do have a feature request. Enabling thread support shouldn't involve recompiling Ogre, as some people (like me) just download the binaries. It should either be a preprocessor definition that doesn't involve recompiling Ogre, or a function call at startup.

Re: ResourceBackgroundQueue Tutorial

Posted: Wed Dec 24, 2008 4:05 pm
by scratchyrice
I second this. Im currently in the procsess of learning to use background resources, So i may do a small guide my self. But we still should not have to recompile the whole libary to enable mutlithreading.

Re: ResourceBackgroundQueue Tutorial

Posted: Fri Dec 26, 2008 10:44 am
by Azgur
scratchyrice wrote: But we still should not have to recompile the whole libary to enable mutlithreading.
It makes sense in a way. Threading will introduce locking at places where it wouldn't be needed otherwise.
This might be a small performance impact you wouldn't want if you're not using threading.

That's my guess at least.

Re: ResourceBackgroundQueue Tutorial

Posted: Fri Dec 26, 2008 3:18 pm
by Moohasha
Azgur wrote:It makes sense in a way. Threading will introduce locking at places where it wouldn't be needed otherwise.
You're right, but that's only if threading is enabled and you aren't using it. I'm talking about having some preprocessor definition in YOUR apps (rather than Ogre), or some function call that enables/disables threading, either at linkage or startup. Qt does this with a preprocessor. You have to #define QT_THREAD_SUPPORT in order to use the classes QThread and QMutex. You don't have to rebuild Qt.
I've looked at the source code, but not well enough to know how the threading works, but it sounds like there's one background thread to load resources, and all ResourceManagers have a mutex to make them thread safe, in which case it might be something as simple as:

Code: Select all

void ResourceManager::enableBackgroundLoading(bool enable)
{
     if (enable)
     {
          // Start background thread
          // Instanciate shared mutex
          // Anything else to support threading
     }
}