Day 4 - And He Said "Let There be Resources"

posted in Perpetual Alpha
Published November 22, 2004
Advertisement
Didn't get the content of the resource manager done today. I spent all today working on the design. I've never seen the code for a resource manager so my design probably could be better but I don't think it's too bad. I had to figure out how I was going to handle unloading files. My first idea was to load a list of resources into a structure which would unload the resources listed in it when it was deleted. But then I wanted a way to grab the same resources from anywhere. So I combined that plan with my original one from yesterday. I have each type's resource manager hold a list of the loaded resource batches. That way I can grab them from anywhere. The resource manager kernel is a task and so is called every frame. The kernel runs through all the loaded batches to see if any have a reference count of 1 (ie the only thing still storing the resources is the kernel itself), if so it unloads that batch. This should give me an automated way of releasing resource batches, give me access to them everywhere, and shouldn't be too heavy on the system as I only have to check a few batches, not every resource.

The main flaw with the solution is one stage where you have to cast a pointer to the resource manager interface to the resource manager for a specific type. Because I had to use the interface classes, but couldn't use virtual functions for everything I needed, I came up with the following function in the interface class:

template  CSPointer< CResourceManager > CastTo() {	CSPointer< CResourceManager > rPtr((CResourceManager*)this);	return rPtr;}


This lets me cast upwards easilly. It isn't the most ellegant solution but as long as I don't mess up the conversions I should be okay. I shouldn't mess them up anyway because I doubt there'll be anywhere in my code where I mightn't know what type of resource I'm trying to retrieve.

I'm going to go watch TV for a while - I've been killing myself on this resource manager stuff. I got AI Game Engine Programming a few days ago so I'll probably read it for a while too. Its much more implimentation oriented than my other AI book AI Game Developement. It breaks games down into their various genres and describes how to deal with the major AI issues in each. It fairly interesting.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement