Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

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

Sign in to follow this  
Stephen R


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.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!