Archived

This topic is now archived and is closed to further replies.

Austrian Coder

Resource management

Recommended Posts

Hello! At the moment i want to play with resource management. I am in the design step. Until now i have a resource class. Now the harder things come - the resourcemanager. I think that there are in genral 2 different ways to go. 1. One global resource manager for every type of resource (sound, texture, mesh, ...). For instance, gTextureManager will call gResourceManger->AddResource(Texture, RT_TEXTURE). 2. One manager for every type of resource. So the resource manager is included in e.g. gTextureManager. Wich solution do you prefer and why?

Share this post


Link to post
Share on other sites
Guess you won''t like my answer, but I think it depends on the size and type of the game.
Given a game like ''Boulder Dash'' you really don''t need to manage every resource type for itself. Ok, that''s a bad example, but I hope you get my point nevertheless

In other cases, I still have to say that it depends.
If there are many and many resources that are the same in size exactly, you probably want to split them from the other resources.
It''s way easier to deal with them seperately, since your strategy can be very simple _and_ effective.
But if that''s not the case, I don''t think splitting the space up (again) would do any good, a manager for all the remaining objects should then do a better job than four or five.

But even if you split some resource types from the others I think the memory manager for the splitted object should still be able to ''communicate'' with the ''main'' manager.
What if it suddenly needs space for additional tiles?
If they''re cascaded like this, you could perhaps even try to fuse the old and new block for tiles.

To make it short:
Second choice only if they simplify the allocation strategy significantly. Then there should still be a general manager that manages the special manager.
But if that''s the case, this could really help in reducing load.

Share this post


Link to post
Share on other sites
i use a hybrid method of both. i have a cSurfaceManager which makes sure that each texture, surface or whatever is only loaded once. then i have a cSpriteManager, which loads my sprite data from a file (height, width, animation, etc) into the manager. when an object (bullet, enemy, etc) needs to be created, it requests the information from the sprite manager via the filename (the sprite file)and if its in there it returns the information copied (but a pointer to the surface), so sprite information is only loaded once. the sprite manager has a surface manager in it, because the sprites need to manage surfaces, because in the sprite files are paths to bmp files.

you have to think about how resources interact, and how they will be implemented into your game. if all resources can be handled and loaded simularly, make a template class or use polymorphism and derive from a base class to all of your different resources. if your resources are handled differently, (like mine), make your own managers or have a base manager class and derive from that, with virtual load, manage functions.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think it is really going to depend on how your managing your memory and how you intend the resources to be freed / loaded. If you maintain separate allocation pools of memory for each type then you might want to consider having a manager for each resource type. Otherwise a single manager might be the way to go.

How often do you cache out resources? Are you using memory zones, priortizing resources, etc.? Do you ever clear all the registered resources (say, at the end of a level)? At what point are resources actually read into memory, when they are registered or is there a separate call when you resolve a resource handle to a memory pointer? One of the things you need to keep in mind is that your manager is potentialy not going to be able to keep all resources that the game might need in memory at all times. You need to design your manager to be able to quickly swap resources in and out while doing its best to keep the most important and most used resources in memory.

If you do a separate manager do you think that you will be able to coordinate actions between the different managers so that one resource type doesn''t end up using all the memory in the system? Lots of things to keep in mind when doing this.

If you have access to the Game Programming Gems series, there are two or three excellent articles in them on the subject of resource management. For an older, and more linear approach you might want to check out Chris Hargroves'' Code on the Cob series hosted in the articles section on this site, he also designes a resource manager there as well. Your best bet might be to just choose one and go with it. Once you get your game up and running you can profile it and see how effective your approach works. Worst case, you might have to rewrite the implementation code which isn''t so bad if you keep a consistant interface.

Share this post


Link to post
Share on other sites
A. P. you have posted alot of questions, so i will answer them now.

quote:
How often do you cache out resources?

It depends on several factors. If a resource need to be cached out, it will be deleted in the gameloop.

Lets say:

A large terrain with 2 houses on each end. So if i am in the near of city A and i couldn''t see city B, textures, meshes,... of city B will be marked.
Then the taskmanger calls e.g. gResourceManager->FreeUnused(); and so the not needed data will be freed.
If I went now to city B, i dont need the stuff from city A. So B will be loaded and A will be cached out.

So the gResourceManager->FreeUnused() will be called in the beginning of the gameloop.

quote:
Are you using memory zones, priortizing resources, etc.?

Please define memory zones.

I want to use priortizing resources, but until now i haven''t thought much about it.

quote:
Do you ever clear all the registered resources (say, at the end of a level)?

Sure. Lets say you are playing the game and you are want to quite it. So go load the mainmenu (at this point you dont need the level data anymore) and show it.
If you want to go back to the game, the ResourceManager must load all level data again.

quote:
At what point are resources actually read into memory, when they are registered or is there a separate call when you resolve a resource handle to a memory pointer?

The resources are loaded at that point, when they needed. So firstly the will be registrated and the all resources will be loaded.


Sadly to say, i have no access to Game Programming Gems series. But in the next days i will go to the libary and look there.

Greets, Christian

Share this post


Link to post
Share on other sites