Game Development Reference
In-Depth Information
if (buffer)
{
zipFile.ReadFile(*index, buffer);
}
}
}
return buffer;
This is about as easy as it gets. After the Zip file is initialized, you find the index to
the name of the file inside the Zip, grab the size, allocate the memory buffer, and
read the bits.
Zip files are a good choice for the base file type of a general purpose resource file
something you can open once and read sounds, textures, meshes, and pretty much
everything else. It
ll use for a
given level in a single Zip file. Even doing this, you might soon discover that the
Zip file for any one level is much bigger than your available memory. Some
resources, like the sounds for your character
'
s a common practice to load all of the resources you
'
s footsteps, will need to be in memory
all the time. Others are used more rarely, like a special sound effect for a machine
that is only activated once.
This problem calls for a cache, and luckily you ' re about to find out how one works.
'
The Resource Cache
If your game has a modest set of graphics and sounds small enough to exist
completely in memory for the life of your game, you don
s still a
good idea to use resource files to pack everything into one file; you ' ll save disk space
and speed up your game
'
t need a cache. It
'
s load time.
Most games are bigger. If your game is going to ship on optical media, you
'
ll have
almost five gigabytes on a DVD and over 25GB on Blu-ray. Optical media will be
larger than the RAM you have. You almost certainly won ' t have enough memory to
load this all at once, but even if you do, you don
'
t want players to wait while the
entire thing is streamed in. What you need is a resource cache
'
a piece of technology
that will sit on top of your resource files and manage the memory and the process of
loading resources when you need them. Even better, a resource cache should be able
to predict resource requirements before you need them.
Resource caches work on similar principles as any other memory cache. Most of the
bits you
ll need to display the next frame or play the next set of sounds are probably
ones you
'
ve used recently. As the game progresses from one state to the next, new
resources are cached in. They might be needed, for example, to play sound effects
'
 
 
Search WWH ::




Custom Search