Jump to content
  • Advertisement
Sign in to follow this  
ProgrammerZ

Resource management suggestions

This topic is 3677 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Skip the word manager, it's really inappropriate. Then think smart pointers, boost has an awesome one you can use too. So then you can make a resource pool of smart pointers :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!