diff --git a/include/client/entities.h b/include/client/entities.h index 3d26eb68e..7fb867ca1 100644 --- a/include/client/entities.h +++ b/include/client/entities.h @@ -62,6 +62,8 @@ typedef struct entity_state_s { typedef struct { entity_state_t * const baseline; entity_state_t * const * const frame; + const int num_frames; + const int num_entities; } entstates_t; extern entstates_t nq_entstates; diff --git a/libs/client/cl_entities.c b/libs/client/cl_entities.c index 85cc7b39e..01397321a 100644 --- a/libs/client/cl_entities.c +++ b/libs/client/cl_entities.c @@ -79,8 +79,8 @@ static entity_state_t * const qw_frames[64] = { &entity_states[512 * 61], &entity_states[512 * 62], &entity_states[512 * 63], &entity_states[512 * 64], }; -entstates_t nq_entstates = {&entity_states[0], nq_frames}; -entstates_t qw_entstates = {&entity_states[0], qw_frames}; +entstates_t nq_entstates = {&entity_states[0], nq_frames, 2, 32000}; +entstates_t qw_entstates = {&entity_states[0], qw_frames, 64, 512}; vec3_t ent_colormod[256] = { {0, 0, 0}, diff --git a/nq/include/client.h b/nq/include/client.h index 894dd2cf4..0bb80f003 100644 --- a/nq/include/client.h +++ b/nq/include/client.h @@ -275,7 +275,6 @@ extern client_state_t cl; // FIXME, allocate dynamically extern entity_t cl_entities[MAX_EDICTS]; -extern entity_state_t cl_entity_states[3][MAX_EDICTS]; extern double cl_msgtime[MAX_EDICTS]; extern byte cl_forcelink[MAX_EDICTS]; diff --git a/nq/source/cl_ents.c b/nq/source/cl_ents.c index 8118c12f9..2d8a17abd 100644 --- a/nq/source/cl_ents.c +++ b/nq/source/cl_ents.c @@ -52,7 +52,6 @@ #include "server.h" entity_t cl_entities[MAX_EDICTS]; -entity_state_t cl_entity_states[3][MAX_EDICTS]; double cl_msgtime[MAX_EDICTS]; byte cl_forcelink[MAX_EDICTS]; @@ -63,7 +62,8 @@ CL_ClearEnts (void) // clear other arrays memset (cl_entities, 0, sizeof (cl_entities)); - memset (cl_entity_states, 0, sizeof (cl_entity_states)); + i = nq_entstates.num_frames * nq_entstates.num_entities; + memset (nq_entstates.frame[0], 0, i * sizeof (entity_state_t)); memset (cl_msgtime, 0, sizeof (cl_msgtime)); memset (cl_forcelink, 0, sizeof (cl_forcelink)); @@ -320,8 +320,8 @@ CL_RelinkEntities (void) // start on the entity after the world for (i = 1; i < cl.num_entities; i++) { - new = &cl_entity_states[1 + cl.mindex][i]; - old = &cl_entity_states[2 - cl.mindex][i]; + new = &nq_entstates.frame[0 + cl.mindex][i]; + old = &nq_entstates.frame[1 - cl.mindex][i]; ent = &cl_entities[i]; // if the object wasn't included in the last packet, remove it if (cl_msgtime[i] != cl.mtime[0] || !new->modelindex) { diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index 132b535fd..35c210bd0 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -152,7 +152,7 @@ CL_EntityNum (int num) if (num >= cl.num_entities) cl.num_entities = num + 1; - return &cl_entity_states[0][num]; + return &nq_entstates.baseline[num]; } static void @@ -486,7 +486,7 @@ CL_ParseUpdate (int bits) num = MSG_ReadByte (net_message); baseline = CL_EntityNum (num); - state = &cl_entity_states[1 + cl.mindex][num]; + state = &nq_entstates.frame[0 + cl.mindex][num]; for (i = 0; i < 16; i++) if (bits & (1 << i)) diff --git a/qw/include/client.h b/qw/include/client.h index c3b89832d..dd1095d14 100644 --- a/qw/include/client.h +++ b/qw/include/client.h @@ -338,9 +338,8 @@ extern struct cvar_s *cl_fb_players; extern client_state_t cl; -// FIXME, allocate dynamically -extern entity_state_t cl_baselines[MAX_EDICTS]; extern entity_t *cl_static_entities; +extern entity_t cl_entities[512]; extern qboolean nomaster; extern char *server_version; // version of server we connected to diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index 1ce410aac..3d96d18ee 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -783,7 +783,7 @@ demo_start_recording (int track) // baselines memset (&blankes, 0, sizeof (blankes)); for (i = 0; i < MAX_EDICTS; i++) { - es = cl_baselines + i; + es = qw_entstates.baseline + i; if (memcmp (es, &blankes, sizeof (blankes))) { MSG_WriteByte (&buf, svc_spawnbaseline); diff --git a/qw/source/cl_entparse.c b/qw/source/cl_entparse.c index 8f498cc69..fa006c0d0 100644 --- a/qw/source/cl_entparse.c +++ b/qw/source/cl_entparse.c @@ -289,7 +289,8 @@ CL_ParsePacketEntities (qboolean delta) if (newindex >= MAX_DEMO_PACKET_ENTITIES) Host_Error ("CL_ParsePacketEntities: newindex == " "MAX_DEMO_PACKET_ENTITIES"); - CL_ParseDelta (&cl_baselines[newnum], &newp->entities[newindex], + CL_ParseDelta (&qw_entstates.baseline[newnum], + &newp->entities[newindex], word); newindex++; continue; @@ -301,7 +302,7 @@ CL_ParsePacketEntities (qboolean delta) Sys_Printf ("WARNING: delta on full update"); } if (word & U_REMOVE) { // Clear the entity - entity_t *ent = &cl_packet_ents[newnum]; + entity_t *ent = &cl_entities[newnum]; if (ent->efrag) r_funcs->R_RemoveEfrags (ent); memset (ent, 0, sizeof (entity_t)); diff --git a/qw/source/cl_ents.c b/qw/source/cl_ents.c index d34e86e91..fa9f219c1 100644 --- a/qw/source/cl_ents.c +++ b/qw/source/cl_ents.c @@ -59,15 +59,17 @@ entity_t cl_player_ents[MAX_CLIENTS]; entity_t cl_flag_ents[MAX_CLIENTS]; -entity_t cl_packet_ents[512]; // FIXME: magic number +entity_t cl_entities[512]; // FIXME: magic number void CL_ClearEnts (void) { size_t i; - for (i = 0; i < sizeof (cl_packet_ents) / sizeof (cl_packet_ents[0]); i++) - CL_Init_Entity (&cl_packet_ents[i]); + i = qw_entstates.num_frames * qw_entstates.num_entities; + memset (qw_entstates.frame[0], 0, i * sizeof (entity_state_t)); + for (i = 0; i < sizeof (cl_entities) / sizeof (cl_entities[0]); i++) + CL_Init_Entity (&cl_entities[i]); for (i = 0; i < sizeof (cl_flag_ents) / sizeof (cl_flag_ents[0]); i++) CL_Init_Entity (&cl_flag_ents[i]); for (i = 0; i < sizeof (cl_player_ents) / sizeof (cl_player_ents[0]); i++) @@ -248,7 +250,7 @@ CL_LinkPacketEntities (void) CL_NewDlight (s1->number, s1->origin, s1->effects, s1->glow_size, s1->glow_color); - ent = &cl_packet_ents[s1->number]; + ent = &cl_entities[s1->number]; // if set to invisible, skip if (!s1->modelindex diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index ea3a1b68a..58794b69e 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -186,7 +186,6 @@ static int cl_usleep_cache; client_static_t cls; client_state_t cl; -entity_state_t cl_entities[UPDATE_BACKUP][MAX_DEMO_PACKET_ENTITIES]; entity_state_t cl_baselines[MAX_EDICTS]; @@ -404,8 +403,7 @@ CL_ClearState (void) cl.fbskins = FBSKINS_DEFAULT; for (i = 0; i < UPDATE_BACKUP; i++) - cl.frames[i].packet_entities.entities = cl_entities[i]; - memset (cl_entities, 0, sizeof (cl_entities)); + cl.frames[i].packet_entities.entities = qw_entstates.frame[i]; cl.serverinfo = Info_ParseString ("", MAX_INFO_STRING, 0); CL_Init_Entity (&cl.viewent); diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index 9526f968d..c6c77ab17 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -752,13 +752,14 @@ CL_ClearBaselines (void) { int i; - memset (cl_baselines, 0, sizeof (cl_baselines)); + i = qw_entstates.num_entities; + memset (qw_entstates.baseline, 0, i * sizeof (entity_state_t)); for (i = 0; i < MAX_EDICTS; i++) { - cl_baselines[i].colormod = 255; - cl_baselines[i].alpha = 255; - cl_baselines[i].scale = 16; - cl_baselines[i].glow_size = 0; - cl_baselines[i].glow_color = 254; + qw_entstates.baseline[i].colormod = 255; + qw_entstates.baseline[i].alpha = 255; + qw_entstates.baseline[i].scale = 16; + qw_entstates.baseline[i].glow_size = 0; + qw_entstates.baseline[i].glow_color = 254; } } @@ -1495,7 +1496,7 @@ CL_ParseServerMessage (void) case svc_spawnbaseline: i = MSG_ReadShort (net_message); - CL_ParseBaseline (&cl_baselines[i]); + CL_ParseBaseline (&qw_entstates.baseline[i]); break; case svc_temp_entity: