diff --git a/source/cl_main.c b/source/cl_main.c index ec2de00..026ce36 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -48,15 +48,19 @@ 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}; + client_static_t cls; client_state_t cl; // FIXME: put these on hunk? -entity_t cl_static_entities[MAX_STATIC_ENTITIES]; -lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; -dlight_t cl_dlights[MAX_DLIGHTS]; +entity_t cl_static_entities[MAX_STATIC_ENTITIES]; +lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES]; -entity_t *cl_entities; //johnfitz -- was a static array, now on hunk -int32_t cl_max_edicts; //johnfitz -- only changes when new map loads +entity_t *cl_entities; //johnfitz -- was a static array, now on hunk +int32_t cl_max_edicts; //johnfitz -- only changes when new map loads + +dlight_t *cl_dlights; +int32_t cl_max_dlights; //johnfitz -- only changes when new map loads int32_t cl_numvisedicts; entity_t *cl_visedicts[MAX_VISEDICTS]; @@ -74,21 +78,23 @@ void CL_ClearState(void) if(!sv.active) Host_ClearMemory(); -// wipe the entire cl structure + // wipe the entire cl structure memset(&cl, 0, sizeof(cl)); SZ_Clear(&cls.message); -// clear other arrays - memset(cl_dlights, 0, sizeof(cl_dlights)); + // 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 cl_max_edicts = CLAMP(MIN_EDICTS, (int32_t)max_edicts.value, MAX_EDICTS); - cl_entities = (entity_t *) Hunk_AllocName(cl_max_edicts * sizeof(entity_t), "cl_entities"); + cl_entities = Hunk_AllocName(cl_max_edicts * sizeof(entity_t), "cl_entities"); //johnfitz + + 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"); } /* @@ -288,7 +294,7 @@ dlight_t *CL_AllocDlight(int32_t key) if(key) { dl = cl_dlights; - for(i = 0 ; i < MAX_DLIGHTS ; i++, dl++) + for(i = 0 ; i < cl_max_dlights ; i++, dl++) { if(dl->key == key) { @@ -302,7 +308,7 @@ dlight_t *CL_AllocDlight(int32_t key) // then look for anything else dl = cl_dlights; - for(i = 0 ; i < MAX_DLIGHTS ; i++, dl++) + for(i = 0 ; i < cl_max_dlights ; i++, dl++) { if(dl->die < cl.time) { @@ -336,7 +342,7 @@ void CL_DecayLights(void) time = cl.time - cl.oldtime; dl = cl_dlights; - for(i = 0 ; i < MAX_DLIGHTS ; i++, dl++) + for(i = 0 ; i < cl_max_dlights ; i++, dl++) { if(dl->die < cl.time || !dl->radius) continue; @@ -650,11 +656,11 @@ int32_t CL_ReadFromServer(void) dev_peakstats.beams = q_max(num_beams, dev_peakstats.beams); //dlights - for(i = 0, l = cl_dlights ; i < MAX_DLIGHTS ; i++, l++) + for(i = 0, l = cl_dlights ; i < cl_max_dlights ; i++, l++) if(l->die >= cl.time && l->radius) num_dlights++; if(num_dlights > 32 && dev_peakstats.dlights <= 32) - Con_DWarning("%" PRIi32 " dlights exceeded standard limit of 32 (max = %" PRIi32 ").\n", num_dlights, MAX_DLIGHTS); + Con_DWarning("%" PRIi32 " dlights exceeded standard limit of 32 (max = %" PRIi32 ").\n", num_dlights, cl_max_dlights); dev_stats.dlights = num_dlights; dev_peakstats.dlights = q_max(num_dlights, dev_peakstats.dlights); @@ -807,6 +813,8 @@ void CL_Init(void) Cvar_RegisterVariable(&cl_maxpitch); //johnfitz -- variable pitch clamping Cvar_RegisterVariable(&cl_minpitch); //johnfitz -- variable pitch clamping + Cvar_RegisterVariable(&cl_maxdlights); + Cmd_AddCommand("entities", CL_PrintEntities_f); Cmd_AddCommand("disconnect", CL_Disconnect_f); Cmd_AddCommand("record", CL_Record_f); diff --git a/source/client.h b/source/client.h index d5b597f..d43b5a7 100644 --- a/source/client.h +++ b/source/client.h @@ -61,22 +61,23 @@ typedef struct // client_state_t should hold all pieces of the client state // -#define SIGNONS 4 // signon messages to receive before connected +#define SIGNONS 4 // signon messages to receive before connected -#define MAX_DLIGHTS 64 //johnfitz -- was 32 +#define MIN_DLIGHTS 32 +#define MAX_DLIGHTS 4096 typedef struct { vec3_t origin; float radius; - float die; // stop lighting after this time - float decay; // drop this each second - float minlight; // don't add when contributing less - int32_t key; - vec3_t color; //johnfitz -- lit support via lordhavoc + float die; // stop lighting after this time + float decay; // drop this each second + float minlight; // don't add when contributing less + int32_t key; + vec3_t color; // johnfitz -- lit support via lordhavoc } dlight_t; -#define MAX_BEAMS 32 //johnfitz -- was 24 +#define MAX_BEAMS 32 // johnfitz -- was 24 typedef struct { int32_t entity; @@ -273,16 +274,18 @@ extern cvar_t m_side; 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 dlight_t cl_dlights[MAX_DLIGHTS]; -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_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_entities; //johnfitz -- was a static array, now on hunk -extern int32_t cl_max_edicts; //johnfitz -- only changes when new map loads +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 + +extern dlight_t *cl_dlights; +extern int32_t cl_max_dlights; //============================================================================= diff --git a/source/gl_rlight.c b/source/gl_rlight.c index 75b4d99..175de17 100644 --- a/source/gl_rlight.c +++ b/source/gl_rlight.c @@ -139,7 +139,7 @@ void R_RenderDlights(void) glBlendFunc(GL_ONE, GL_ONE); l = cl_dlights; - for(i = 0 ; i < MAX_DLIGHTS ; i++, l++) + for(i = 0 ; i < cl_max_dlights ; i++, l++) { if(l->die < cl.time || !l->radius) continue; @@ -251,7 +251,7 @@ void R_PushDlights(void) // advanced yet for this frame l = cl_dlights; - for(i = 0 ; i < MAX_DLIGHTS ; i++, l++) + for(i = 0 ; i < cl_max_dlights ; i++, l++) { if(l->die < cl.time || !l->radius) continue; diff --git a/source/r_alias.c b/source/r_alias.c index 059a86e..591dfe6 100644 --- a/source/r_alias.c +++ b/source/r_alias.c @@ -553,7 +553,7 @@ void R_SetupAliasLighting(entity_t *e) R_LightPoint(e->origin); //add dlights - for(i = 0 ; i < MAX_DLIGHTS ; i++) + for(i = 0 ; i < cl_max_dlights ; i++) { if(cl_dlights[i].die >= cl.time) { diff --git a/source/r_brush.c b/source/r_brush.c index 878222f..d4a716e 100644 --- a/source/r_brush.c +++ b/source/r_brush.c @@ -545,7 +545,7 @@ void R_DrawBrushModel(entity_t *e) // instanced model if(clmodel->firstmodelsurface != 0 && !gl_flashblend.value) { - for(k = 0 ; k < MAX_DLIGHTS ; k++) + for(k = 0 ; k < cl_max_dlights ; k++) { if((cl_dlights[k].die < cl.time) || (!cl_dlights[k].radius)) @@ -1065,7 +1065,7 @@ void R_AddDynamicLights(msurface_t *surf) tmax = (surf->extents[1] >> 4) + 1; tex = surf->texinfo; - for(lnum = 0 ; lnum < MAX_DLIGHTS ; lnum++) + for(lnum = 0 ; lnum < cl_max_dlights ; lnum++) { if(!(surf->dlightbits[lnum >> 5] & (1U << (lnum & 31)))) continue; // not lit by this light diff --git a/source/zone.c b/source/zone.c index 556da0c..9e69a73 100644 --- a/source/zone.c +++ b/source/zone.c @@ -288,30 +288,30 @@ void Z_Print(memzone_t *zone) //============================================================================ -#define HUNK_SENTINAL 0x1df001ed +#define HUNK_SENTINEL 0x1df001ed #define HUNKNAME_LEN 24 typedef struct { - int32_t sentinal; - int32_t size; // including sizeof(hunk_t), -1 = not allocated + int32_t sentinel; + int32_t size; // including sizeof(hunk_t), -1 = not allocated char name[HUNKNAME_LEN]; } hunk_t; byte *hunk_base; -int32_t hunk_size; +int32_t hunk_size; -int32_t hunk_low_used; -int32_t hunk_high_used; +int32_t hunk_low_used; +int32_t hunk_high_used; bool hunk_tempactive; -int32_t hunk_tempmark; +int32_t hunk_tempmark; /* ============== Hunk_Check -Run consistancy and sentinal trahing checks +Run consistancy and sentinel trahing checks ============== */ void Hunk_Check(void) @@ -320,8 +320,8 @@ void Hunk_Check(void) for(h = (hunk_t *)hunk_base ; (byte *)h != hunk_base + hunk_low_used ;) { - if(h->sentinal != HUNK_SENTINAL) - Sys_Error("Hunk_Check: trahsed sentinal"); + if(h->sentinel != HUNK_SENTINEL) + Sys_Error("Hunk_Check: trahsed sentinel"); if(h->size < (int32_t) sizeof(hunk_t) || h->size + (byte *)h - hunk_base > hunk_size) Sys_Error("Hunk_Check: bad size"); h = (hunk_t *)((byte *)h + h->size); @@ -377,8 +377,8 @@ void Hunk_Print(bool all) // // run consistancy checks // - if(h->sentinal != HUNK_SENTINAL) - Sys_Error("Hunk_Check: trahsed sentinal"); + if(h->sentinel != HUNK_SENTINEL) + Sys_Error("Hunk_Check: trahsed sentinel"); if(h->size < (int32_t) sizeof(hunk_t) || h->size + (byte *)h - hunk_base > hunk_size) Sys_Error("Hunk_Check: bad size"); @@ -453,7 +453,7 @@ void *Hunk_AllocName(int32_t size, const char *name) memset(h, 0, size); h->size = size; - h->sentinal = HUNK_SENTINAL; + h->sentinel = HUNK_SENTINEL; q_strlcpy(h->name, name, HUNKNAME_LEN); return (void *)(h + 1); @@ -544,7 +544,7 @@ void *Hunk_HighAllocName(int32_t size, const char *name) memset(h, 0, size); h->size = size; - h->sentinal = HUNK_SENTINAL; + h->sentinel = HUNK_SENTINEL; q_strlcpy(h->name, name, HUNKNAME_LEN); return (void *)(h + 1);