To provide a smooth loading of assets for a typical game session, it is important that the engine do as much work as possible to load those assets before the session begins. By doing this, the player’s experience is not disturbed by interruptions as the engine tries to cache assets in the middle of a session, often causing “hitching�? or delays in rendering. To do this, entities must declare and precache the assets they intend to use before the session starts. There are multiple utility functions in place to achieve this.
Precache() function is available to all descendants of the
CBaseEntity class and must be called in the
Spawn() function of each entity. All assets used by the entity (models, sounds, VCD, decals) must be declared in this function to be used. Assets may not be precached outside of this function.
Assets are precached using the following functions:
Used to precache a model.
int CBaseEntity::PrecacheModel( const char *name )
- Filename of the model to load
- Reference index for the model.
Used to precache a sound script as declared in a sound script file.
void CBaseEntity::PrecacheScriptSound( const char *soundname )
- Name of sound script to precache.
- Sound script must be declared in the sound script manifest document.
Used to precache a VCD file.
void PrecacheInstancedScene( char const *pszScene )
- Filename of the VCD to precache.
Utility function that will call the
Precache() function for an entity that will be referenced or created during the lifetime of the calling entity. This is often used for weapons that will create a child entity (like a grenade) dynamically during the course of a session.
void UTIL_PrecacheOther( const char *szClassname, const char *modelName )
- Entity classname to precache assets for.
- Model name to use for this entity.
Used to precache a decal.
int UTIL_PrecacheDecal( const char *name, bool preload )
- Name of the decal to precache.
- Whether or not to preload this decal.
- Reference index for the decal model.