Original Post
I've been designing a multithreaded resource manager over the past couple days. The basic way that it works is that my main game thread uses a ResourceManager class to manage all the resources (which would be things loaded from the disk, like models, sounds, etc). The ResourceManager uses a ResourceLoader class (which the rest of the game isn't aware of) to load resources that the game requests. The RM communicates with the RL through message passing, and all the resource loading is done in the RL class in a seperate thread. The result is that (hopefully) the game can stream resources on the fly and remain nice and fluid even as stuff is busy being loaded (especially, I hope, on new dual core machines). Now let's say there's these "doodad" things. These doodad things are like props that populate the game world. My example game world is full of tree doodads. In order to create a tree doodad the doodad must refer to a tree model, which contains graphical information as well as other fun stuff like collision info, etc. In other words, to fully create a tree doodad the doodad has to be able to refer to the proper tree model resource. But here's an issue. Let's say I want to create a tree doodad which uses a particular tree model, perhaps Tree01.obj. Inside the doodad's constructor it requests a pointer to the Tree01.obj model, which isn't loaded yet, but the RM sends a message to the RL that it needs to be loaded. Meanwhile the doodad is... doing what? I guess the RM could just return immediately with a NULL pointer when the doodad requests the model, which the doodad understands to mean that the resource is in the process of being loaded. But then what? How does the doodad find out when the model is finally loaded? Polling? Some kind of callback? OR, should doodad creation be done over on the resource loading thread, so that instead of a "resource loading thread" it becomes an "entity creation thread" that handles both loading resources and creating game objects? My game says "put a tree over there," sends a message somewhere, the other thread gets the message, loads the required resources, creates the doodads, and sends a "here's that tree you wanted" message to the game thread. This could work, but it means that so much more stuff is going on in the loading/creation thread that there's a lot more conflicts that could come up that I'd have to put locks around (for instance, my loading thread shouldn't be adding new geometries to the physics engine when the physics engine is busy calculating a timestep) and that could hurt performance. Plus if a resource is already loaded you're wasting a lot of time waiting for messages to be passed around. To summarize, how does World of Warcraft do it?