Chapter 8: Loading and Caching Game Resources


Overview

Once you get a nice bitmap or sound, how do you actually get it into your game? Most game books show code examples where the game loads BMP, WAV, or MP3 files directly. This doesn't work in real games. Real games have thousands of bitmaps, sounds, models, and other bits of data. They don't all fit into memory at the same time either. A DVD can store 4.7Gb and the last time I looked my PC had only a fraction of that amount of RAM. So how do developers really incorporate sounds and bitmaps into their games?

They convert them to the smallest possible useable format, and pack them all into a simple flat file, usually called a resource file. By the way, just in case I haven't mentioned it, I tend to use the terms game assets and game resources to mean the same thing—they are all game data. Art, sounds, AI, map levels, are all game assets.

Each game resource you use must be converted to the smallest possible format without compromising its quality. This is pretty easy for sounds, since you can easily predict the quality and size delta of a 44KHz stereo WAV versus an 11KHZ mono WAV stream. Bitmaps are trickier to work with, on the other hand, because the best storage format is completely dependent on its use in the game and what it looks like.

That's only the first part as you'll learn in this chapter. Since these resources are usually packed into a resource file or resource database, game companies usually write their own tools to create these files. You'll see an example of one I've used for the last few years, and while they aren't terribly complicated to write they always mirror the particular needs of your game.

Finally, a game has to have some internal mechanism to load desired resources. Depending on the game design it might also need a resource cache, a technology that can keep common resources resident in memory but also predict what resources are about to be needed by the game.




Game Coding Complete
Game Coding Complete
ISBN: 1932111751
EAN: 2147483647
Year: 2003
Pages: 139

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net