Sign in to follow this  
ProgrammerZ

Resource management suggestions

Recommended Posts

Hey guys. I'm working on a resource manager for my game engine and I wanted some feedback/suggestions on my system: The game engine will instantiate one ResourceManager. The ResourceManager will in turn initialize a number of ResourceSystems, which are derived from a base ResourceSystem<T> class. ResourceSystems have a std::vector<T> m_Resources member. There is also a Resource class, which has a file name and a reference count. Specific resources (Mesh, Texture, Sound, Sprite, etc.) are derived from the Resource class. So, the ResourceManager class will have members such as ResourceSystem<Texture> m_pTextureSystem, etc. When the program requests a resource, the resource system corresponding to the type of resource requested will check to see if the resource already exists. If it does, it will return a handle (unsigned int) to the resource and increment the resource's reference count. If not, it will load the resource and return the handle, setting the new resource's reference count to one. When the program is done with a resource, it will call the ResourceSystem::ReleaseResource(unsigned int handle) function, which decrements the indicated resource's reference count. The ResourceSystem will also have a GetResourceFromHandle member function. The Resource class will have AddRef() and RemoveRef() methods, and a GetRefs() function too. If a resource has no references, its ResourceSystem will delete it. I plan to have my GraphicsManager, SoundManager, etc. classes take handles to resources as arguments to their RenderMesh, PlaySound, etc. member functions. This way, the program only has to know what the handle to the resource is to use it -- in fact, the program doesn't even have to know what a resource is at all. Using handles also prevents users from inadvertedly deleting a pointer and consequently corrupting all other pointers. Any feedback? --ProgrammerZ

Share this post


Link to post
Share on other sites

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

Sign in to follow this