I've seen many a time in source code, things like this [well, this is more of a pseudo C++ idea of mine]
typedef shared_ptr ResourcePtr;// for ease
ResourcePtr sound1 = resourceManager.Get("boom.ogg");
sound1->Play();
ResourcePtr sprite = resourceManager.Get("sprite.png");
I was just wondering how useful a class like this was, something that:
- Loaded media files
- Stored them in memory
- Did this at the start of a level - loading screen.
- Cleaned up
Rather than having a system of:
- Resources are held by entities only, or loose.
- Responsible for own load into memory.
The first is a 'manager' as such; something I feel indicates it's wrong to use. However, it allows for something like a vector of resource names to be passed, rather than having to scramble around finding everything that needs to be loaded.
Answer
A good resource manager is key to how well - and how flexible - your game 'engine' is going to be.
Not only does it solve a lot of problems with low level resource management, but it also helps to ensure that resources are loaded only once, and then reused if they are already loaded.
If the resource system is abstracted well, the underlying details can wary between file system, physfs storage, sql even...
You just request a resource, and it's given to you.
No need to worry about resource IDs and stuff like that.
Duplicate resource conflict handling, etc.
Let the resource manager sort that out.
Depending on how you design it - if C++ then make friends with your scenemanaging class(es) to ensure that ownership is properly handled.
Resource pool ?
No problem.
Forgetting to release resources?
No problem.
Same interface to resources no matter where they are: memory, disk, archive, network.
No problem.
Do you want streaming?
Threading?
Let your resource management hub take care of that.
And you can rest assured that it will inform you when the resources are ready to be used.
Ogre 3D has a very flexible resource management system, but I am sure there are others 'out there'.
No comments:
Post a Comment