Sign in to follow this  
Kenny77

Resource and State Management

Recommended Posts

I find whenever I start a project it always gets halted by something related to state or resource management. The only solution I can think up is to have certain states load and delete resources that they need, but I always have a problem with objects needing to interact between states (music continually playing through the menu, user information being available in the menu and during gameplay). Basically I'm still struggling to find a way to organize everything in way that is efficient and organized. Is there any books or articles that address this sort of issue in game development?

Share this post


Link to post
Share on other sites
I can't imagine very many cases where you would actually want to tie resources to a particular game state. Sure the state might require a particular resource like the Title Screen music but you may also want music during play so to tie music to the title screen state would be counter productive to say the least.

Basicly state management and resource management are two different areas of your system and should not have many, if any, dependencies; resource load state withstanding, but even then its just a state were resources are loaded and does not imply dependency.

There is decent templated resource holder article here, I used it as inspiration for my own asset holder except that I went for a 'fat' self managed asset holder ie. no manager class.

Once you have a robust resource management system I think you will find things alot easier. I think this is the main issue you are having and you are just over-complicating the problem by thinking about states at the same time.

Now if I overlooked something then please someone step in and cut me down to size :)

Michael

Share this post


Link to post
Share on other sites
Quote:
Original post by Kenny77
I find whenever I start a project it always gets halted by something related to state or resource management. The only solution I can think up is to have certain states load and delete resources that they need, but I always have a problem with objects needing to interact between states (music continually playing through the menu, user information being available in the menu and during gameplay).

Basically I'm still struggling to find a way to organize everything in way that is efficient and organized. Is there any books or articles that address this sort of issue in game development?

I have exactly the same problem and would also like some pointers or tips on how you people handle things like this.

Thanks!

Share this post


Link to post
Share on other sites
I ran into this problem a few times too. The problem is that your states own these resources, as if they're the only ones that need them. What they should do instead is refer to these resources. A resource management system can take care of the ownership (e.g. creating resources when a state asks for them, removing them when they're no longer used). That goes for user information, music, graphics, etc. Some states need to display some user information, some need to use it, some need to modify it, but none of these should actually own the information.

So, on one hand, you have your user info, your texture cache, your audio system, and on the other hand, you have your states.

Share this post


Link to post
Share on other sites
Check my site in my sig for an article that I recently wrote on game state management. As far as resources go, there is no reason for resources to be tied to the states. The way it sounds like you're doing it is without an independent resource manager, just manually loading the resources that the state needs on enter and cleaning them up on exit. With a resource manager, you can still load resources on a state by state basis, but they will be placed into a central holder that can be accessed from all states AND they are not freed until they are no longer being used by any state.

In short, just let all states hold a pointer to ResourceManager.

Share this post


Link to post
Share on other sites
So should I assign ID's to all of my resources and just make them available globally? Then load/delete them when a state needs it/doesn't need it?

This leads me to my (hopefully) last few questions about this. What should I do with things like the main screen and music (that needs to be played over multiple menu states)? Should I make it global as well? Or is there a better way to handle these?

Sorry about all these questions, I've just never seen a complete article or example on this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this