]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
an optimization to CL_RelinkNetworkEntities (and related code) which increases perfor...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 5 Aug 2002 10:20:25 +0000 (10:20 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 5 Aug 2002 10:20:25 +0000 (10:20 +0000)
(store the ent->state_current.active flags in a separate array to use less memory bandwidth)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2196 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
cl_parse.c
client.h

index 6f8a666e1c21cc3b0a11f44bdde92cafd3d01d2b..aaeb1e5c5c361ac860df8f94070a633139a85b9a 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -70,6 +70,7 @@ int cl_max_lightstyle;
 int cl_max_brushmodel_entities;
 
 entity_t *cl_entities;
+qbyte *cl_entities_active;
 entity_t *cl_static_entities;
 entity_t *cl_temp_entities;
 cl_effect_t *cl_effects;
@@ -120,6 +121,7 @@ void CL_ClearState (void)
        cl_max_brushmodel_entities = MAX_EDICTS;
 
        cl_entities = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(entity_t));
+       cl_entities_active = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(qbyte));
        cl_static_entities = Mem_Alloc(cl_entities_mempool, cl_max_static_entities * sizeof(entity_t));
        cl_temp_entities = Mem_Alloc(cl_entities_mempool, cl_max_temp_entities * sizeof(entity_t));
        cl_effects = Mem_Alloc(cl_entities_mempool, cl_max_effects * sizeof(cl_effect_t));
@@ -359,9 +361,14 @@ static void CL_RelinkNetworkEntities()
        // start on the entity after the world
        for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS;i++, ent++)
        {
-               // if the object wasn't included in the latest packet, remove it
+               // if the object isn't active in the current network frame, skip it
+               if (!cl_entities_active[i])
+                       continue;
                if (!ent->state_current.active)
+               {
+                       cl_entities_active[i] = false;
                        continue;
+               }
 
                VectorCopy(ent->persistent.trail_origin, oldorg);
 
index 6bbe93388e03889ba82abce6f7401d05ab09375a..722e0a8b6b3266b7ae4e873b0e618e22b284d32c 100644 (file)
@@ -107,22 +107,6 @@ void CL_Parse_Init(void)
 qboolean Nehahrademcompatibility; // LordHavoc: to allow playback of the early Nehahra movie segments
 int dpprotocol; // LordHavoc: version of network protocol, or 0 if not DarkPlaces
 
-/*
-===============
-CL_EntityNum
-
-This error checks and tracks the total number of entities
-===============
-*/
-entity_t       *CL_EntityNum (int num)
-{
-       if (num >= MAX_EDICTS)
-               Host_Error ("CL_EntityNum: %i is an invalid number",num);
-               
-       return &cl_entities[num];
-}
-
-
 /*
 ==================
 CL_ParseStartSoundPacket
@@ -138,7 +122,7 @@ void CL_ParseStartSoundPacket(int largesoundindex)
     float      attenuation;
        int             i;
                   
-    field_mask = MSG_ReadByte(); 
+    field_mask = MSG_ReadByte();
 
     if (field_mask & SND_VOLUME)
                volume = MSG_ReadByte ();
@@ -553,10 +537,7 @@ void CL_ParseUpdate (int bits)
        if (num < 1)
                Host_Error("CL_ParseUpdate: invalid entity number (%i)\n", num);
 
-       // mark as visible (no kill this frame)
-       entlife[num] = 2;
-
-       ent = CL_EntityNum (num);
+       ent = cl_entities + num;
 
        for (i = 0;i < 32;i++)
                if (bits & (1 << i))
@@ -571,8 +552,8 @@ void CL_ParseUpdate (int bits)
        else
                new = ent->state_baseline;
 
+       new.number = num;
        new.time = cl.mtime[0];
-
        new.flags = 0;
        if (bits & U_MODEL)             new.modelindex = (new.modelindex & 0xFF00) | MSG_ReadByte();
        if (bits & U_FRAME)             new.frame = (new.frame & 0xFF00) | MSG_ReadByte();
@@ -642,6 +623,12 @@ void CL_ParseUpdate (int bits)
                ent->state_previous = ent->state_current;
                ent->state_current = new;
        }
+       if (ent->state_current.active)
+       {
+               cl_entities_active[ent->state_current.number] = true;
+               // mark as visible (no kill this frame)
+               entlife[ent->state_current.number] = 2;
+       }
 }
 
 void CL_ReadEntityFrame(void)
@@ -653,13 +640,14 @@ void CL_ReadEntityFrame(void)
        EntityFrame_FetchFrame(&cl.entitydatabase, EntityFrame_MostRecentlyRecievedFrameNum(&cl.entitydatabase), &entityframe);
        for (i = 0;i < entityframe.numentities;i++)
        {
-               // the entity lives again...
-               entlife[entityframe.entitydata[i].number] = 2;
                // copy the states
                ent = &cl_entities[entityframe.entitydata[i].number];
                ent->state_previous = ent->state_current;
                ent->state_current = entityframe.entitydata[i];
                ent->state_current.time = cl.mtime[0];
+               // the entity lives again...
+               entlife[ent->state_current.number] = 2;
+               cl_entities_active[ent->state_current.number] = true;
        }
        VectorCopy(cl.viewentoriginnew, cl.viewentoriginold);
        VectorCopy(entityframe.eye, cl.viewentoriginnew);
@@ -1198,13 +1186,15 @@ void CL_ParseServerMessage (void)
 
                case svc_spawnbaseline:
                        i = MSG_ReadShort ();
-                       // must use CL_EntityNum() to force cl.num_entities up
-                       CL_ParseBaseline (CL_EntityNum(i), false);
+                       if (i < 0 || i >= MAX_EDICTS)
+                               Host_Error ("CL_ParseServerMessage: svc_spawnbaseline: invalid entity number %i", i);
+                       CL_ParseBaseline (cl_entities + i, false);
                        break;
                case svc_spawnbaseline2:
                        i = MSG_ReadShort ();
-                       // must use CL_EntityNum() to force cl.num_entities up
-                       CL_ParseBaseline (CL_EntityNum(i), true);
+                       if (i < 0 || i >= MAX_EDICTS)
+                               Host_Error ("CL_ParseServerMessage: svc_spawnbaseline2: invalid entity number %i", i);
+                       CL_ParseBaseline (cl_entities + i, true);
                        break;
                case svc_spawnstatic:
                        CL_ParseStatic (false);
index 7d37ebcc92e343b3b463cab3a7e2be6f16f70197..3faba2f8e66e3725f5949269a0d5e2313ca076e3 100644 (file)
--- a/client.h
+++ b/client.h
@@ -471,6 +471,7 @@ extern int cl_num_temp_entities;
 extern int cl_num_brushmodel_entities;
 
 extern entity_t *cl_entities;
+extern qbyte *cl_entities_active;
 extern entity_t *cl_static_entities;
 extern entity_t *cl_temp_entities;
 extern entity_render_t **cl_brushmodel_entities;