• Forum
  • Lounge
  • How does a game resource manager know wh

 
How does a game resource manager know when to load and unload resources?

Does it have to have some knowledge of the current level structure? Does it require hints from other parts of the game code?

Also does anyone know of any books, tutorials, or articles that talk about resource managers in detail?
It depends on how you design the manager.
To me, it would have these qualities:
1.) Load a resource when it is requested for the first time
2.) Have an option to load a resource before it is requested for the first time (preloading before levels, perhaps)
3.) Delete a resource when the game explicitly says to free it. I.e., the game switches maps, it tells the resource manager it doesn't need these textures anymore.

That's the only way it makes sense to me, because the resource manager couldn't possibly know when to load or delete textures on its own. Although I suppose you could abstract a resource class and give it a "lifetime" quality. You would have to handle events and such in the rest of your framework pretty well, such that when some core game event happens it's broadcasted to all of the modules working inside the game and they do what they need with the message.

As for books/tutorials, I don't know of any that focus on this topic specifically.
Check out these books they have some good stuff on resource caches and resource managers.

1 - Game Engine Architecture (MUST HAVE) http://www.amazon.com/dp/1568814135/?tag=stackoverfl08-20

2 - Game Coding Complete http://www.amazon.com/Game-Coding-Complete-Fourth-Edition/dp/1133776574

Them two books should give you the understanding you need to press on.

As for your topic it really all depends on what size and type of game your are making as to how your code resource cache.

If it is a small indie game you most likely can get by with preloading most or if not all your resources into memory at the start depending on how much resources you have. If you can't preload all the resources into memory you would probably break out the preloading to set points in the game (Think loading screen when switching a map or screen).

If you are working on a larger game or have a open world type game you will need to load resources on the fly and you will need a smart resource cache to know when to load something, when to unload something, ect so you avoid as many cache misses as possible.

Your main goal is to avoid reading from the hard drive as much as possible because it is such a VERY SLOW process. If you have to read from the hard drive make sure you grab as much things as you can in that trip. Grabbing 100 resources from the hard drive at once is always better then grabbing 100 resources one at a time over a period of time.

There are so many different ways developers can accomplish this that I won't go into the details but with some research on smart resource caches you should see a few examples of how it can be done.

Does it have to have some knowledge of the current level structure?

For a smart resource cache yes some games will use the level structure to determine what resources are to be loaded and unloaded into the cache. For example lets say you are playing a FPS that is inside a big building with lots of hallways and different floors.

The resource cache could use the natural layout of the building to determine what sections to load. It would then position certain trigger points in critical areas around the building to send messages to the cache that it can unload these resources and load these. These trigger points would be in hallways, stairways and other points where you could reasonably determine where the character would be heading.

But in reality you really shouldn't have to worry about creating a smart resource cache that knows when to load and unload resources to avoid cache misses unless you are working on a quite serious indie project or a AAA quality game. Though it is a fascinating subject if you are interested in it.
Last edited on
From my experience I've never felt the need to try and make the engine like a garbage collector. What I'm working on right now just releases things from memory when it's super obvious it's not need anymore, i.e editing a different tileset, or creating a new map. Just give it instructions to follow and tell it when to execute them, resource managers don't have to be extremely complex in hobbyist games.
Topic archived. No new replies allowed.