From b2400a2fcb78b9cd588bc8b000357e698bb7b9cc Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 5 Aug 2002 10:20:25 +0000 Subject: [PATCH] an optimization to CL_RelinkNetworkEntities (and related code) which increases performance by 5% (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 | 9 ++++++++- cl_parse.c | 46 ++++++++++++++++++---------------------------- client.h | 1 + 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/cl_main.c b/cl_main.c index 6f8a666e..aaeb1e5c 100644 --- 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); diff --git a/cl_parse.c b/cl_parse.c index 6bbe9338..722e0a8b 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -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); diff --git a/client.h b/client.h index 7d37ebcc..3faba2f8 100644 --- 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; -- 2.39.2