# How do you deal with graphics & sound management?

This topic is 4105 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

One of the biggest issues I've had since I moved from writing text-based games to writing graphical games is the issue of storing, managing, and rendering graphics, sound, and other resources. I've never really come across a good way to handle storing said resources in a way that doesn't require me to hardcode what resource files are being used where. I'm thinking about c++, my language of choice, but if you have other responses not tied to that language, that would be awesome too. I've looked at the code for other games, and at the files used in professional games. Planescape: Torment (I just started playing it, and that game rocks. Try it.) has a sort of homebrewed scripting file. This file describes, for each type of creature in the game, a specific set of possible actions the creature could take (walking, attacking, etc) and ties that action to a separate resource file. That's all well and good. What confuses me especially is what you do with the resources once you've got them loaded into memory. How do you separate that graphics code from your game code? For example, if you have, say, a "Creature" class that represents any creature in the game world, and an "Object" class that can be any sort of non-moving object (a building, an item on the ground etc), how would you go about separating how the objects interact from how they render themselves? This is a pretty generic example, I know, but I hope you understand what I mean. It seems difficult and unwieldly to do this in an object-oriented manner. Please let me know if this is too rambling, as I'm posting at 1:00 AM and need some sleep. I'll check up on this thread in the morning and clean up my post. Thanks for reading!

##### Share on other sites
1. Resource Management - Personally, I have a base manager class which provides: A logging interface, An interpreter interface, caching for the resources, and a Map from Resource Name to a stored Loading String. Depending on what API is being actually used to display/play/etc various concrete inheritors are used which seed the interpreter with loader functions.

ImageManager.Load("Sheep");

Sheep might be mapped to "load from file" or "load from server". The ImageManager might be instantiated to D3DImageManager or OGLImageManager... Caching is done via boost::weak_ptr. In C++ my interpreter uses boost::spirit/boost::function, in C# a little bit of regex and a little bit of introspection on delegates.

2. Code Seperation - As usual, if two things need to interact, but not 'know' about one another you'll need some sort of message system, function object tie in, or simply another class which knows of both. In my hobby project, I use a combination of the last two. A third class creates the renderable based on an object. It's hardcoded to use "Sheep" as the resource name (and then the resource's loading can be changed via file in the interpreter) for a Sheep object. The game just says:
Renderable SheepView = RenderableFactory.Load(aSheep);

The Sheep is then blissfully ignorant what its representation is and the Renderable doesn't care that it's a poorly drawn sheep sprite. The game and the RenderableFactory know of both, but then again... they need to anyways.

re: function object tie in - Later in that function that loads the SheepView, I might use a function object to listen to aSheep.ChangeColor so that the image matches the underlying data. C# makes this easier than C++, but boost::signals does similar things; anyways, the concept is more important than the implimentation...

Hope that helps, but remember: this is only my current implementation, I'm a relative noob, and there's many ways to achieve a goal.

##### Share on other sites
Interesting -- thanks for the detailed description! I'll have to take another look at the factory pattern, as I've never used it in a practical manner before and it seems to be used in a lot of different ways.

If anyone else has anything to add, that would be great.

##### Share on other sites
I posted an explanation of the Crown and Cutlass resource system a little while ago. Perhaps that will be helpful. The "pre-rewrite" doc links are bad, I think we accidentally overwrote that data. I'll fix that and edit my post when they are working again.

Edit: We fixed the "pre-rewrite" docs...

[Edited by - Mr Grinch on June 27, 2007 1:36:06 PM]

##### Share on other sites
Quote:
 Original post by Mr GrinchI posted an explanation of the Crown and Cutlass resource system a little while ago. Perhaps that will be helpful. The "pre-rewrite" doc links are bad, I think we accidentally overwrote that data. I'll fix that and edit my post when they are working again.

Wow -- that's a really nice system, pretty much just what I was looking for in terms of resource management. Watch as I steal your ideas!

Thanks very much for sharing it.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
12

• 9
• 22
• 16
• 9
• 17
• ### Forum Statistics

• Total Topics
632609
• Total Posts
3007398

×