From 97ef220fb95da1f4bd7ce9936519ef8a93ec667e Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Mon, 25 Nov 2019 22:23:25 -0500 Subject: [PATCH] dynamically allocate tempents --- source/cl_main.c | 11 +++++++---- source/cl_parse.c | 2 +- source/cl_tent.c | 36 +++++++++++++++++++----------------- source/client.h | 10 ++++++---- source/quakedef.h | 22 +++++++++++----------- 5 files changed, 44 insertions(+), 37 deletions(-) diff --git a/source/cl_main.c b/source/cl_main.c index 026ce36..9a026e8 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -48,7 +48,8 @@ cvar_t m_side = {"m_side", "0.8", CVAR_ARCHIVE}; cvar_t cl_maxpitch = {"cl_maxpitch", "90", CVAR_ARCHIVE}; //johnfitz -- variable pitch clamping cvar_t cl_minpitch = {"cl_minpitch", "-90", CVAR_ARCHIVE}; //johnfitz -- variable pitch clamping -cvar_t cl_maxdlights = {"cl_maxdlights", "128", CVAR_ARCHIVE}; +cvar_t cl_maxdlights = {"cl_maxdlights", "128", CVAR_ARCHIVE}; +cvar_t cl_maxtempents = {"cl_maxtempents", "256", CVAR_ARCHIVE}; client_static_t cls; client_state_t cl; @@ -85,7 +86,6 @@ void CL_ClearState(void) // clear other arrays memset(cl_lightstyle, 0, sizeof(cl_lightstyle)); - memset(cl_temp_entities, 0, sizeof(cl_temp_entities)); memset(cl_beams, 0, sizeof(cl_beams)); //johnfitz -- cl_entities is now dynamically allocated @@ -95,6 +95,9 @@ void CL_ClearState(void) cl_max_dlights = CLAMP(MIN_DLIGHTS, (int32_t)cl_maxdlights.value, MAX_DLIGHTS); cl_dlights = Hunk_AllocName(cl_max_dlights * sizeof(*cl_dlights), "cl_dlights"); + + max_temp_entities = CLAMP(0, (int32_t)cl_maxtempents.value, 32000); + cl_temp_entities = Hunk_AllocName(max_temp_entities * sizeof(*cl_temp_entities), "cl_temp_entities"); } /* @@ -602,7 +605,6 @@ Read all incoming data from the server int32_t CL_ReadFromServer(void) { int32_t ret; - extern int32_t num_temp_entities; //johnfitz int32_t num_beams = 0; //johnfitz int32_t num_dlights = 0; //johnfitz beam_t *b; //johnfitz @@ -642,7 +644,7 @@ int32_t CL_ReadFromServer(void) //temp entities if(num_temp_entities > 64 && dev_peakstats.tempents <= 64) - Con_DWarning("%" PRIi32 " tempentities exceeds standard limit of 64 (max = %" PRIi32 ").\n", num_temp_entities, MAX_TEMP_ENTITIES); + Con_DWarning("%" PRIi32 " tempentities exceeds standard limit of 64 (max = %" PRIi32 ").\n", num_temp_entities, max_temp_entities); dev_stats.tempents = num_temp_entities; dev_peakstats.tempents = q_max(num_temp_entities, dev_peakstats.tempents); @@ -814,6 +816,7 @@ void CL_Init(void) Cvar_RegisterVariable(&cl_minpitch); //johnfitz -- variable pitch clamping Cvar_RegisterVariable(&cl_maxdlights); + Cvar_RegisterVariable(&cl_maxtempents); Cmd_AddCommand("entities", CL_PrintEntities_f); Cmd_AddCommand("disconnect", CL_Disconnect_f); diff --git a/source/cl_parse.c b/source/cl_parse.c index e333e9f..0d8185d 100644 --- a/source/cl_parse.c +++ b/source/cl_parse.c @@ -879,7 +879,7 @@ CL_ParseStatic void CL_ParseStatic(int32_t version) //johnfitz -- added a parameter { entity_t *ent; - int32_t i; + int32_t i; i = cl.num_statics; if(i >= MAX_STATIC_ENTITIES) diff --git a/source/cl_tent.c b/source/cl_tent.c index a818278..bb59504 100644 --- a/source/cl_tent.c +++ b/source/cl_tent.c @@ -23,17 +23,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -int32_t num_temp_entities; -entity_t cl_temp_entities[MAX_TEMP_ENTITIES]; -beam_t cl_beams[MAX_BEAMS]; +entity_t *cl_temp_entities; +int32_t num_temp_entities; +int32_t max_temp_entities; -sfx_t *cl_sfx_wizhit; -sfx_t *cl_sfx_knighthit; -sfx_t *cl_sfx_tink1; -sfx_t *cl_sfx_ric1; -sfx_t *cl_sfx_ric2; -sfx_t *cl_sfx_ric3; -sfx_t *cl_sfx_r_exp3; +beam_t cl_beams[MAX_BEAMS]; + +sfx_t *cl_sfx_wizhit; +sfx_t *cl_sfx_knighthit; +sfx_t *cl_sfx_tink1; +sfx_t *cl_sfx_ric1; +sfx_t *cl_sfx_ric2; +sfx_t *cl_sfx_ric3; +sfx_t *cl_sfx_r_exp3; /* ================= @@ -42,13 +44,13 @@ CL_ParseTEnt */ void CL_InitTEnts(void) { - cl_sfx_wizhit = S_PrecacheSound("wizard/hit.wav"); + cl_sfx_wizhit = S_PrecacheSound("wizard/hit.wav"); cl_sfx_knighthit = S_PrecacheSound("hknight/hit.wav"); - cl_sfx_tink1 = S_PrecacheSound("weapons/tink1.wav"); - cl_sfx_ric1 = S_PrecacheSound("weapons/ric1.wav"); - cl_sfx_ric2 = S_PrecacheSound("weapons/ric2.wav"); - cl_sfx_ric3 = S_PrecacheSound("weapons/ric3.wav"); - cl_sfx_r_exp3 = S_PrecacheSound("weapons/r_exp3.wav"); + cl_sfx_tink1 = S_PrecacheSound("weapons/tink1.wav"); + cl_sfx_ric1 = S_PrecacheSound("weapons/ric1.wav"); + cl_sfx_ric2 = S_PrecacheSound("weapons/ric2.wav"); + cl_sfx_ric3 = S_PrecacheSound("weapons/ric3.wav"); + cl_sfx_r_exp3 = S_PrecacheSound("weapons/r_exp3.wav"); } /* @@ -271,7 +273,7 @@ entity_t *CL_NewTempEntity(void) if(cl_numvisedicts == MAX_VISEDICTS) return NULL; - if(num_temp_entities == MAX_TEMP_ENTITIES) + if(num_temp_entities == max_temp_entities) return NULL; ent = &cl_temp_entities[num_temp_entities]; memset(ent, 0, sizeof(*ent)); diff --git a/source/client.h b/source/client.h index d43b5a7..a02b915 100644 --- a/source/client.h +++ b/source/client.h @@ -267,20 +267,22 @@ extern cvar_t m_forward; extern cvar_t m_side; -#define MAX_TEMP_ENTITIES 256 //johnfitz -- was 64 -#define MAX_STATIC_ENTITIES 4096 //ericw -- was 512 //johnfitz -- was 128 -#define MAX_VISEDICTS 4096 // larger, now we support BSP2 +#define MAX_STATIC_ENTITIES 4096 //ericw -- was 512 //johnfitz -- was 128 +#define MAX_VISEDICTS 4096 // larger, now we support BSP2 extern client_state_t cl; // FIXME, allocate dynamically extern entity_t cl_static_entities[MAX_STATIC_ENTITIES]; extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; -extern entity_t cl_temp_entities[MAX_TEMP_ENTITIES]; extern beam_t cl_beams[MAX_BEAMS]; extern entity_t *cl_visedicts[MAX_VISEDICTS]; extern int32_t cl_numvisedicts; +extern entity_t *cl_temp_entities; +extern int32_t num_temp_entities; //johnfitz +extern int32_t max_temp_entities; //johnfitz + extern entity_t *cl_entities; //johnfitz -- was a static array, now on hunk extern int32_t cl_max_edicts; //johnfitz -- only changes when new map loads diff --git a/source/quakedef.h b/source/quakedef.h index 5409cc5..459a626 100644 --- a/source/quakedef.h +++ b/source/quakedef.h @@ -239,19 +239,19 @@ extern bool noclip_anglehack; // // host // -extern quakeparms_t *host_parms; +extern quakeparms_t *host_parms; -extern cvar_t sys_ticrate; -extern cvar_t sys_throttle; -extern cvar_t sys_nostdout; -extern cvar_t developer; -extern cvar_t max_edicts; //johnfitz +extern cvar_t sys_ticrate; +extern cvar_t sys_throttle; +extern cvar_t sys_nostdout; +extern cvar_t developer; +extern cvar_t max_edicts; //johnfitz -extern bool host_initialized; // true if into command execution -extern double host_frametime; -extern byte *host_colormap; -extern int32_t host_framecount; // incremented every frame, never reset -extern double realtime; // not bounded in any way, changed at +extern bool host_initialized; // true if into command execution +extern double host_frametime; +extern byte *host_colormap; +extern int32_t host_framecount; // incremented every frame, never reset +extern double realtime; // not bounded in any way, changed at // start of every frame, never reset typedef struct filelist_item_s