Game Development Reference
In-Depth Information
shared_ptr<ResHandle> handle =
g_pApp->m_ResCache->GetHandle(&resource);
++loaded;
}
if (progressCallback != NULL)
{
progressCallback(i * 100/numFiles, cancel);
}
}
return loaded;
}
This method uses a simple scheme of wildcard pattern matching that you
ve seen previ-
ously. The resources are iterated as they are ordered in the file, and if they match the
pattern, they are loaded. During the load, a progress callback function can be called to
animateaprogressbar,oritcanbesettoNULLandignored.Withthismethod,you
could preload a number of resources based on a wildcard pattern, which could be set to
a named area or room of a level, for example. If all the resources were very small, this
method could be used to load resources asynchronously.
If you want to find out how your resources are being used, you should instrument your
build. That means you should create a debug build with special code that creates a log
file every time a resource is used. Use this log as a secondary data file to your resource
file creator, and you
'
sbestadvantage.
In open world games, the maximum map density should always leave a little CPU
time to perform some cache chores. Denser areas will spend most of their CPU
time on game tasks for rendering, sound, and AI. Sparse areas will spend more time
preparing the cache for denser areas about to reach the display. The trick is to bal-
ance these areas carefully, guiding the player through pinch points where it
'
ll be able to sequence the file to your game
'
'
s possible,
and never overloading the cache.
If the CPU can
ll probably
suffer a cache miss and risk the player detecting a stutter in the game. Not all is lost,
however, since a cache miss is a good opportunity to catch up on the entire list of
resources that will be needed all at once. This should be considered a worst-case sce-
nario, because if your game does this all the time, it will frustrate players. If you do
this in a first-person shooter, you
'
t keep up with cache requests and other game tasks, you
'
ll end up with a lot of bad reviews.
A better solution is a fallback mechanism for some resources that suffer a cache miss.
Flight simulators and other open architecture games can sometimes get away with
keeping the uncached resource hidden until the cache can load it. Imagine a flight
'
Search WWH ::




Custom Search