
Precaching was one of the first stumbling blocks we encountered when
we starting working with the SDK. It turns out to be quite simple if
you don't ask too many questions about how it works.
Why precache?
Good question. I don't actually know, but I can guess. If anyone
knows better than please tell me!
My current theory is that the server needs to tell the clients
which models and sounds they require. If, for whatever reason, any of
these are not available then this gives the chance for the client to
tell the server before gameplay starts. For this reason, all
precache's must first be done before the 3D engine starts. This is
not a problem for any entities that are placed in the map since they
are spawned before the 3D engine starts. However, any items that are
dynamically created must be precached manually.
So how do we force things to be precache?
This is done by either precaching the objects one at a time or by
calling the utility function "UTIL_PrecacheOther". It is quite clear
from the SDK source that UTIL_PrecacheOther is a hack. What it does
is it creates the entity, calls its Precache function and then removes
that entity.
Where do we force these precaches?
In client.cpp there is a function called ClientPrecache. Add your
own manual precaches here -- just as Valve had to do for a load of
their sounds.
More questions?
Ask me and I'll do my best to answer them.
|