From 9e883a148a3370e139b78a19d2ee645fba8db8d1 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 7 May 2007 07:28:00 +0000 Subject: [PATCH] reduced uninitialized data size by 13MB by moving some temporary arrays used by outdated protocols into their database struct, also moved some other arrays git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7245 d7cf8633-e32d-0410-b094-e92efae38249 --- protocol.c | 34 ++++++++++++++-------------------- protocol.h | 41 +++++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/protocol.c b/protocol.c index da014322..848ad7c7 100644 --- a/protocol.c +++ b/protocol.c @@ -1,8 +1,6 @@ #include "quakedef.h" -#define E5_PROTOCOL_PRIORITYLEVELS 32 - // this is 88 bytes (must match entity_state_t in protocol.h) entity_state_t defaultstate = { @@ -58,12 +56,6 @@ protocolversioninfo[] = {0, NULL} }; -static entity_frame_t deltaframe; // FIXME? -static entity_frame_t framedata; // FIXME? - -int entityframe5_prioritychaincounts[E5_PROTOCOL_PRIORITYLEVELS]; -unsigned short entityframe5_prioritychains[E5_PROTOCOL_PRIORITYLEVELS][ENTITYFRAME5_MAXSTATES]; - protocolversion_t Protocol_EnumForName(const char *s) { int i; @@ -1070,7 +1062,7 @@ void EntityFrame_AddFrame(entityframe_database_t *d, vec3_t eye, int framenum, i void EntityFrame_WriteFrame(sizebuf_t *msg, entityframe_database_t *d, int numstates, const entity_state_t *states, int viewentnum) { int i, onum, number; - entity_frame_t *o = &deltaframe; + entity_frame_t *o = &d->deltaframe; const entity_state_t *ent, *delta; vec3_t eye; prvm_eval_t *val; @@ -1138,13 +1130,15 @@ void EntityFrame_WriteFrame(sizebuf_t *msg, entityframe_database_t *d, int numst void EntityFrame_CL_ReadFrame(void) { int i, number, removed; - entity_frame_t *f = &framedata, *delta = &deltaframe; + entity_frame_t *f, *delta; entity_state_t *e, *old, *oldend; entity_t *ent; entityframe_database_t *d; if (!cl.entitydatabase) cl.entitydatabase = EntityFrame_AllocDatabase(cls.levelmempool); d = cl.entitydatabase; + f = &d->framedata; + delta = &d->deltaframe; EntityFrame_Clear(f, NULL, -1); @@ -1705,7 +1699,7 @@ int EntityState5_Priority(entityframe5_database_t *d, int stateindex) entity_state_t *s; // if it is the player, update urgently if (stateindex == d->viewentnum) - return E5_PROTOCOL_PRIORITYLEVELS - 1; + return ENTITYFRAME5_PRIORITYLEVELS - 1; // priority increases each frame no matter what happens priority = d->priorities[stateindex] + 1; // players get an extra priority boost @@ -1715,7 +1709,7 @@ int EntityState5_Priority(entityframe5_database_t *d, int stateindex) if (!d->states[stateindex].active) { priority++; - return bound(1, priority, E5_PROTOCOL_PRIORITYLEVELS - 1); + return bound(1, priority, ENTITYFRAME5_PRIORITYLEVELS - 1); } // certain changes are more noticable than others if (d->deltabits[stateindex] & (E5_FULLUPDATE | E5_ATTACHMENT | E5_MODEL | E5_FLAGS | E5_COLORMAP)) @@ -1739,7 +1733,7 @@ int EntityState5_Priority(entityframe5_database_t *d, int stateindex) // distance from the player if (VectorDistance(d->states[d->viewentnum].netcenter, s->netcenter) < 1024.0f) priority++; - return bound(1, priority, E5_PROTOCOL_PRIORITYLEVELS - 1); + return bound(1, priority, ENTITYFRAME5_PRIORITYLEVELS - 1); } void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbits, sizebuf_t *msg) @@ -2304,7 +2298,7 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int num return; // build lists of entities by priority level - memset(entityframe5_prioritychaincounts, 0, sizeof(entityframe5_prioritychaincounts)); + memset(d->prioritychaincounts, 0, sizeof(d->prioritychaincounts)); l = 0; for (num = 0;num < d->maxedicts;num++) { @@ -2312,12 +2306,12 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int num { if (d->deltabits[num]) { - if (d->priorities[num] < (E5_PROTOCOL_PRIORITYLEVELS - 1)) + if (d->priorities[num] < (ENTITYFRAME5_PRIORITYLEVELS - 1)) d->priorities[num] = EntityState5_Priority(d, num); l = num; priority = d->priorities[num]; - if (entityframe5_prioritychaincounts[priority] < ENTITYFRAME5_MAXSTATES) - entityframe5_prioritychains[priority][entityframe5_prioritychaincounts[priority]++] = num; + if (d->prioritychaincounts[priority] < ENTITYFRAME5_MAXSTATES) + d->prioritychains[priority][d->prioritychaincounts[priority]++] = num; } else d->priorities[num] = 0; @@ -2360,11 +2354,11 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int num MSG_WriteLong(msg, framenum); if (sv.protocol != PROTOCOL_QUAKE && sv.protocol != PROTOCOL_QUAKEDP && sv.protocol != PROTOCOL_NEHAHRAMOVIE && sv.protocol != PROTOCOL_DARKPLACES1 && sv.protocol != PROTOCOL_DARKPLACES2 && sv.protocol != PROTOCOL_DARKPLACES3 && sv.protocol != PROTOCOL_DARKPLACES4 && sv.protocol != PROTOCOL_DARKPLACES5 && sv.protocol != PROTOCOL_DARKPLACES6) MSG_WriteLong(msg, movesequence); - for (priority = E5_PROTOCOL_PRIORITYLEVELS - 1;priority >= 0 && packetlog->numstates < ENTITYFRAME5_MAXSTATES;priority--) + for (priority = ENTITYFRAME5_PRIORITYLEVELS - 1;priority >= 0 && packetlog->numstates < ENTITYFRAME5_MAXSTATES;priority--) { - for (i = 0;i < entityframe5_prioritychaincounts[priority] && packetlog->numstates < ENTITYFRAME5_MAXSTATES;i++) + for (i = 0;i < d->prioritychaincounts[priority] && packetlog->numstates < ENTITYFRAME5_MAXSTATES;i++) { - num = entityframe5_prioritychains[priority][i]; + num = d->prioritychains[priority][i]; n = d->states + num; if (d->deltabits[num] & E5_FULLUPDATE) d->deltabits[num] = E5_FULLUPDATE | EntityState5_DeltaBits(&defaultstate, n); diff --git a/protocol.h b/protocol.h index 142544f8..b12aab92 100644 --- a/protocol.h +++ b/protocol.h @@ -442,6 +442,22 @@ the Write function performs these steps: server updates entities in looping ranges, a frame consists of a range of visible entities (not always all visible entities), */ +#define MAX_ENTITY_HISTORY 64 +#define MAX_ENTITY_DATABASE (MAX_EDICTS * 2) + +// build entity data in this, to pass to entity read/write functions +typedef struct entity_frame_s +{ + double time; + int framenum; + int numentities; + int firstentitynum; + int lastentitynum; + vec3_t eye; + entity_state_t entitydata[MAX_ENTITY_DATABASE]; +} +entity_frame_t; + typedef struct entity_frameinfo_s { double time; @@ -451,9 +467,6 @@ typedef struct entity_frameinfo_s } entity_frameinfo_t; -#define MAX_ENTITY_HISTORY 64 -#define MAX_ENTITY_DATABASE (MAX_EDICTS * 2) - typedef struct entityframe_database_s { // note: these can be far out of range, modulo with MAX_ENTITY_DATABASE to get a valid range (which may wrap) @@ -475,21 +488,12 @@ typedef struct entityframe_database_s entity_frameinfo_t frames[MAX_ENTITY_HISTORY]; // entities entity_state_t entitydata[MAX_ENTITY_DATABASE]; -} -entityframe_database_t; -// build entity data in this, to pass to entity read/write functions -typedef struct entity_frame_s -{ - double time; - int framenum; - int numentities; - int firstentitynum; - int lastentitynum; - vec3_t eye; - entity_state_t entitydata[MAX_ENTITY_DATABASE]; + // structs for building new frames and reading them + entity_frame_t deltaframe; + entity_frame_t framedata; } -entity_frame_t; +entityframe_database_t; // LordHavoc: these are in approximately sorted order, according to cost and // likelyhood of being used for numerous objects in a frame @@ -705,6 +709,7 @@ void EntityFrame4_CL_ReadFrame(void); #define ENTITYFRAME5_MAXPACKETLOGS 64 #define ENTITYFRAME5_MAXSTATES 1024 +#define ENTITYFRAME5_PRIORITYLEVELS 32 typedef struct entityframe5_changestate_s { @@ -762,6 +767,10 @@ typedef struct entityframe5_database_s // rather than a memmove to remove them from the start. //int numchangestates; //entityframe5_changestate_t changestates[MAX_EDICTS]; + + // buffers for building priority info + int prioritychaincounts[ENTITYFRAME5_PRIORITYLEVELS]; + unsigned short prioritychains[ENTITYFRAME5_PRIORITYLEVELS][ENTITYFRAME5_MAXSTATES]; } entityframe5_database_t; -- 2.39.2