Jump to content
  • Advertisement
Sign in to follow this  
lack o comments

need tip for resource manager

This topic is 5151 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

I'm writing a new resource manager (you probably gather that from the thread name =). Anyway, I want to include a database that keeps a list of all filenames used in the project. My question is, would it be advisable to keep the list separate from the actual resource data, or combine them and just use state flags to determine which are loaded and which aren't. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

My resource manager maintains a map of filename to resource tags for a given resource type:

template<typename resource_type> struct resource_tag;
std::map<std::string, resource_tag<myRes> > resources;

The resource tag contains information such as a reference count for intelligent caching; the tag also contains a pointer to the actual resource class:

template<typename resource_type>
struct resource_tag
{
// various attributes...
unsigned int m_refCount;
resource_type* m_pResource;

// increment reference count
void AcquireResource(const std::string& filename)
{
if(m_refCount++ == 0)
{ m_pResource = new resource_type(filename);
}
}

// decrement reference count
void ReleaseResource()
{
if(!--m_refCount)
{ delete m_pResource;
}
}
};

My resource handles update the reference count on a resource tag, and this triggers the load/release of a given resource.

Hope this helps. :)

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.

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!