Loading resources in the background

Started by iyasu, April 16, 2005, 03:45:39

Previous topic - Next topic

iyasu

When searching for multithread, it's stated that all opengl operations should occur in the same thread.
What if I need to load many things at the beginning of each level of the game, and  render a loading screen (and even the mouse cursor) so the screen doesn't hang?

Would parsing every file (meshes) to data structures in a thread, then come back to main thread to parse these new objects so opengl can load their textures be a good solution?

Thanks in advance.

princec

I solved this the usual way without using threads, by using a straightforward callback mechanism.

If you have some "Loader" object that is told to load a set of things, it can call a method "onLoaded()" on some "LoaderListener". What I do is put up my loading screen, update the display, and start loading stuff one at a time, and every time it loads a thing it calls back onLoaded(), at which point I redraw the display with a tweaked progress bar.

Cas :)

iyasu

I kinda see your point. This would give a chance so the Renderer can update screen when a single resource is loaded.
But wouldn't that freeze the screen (and input handling) between onLoaded() calls?
I know freezing sometimes is unavoidable, but I don't want to make the game too unresponsive to the player.