Integration Day

posted in I am a duck
Published April 05, 2006
Advertisement
This morning I worked on integrating my resource manager into my game. The good news is that I didn't have any problems with the new code. It all ran flawlessly thanks to getting most of the bugs ironed out with unit tests. The tricky part was getting my game to use it properly. Up until now I've just had my scene classes loading up the textures it wanted, when it wanted it. Being on the multi-threaded kick I wanted to make my resource manager run on it's own thread. This actually has some good uses beyond just being fun.

One of the problems with D3D on a PC is losing a device. This can happen when someone changes resolution or when the stars become misalligned. When this happens you have to release all your textures, reset the device and reload your textures. When this becomes trickier is when you start throwing multiple threads into the mix. What I found out in the early work on my engine is that you need to use the same thread that creates the textures to release the textures. Depending on how you have your threads working this can actually be a bit tricky. Having a resource manager running on it's own thread solves this problem. Since it handles all loading and releasing of textures you always have the same thread doing that work. Good stuff.

Of course life isn't always simple. My scene objects now have to ask the resource manager to load something. This is done by sending a message to the manager. Not wanting to create any blocks on my threads I made this an asyncronous action. So the scene makes the request and then just goes on it's merry way doing whatever other work it wants. When the resource manager is done loading things it sends a message back to the scene along with a pointer to the new texture object. Add a message handling function to the scene and everything is working. Next step is handling the loading of audio resources this way as well.
0 likes 1 comments

Comments

Mushu
Threads are evil!

(oh, and thanks for reminding me about unit testing :D)
April 05, 2006 10:36 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement