Game Development Reference
In-Depth Information
have tons of CPU horsepower, and resource management can certainly get its own
thread. The problem is going to be synchronization and keeping all the CPUs from
stalling.
Caching Resources into DirectX et al.
Luckily for you, DirectX objects such as sound effects, textures, and even meshes can
all load from a memory stream. For example, you can load a DirectX texture using
the D3DXCreateTextureFromFileInMemory() API, which means loading a tex-
ture from your resource cache is pretty easy:
Resource resource(m_params.m_Texture);
shared_ptr<ResHandle> texture = g_pApp->m_ResCache->GetHandle(&resource);
if ( FAILED (
D3DXCreateTextureFromFileInMemory(
DXUTGetD3D9Device(),
texture->Buffer(),
texture->Size(),
&m_pTexture ) ) )
{
return E_FAIL;
}
There are some SDKs out there that don ' t let you do this. They require you to send
filenames into their APIs, and they take complete control of loading their own data.
While it
'
s unfortunate, it simply means that you can
'
t use the resource cache for
those parts of your game.
World Design and Cache Prediction
Perhaps you
'
ve just finished a supercharged version of ResCache
good for you.
You
ll proba-
bly suffer a wildly fluctuating frame rate. The moment your game asks for resources
outside of the cache, your game will suffer a major stutter even a few tens of milli-
seconds in a platformer or first-person shooter can frustrate a player.
First, classify your game design into one of the following categories:
'
re not done yet. If you load resources the moment you need them, you
'
n Load Everything at Once: This is for any game that caches resources on a screen-
by-screen basis or level-by-level. Each screen of Myst is a good example, as well as
Grim Fandango. Most fighting games work under this model for each event.
n Load Only at Pinch Points: Almost every shooter utilizes this design, where
resources are cached in during elevator rides or in small barren hallways.
 
 
 
Search WWH ::




Custom Search