Hopefully this will be part 1 of an extended - but quite irregular - series, and hopefully other people will also join in.
For part 1 we're going to do static entities, probably the easiest of them all, but with a time-bomb to catch the unwary.
Concept
A static entity is sent from QC to the client when the server spawns, and from that point onwards it lives only on the client. The server doesn't know about it, the server doesn't care about it, the server cannot interact with it. Once spawned it exists for the full lifetime of the map and nothing can remove it, not even the most agile of QC ninjas, as Quake does not provide an interface for doing anything other than spawning a static entity. A static entity is like the Duracell bunny on nuclear power.
Quake has a hard-coded maximum of 128 static entities, so let's get rid of it.
This code will work with both software and GLQuake.
The Code
Open your cl_parse.c file, find the CL_ParseStatic function, and replace it with this:
Code: Select all
void CL_ParseStatic (void)
{
entity_t *ent;
// mh - extended static entities begin
ent = (entity_t *) Hunk_Alloc (sizeof (entity_t));
CL_ParseBaseline (ent);
// mh - extended static entities end
// copy it to the current state
ent->model = cl.model_precache[ent->baseline.modelindex];
ent->frame = ent->baseline.frame;
ent->colormap = vid.colormap;
ent->skinnum = ent->baseline.skin;
ent->effects = ent->baseline.effects;
VectorCopy (ent->baseline.origin, ent->origin);
VectorCopy (ent->baseline.angles, ent->angles);
R_AddEfrags (ent);
}
If you study the differences between the old and the new, you'll see that instead of pulling a new static entity from a fixed size array I am instead allocating it directly on the Hunk. This way it will be automatically free'ed between map loads, and we no longer need to worry about managing anything.
Beware!
That time bomb I mentioned earlier? It's right there in the last line - the call to R_AddEfrags. Although we no longer have a limit on the number of static entities we still have a limit on the number of efrags, and removing this requires a little bit more work. That's what I'm going to show one way of doing in the next part.
Cleaning up
We can now remove the rest of the code relating to this limit. The num_statics member from client_state_t, the MAX_STATIC_ENTITIES define and the cl_static_entities array itself.