Inside3D!
     

Extending Quake Limits - Part 1: Static Entities

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
mh



Joined: 12 Jan 2008
Posts: 910

PostPosted: Fri Jan 08, 2010 5:00 pm    Post subject: Extending Quake Limits - Part 1: Static Entities Reply with quote

We all know that Quake has some quite annoying built-in limits, so let's deal with some of them. I don't think I've ever seen any practical tutorials on extending limits, and it's time to put that right.

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:
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);
}


That's it. Easiest tutorial ever!

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.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group