Jump to content
  • Advertisement
Sign in to follow this  
Gary the Llama

Writing a resource manager...

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

At this point, I'm quite comfortable with C++. I'd like to start putting together a toolset that I can use for games that I write. I know that a resource manager is something I will need... I just have no idea how to implement it. How does it work? What is it managing? Does it handle memory too or is that something different? Also, I'd like to keep it OOP-based, if possible. What would a resource manager class look like? Any tips or nudges in the right direction would be great. (I've done a few Google searches but they didn't help me too much.)

Share this post


Link to post
Share on other sites
Advertisement
Yes, write a working game and try to reuse the components rather than the other way around. Writing components you don't know how or why to use is not of much use.

But to answer your question properly, a resource manager is a piece of code that is an interface to the rest of your game responsible for fetching resources for you. It might look something like:

ResourceManager manager;
manager.loadResourceTable( "resource_list.foo" );

Resource<Sprite> my_sprite;
manager.load( my_sprite, "MyCoolSprite" ); // Where MyCoolSprite is a key in the resource list

Beneath the surface the resource manager might take care of locating the necessary assets and loading them for you, as well as keeping them in system ram as long as necessary in order to keep resource loading during gameplay to a minimum.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
A resource manager just basicly reads/writes to a file containing resources. Kind of like having files inside files. To make one, it all depends what you need, in my experience all I ever needed was size, name e.g.

[source lang=cpp]
struct ResourceHeader{
long size; // Sizeof resource, sometimes you can have resource withing resource like
// /rc/characters/3dparts/plane etc.
long howmany;
long szname;
char* name; // not null terminated in file
};
Then after that just a bunch of resources

struct Resource{
long sizedata;
long szname;
char* name;
void* data;
};

let CF be some file class.

class CRManager{
void* getresource(char* nom)
{
// find resource
// read resource and return it back
}
};


Well its alot of work, but once you make a class you can reuse it over and over. The above is not very effieciant in speed. You might want to add extra things like tables to find resources faster. But speed is not alway's important.

Heres a "Table Psudo code example"
[source lang=cpp]
struct ElementInTable{
long type; // 1 = "pointer" points to a "directory" of more tables 0 = "pointer" points to
// the contents of a file
long szname;
long pointer; // pointer points somewhere in the file
};



There is alot of way's you can make it, optimized for finding resources(loading levels) or optimized for wrting resources (e.g. quick save files).

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!