Writing a resource manager...

Started by
1 comment, last by GameDev.net 18 years, 8 months ago
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.)
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.
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
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 resourcesstruct 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 filelong 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).

This topic is closed to new replies.

Advertisement