Game Development Reference
In-Depth Information
files can be pretty complicated
much more so than simply opening a JPG or an
MP3 file.
A resource cache is one of those hidden systems I told you about. An open world
game like Grand Theft Auto has gigabytes of art and sound, and the system only
has a fraction of the memory needed to load everything. Let me explain why a
resource cache is important with a little metaphor. Imagine the problem of getting a
crowd of people out of a burning building. Left to their own devices, the crowd will
panic, attempt to force themselves through every available exit, and only a small frac-
tion of the people will escape alive.
Now imagine another scenario, where the evacuation is completely organized. The
crowd would divide themselves into single file lines, each line going out the nearest
exit. If the lines don
'
t cross, people could almost run. It would be very likely that
even a large building could be completely evacuated.
This analogy also works well for game resources. The burning building is your slow
optical media, and the doors are the limited bandwidth you have for streaming this
media. The bits in your resource file represent the crowd. Your job is to figure out a
way to get as many of the bits from the optical media into memory in the shortest
possible time. That
'
s not the entire problem, though. A resource cache is exactly what
the name implies
commonly used assets like the graphics for the HUD are always
in memory, and rarely used assets like the cinematic endgame are only in memory
while it
s playing, and most likely only a piece of it at that.
The resource cache manages assets like these in a way that fools the game into think-
ing that they are always in memory. If everything works well, the game will never
have to wait for anything, since the resource cache should be smart enough to predict
which assets will be used and load them before they are needed.
Every now and then, the cache might miscalculate and suffer a cache miss. Depend-
ing on the resource, the game might be able to continue without it until it has been
loaded, such as the graphics for an object in the far distance. In that case, the
graphic can fade in once it is safely in memory. In other cases, the game isn
'
'
tso
'
lucky, such as a missing audio file for a character
s lines. Since they are synched to
the facial animations, the game has to wait until the audio is loaded before the char-
acter can begin speaking. If it does that, players will notice a slight pause or
hitch
in the game.
So it
s not enough to write a little cache that knows whether resources exist in
memory at the moment they are needed. It has to be clever, predicting the future
to some extent and even providing the game with a backup in case the cache suffers
a miss.
'
Search WWH ::




Custom Search