From e87a1b8d9db16ce3c751e9881887e8249aa13336 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 26 Jul 2017 04:27:16 +0000 Subject: [PATCH] drop MAX_MAP_LEAFS limit and move 4 static buffers to use realloc(). 4 buffers were: mod_novis, decompressed, checkpvs, and fatpvs. Also fix fatbytes calculation in SV_FatPVS to match the other PVS buffers, was (numleafs+31)>>3, changed to (numleafs+7)>>3. I am assuming the previous was a bug/typo. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1434 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/bspfile.h | 6 +++--- Quake/gl_model.c | 56 ++++++++++++++++++++++++++++++------------------ Quake/gl_model.h | 1 + Quake/pr_cmds.c | 15 +++++++++++-- Quake/r_world.c | 4 ++-- Quake/sv_main.c | 15 ++++++++++--- 6 files changed, 66 insertions(+), 31 deletions(-) diff --git a/Quake/bspfile.h b/Quake/bspfile.h index 988b2d8a..6da832f0 100644 --- a/Quake/bspfile.h +++ b/Quake/bspfile.h @@ -35,7 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAX_MAP_PLANES 32767 #define MAX_MAP_NODES 32767 // because negative shorts are contents #define MAX_MAP_CLIPNODES 32767 -#define MAX_MAP_LEAFS 80000 //johnfitz -- was 8192 +//#define MAX_MAP_LEAFS 80000 //johnfitz -- was 8192 #define MAX_MAP_VERTS 65535 #define MAX_MAP_FACES 65535 #define MAX_MAP_MARKSURFACES 65535 @@ -333,8 +333,8 @@ extern byte dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t) extern int entdatasize; extern char dentdata[MAX_MAP_ENTSTRING]; -extern int numleafs; -extern dleaf_t dleafs[MAX_MAP_LEAFS]; +//extern int numleafs; +//extern dleaf_t dleafs[MAX_MAP_LEAFS]; extern int numplanes; extern dplane_t dplanes[MAX_MAP_PLANES]; diff --git a/Quake/gl_model.c b/Quake/gl_model.c index d4854580..1f3eb059 100644 --- a/Quake/gl_model.c +++ b/Quake/gl_model.c @@ -36,7 +36,11 @@ qmodel_t *Mod_LoadModel (qmodel_t *mod, qboolean crash); cvar_t external_ents = {"external_ents", "1", CVAR_ARCHIVE}; -byte mod_novis[MAX_MAP_LEAFS/8]; +static byte *mod_novis; +static int mod_novis_capacity; + +static byte *mod_decompressed; +static int mod_decompressed_capacity; #define MAX_MOD_KNOWN 2048 /*johnfitz -- was 512 */ qmodel_t mod_known[MAX_MOD_KNOWN]; @@ -55,8 +59,6 @@ void Mod_Init (void) Cvar_RegisterVariable (&gl_subdivide_size); Cvar_RegisterVariable (&external_ents); - memset (mod_novis, 0xff, sizeof(mod_novis)); - //johnfitz -- create notexture miptex r_notexture_mip = (texture_t *) Hunk_AllocName (sizeof(texture_t), "r_notexture_mip"); strcpy (r_notexture_mip->name, "notexture"); @@ -128,13 +130,19 @@ Mod_DecompressVis */ byte *Mod_DecompressVis (byte *in, qmodel_t *model) { - static byte decompressed[MAX_MAP_LEAFS/8]; int c; byte *out; int row; row = (model->numleafs+7)>>3; - out = decompressed; + if (mod_decompressed == NULL || row > mod_decompressed_capacity) + { + mod_decompressed_capacity = row; + mod_decompressed = (byte *) realloc (mod_decompressed, mod_decompressed_capacity); + if (!mod_decompressed) + Sys_Error ("Mod_DecompressVis: realloc() failed on %d bytes", mod_decompressed_capacity); + } + out = mod_decompressed; #if 0 memcpy (out, in, row); @@ -146,7 +154,7 @@ byte *Mod_DecompressVis (byte *in, qmodel_t *model) *out++ = 0xff; row--; } - return decompressed; + return mod_decompressed; } do @@ -164,19 +172,36 @@ byte *Mod_DecompressVis (byte *in, qmodel_t *model) *out++ = 0; c--; } - } while (out - decompressed < row); + } while (out - mod_decompressed < row); #endif - return decompressed; + return mod_decompressed; } byte *Mod_LeafPVS (mleaf_t *leaf, qmodel_t *model) { if (leaf == model->leafs) - return mod_novis; + return Mod_NoVisPVS (model); return Mod_DecompressVis (leaf->compressed_vis, model); } +byte *Mod_NoVisPVS (qmodel_t *model) +{ + int pvsbytes; + + pvsbytes = (model->numleafs+7)>>3; + if (mod_novis == NULL || pvsbytes > mod_novis_capacity) + { + mod_novis_capacity = pvsbytes; + mod_novis = (byte *) realloc (mod_novis, mod_novis_capacity); + if (!mod_novis) + Sys_Error ("Mod_NoVisPVS: realloc() failed on %d bytes", mod_novis_capacity); + + memset(mod_novis, 0xff, mod_novis_capacity); + } + return mod_novis; +} + /* =================== Mod_ClearAll @@ -1481,10 +1506,6 @@ void Mod_ProcessLeafs_L1 (dl1leaf_t *in, int filelen) out = (mleaf_t *) Hunk_AllocName (count * sizeof(*out), loadname); - - if (count > MAX_MAP_LEAFS) - Host_Error ("Mod_LoadLeafs: %i leafs exceeds limit of %i.\n", count, MAX_MAP_LEAFS); - loadmodel->leafs = out; loadmodel->numleafs = count; @@ -1528,10 +1549,6 @@ void Mod_ProcessLeafs_L2 (dl2leaf_t *in, int filelen) out = (mleaf_t *) Hunk_AllocName (count * sizeof(*out), loadname); - - if (count > MAX_MAP_LEAFS) - Host_Error ("Mod_LoadLeafs: %i leafs exceeds limit of %i.\n", count, MAX_MAP_LEAFS); - loadmodel->leafs = out; loadmodel->numleafs = count; @@ -1901,11 +1918,8 @@ void Mod_LoadSubmodels (lump_t *l) // johnfitz -- check world visleafs -- adapted from bjp out = loadmodel->submodels; - if (out->visleafs > MAX_MAP_LEAFS) - Sys_Error ("Mod_LoadSubmodels: too many visleafs (%d, max = %d) in %s", out->visleafs, MAX_MAP_LEAFS, loadmodel->name); - if (out->visleafs > 8192) - Con_DWarning ("%i visleafs exceeds standard limit of 8192 (max = %d).\n", out->visleafs, MAX_MAP_LEAFS); + Con_DWarning ("%i visleafs exceeds standard limit of 8192.\n", out->visleafs); //johnfitz } diff --git a/Quake/gl_model.h b/Quake/gl_model.h index 4b1acc55..fba67cf9 100644 --- a/Quake/gl_model.h +++ b/Quake/gl_model.h @@ -509,6 +509,7 @@ void Mod_TouchModel (const char *name); mleaf_t *Mod_PointInLeaf (float *p, qmodel_t *model); byte *Mod_LeafPVS (mleaf_t *leaf, qmodel_t *model); +byte *Mod_NoVisPVS (qmodel_t *model); void Mod_SetExtraFlags (qmodel_t *mod); diff --git a/Quake/pr_cmds.c b/Quake/pr_cmds.c index 5336badf..115fe379 100644 --- a/Quake/pr_cmds.c +++ b/Quake/pr_cmds.c @@ -735,7 +735,8 @@ static void PF_checkpos (void) //============================================================================ -static byte checkpvs[MAX_MAP_LEAFS/8]; +static byte *checkpvs; //ericw -- changed to malloc +static int checkpvs_capacity; static int PF_newcheckclient (int check) { @@ -744,6 +745,7 @@ static int PF_newcheckclient (int check) edict_t *ent; mleaf_t *leaf; vec3_t org; + int pvsbytes; // cycle to the next one @@ -782,7 +784,16 @@ static int PF_newcheckclient (int check) VectorAdd (ent->v.origin, ent->v.view_ofs, org); leaf = Mod_PointInLeaf (org, sv.worldmodel); pvs = Mod_LeafPVS (leaf, sv.worldmodel); - memcpy (checkpvs, pvs, (sv.worldmodel->numleafs+7)>>3 ); + + pvsbytes = (sv.worldmodel->numleafs+7)>>3; + if (checkpvs == NULL || pvsbytes > checkpvs_capacity) + { + checkpvs_capacity = pvsbytes; + checkpvs = (byte *) realloc (checkpvs, checkpvs_capacity); + if (!checkpvs) + Sys_Error ("PF_newcheckclient: realloc() failed on %d bytes", checkpvs_capacity); + } + memcpy (checkpvs, pvs, pvsbytes); return i; } diff --git a/Quake/r_world.c b/Quake/r_world.c index 95e957e2..365e74dd 100644 --- a/Quake/r_world.c +++ b/Quake/r_world.c @@ -29,7 +29,7 @@ extern cvar_t gl_fullbrights, r_drawflat, gl_overbright, r_oldwater, r_oldskylea extern glpoly_t *lightmap_polys[MAX_LIGHTMAPS]; byte *SV_FatPVS (vec3_t org, qmodel_t *worldmodel); -extern byte mod_novis[MAX_MAP_LEAFS/8]; + int vis_changed; //if true, force pvs to be refreshed //============================================================================== @@ -96,7 +96,7 @@ void R_MarkSurfaces (void) // choose vis data if (r_novis.value || r_viewleaf->contents == CONTENTS_SOLID || r_viewleaf->contents == CONTENTS_SKY) - vis = &mod_novis[0]; + vis = Mod_NoVisPVS (cl.worldmodel); else if (nearwaterportal) vis = SV_FatPVS (r_origin, cl.worldmodel); else diff --git a/Quake/sv_main.c b/Quake/sv_main.c index 6cfa20e7..5b9e1206 100644 --- a/Quake/sv_main.c +++ b/Quake/sv_main.c @@ -460,8 +460,9 @@ crosses a waterline. ============================================================================= */ -int fatbytes; -byte fatpvs[MAX_MAP_LEAFS/8]; +static int fatbytes; +static byte *fatpvs; +static int fatpvs_capacity; void SV_AddToFatPVS (vec3_t org, mnode_t *node, qmodel_t *worldmodel) //johnfitz -- added worldmodel as a parameter { @@ -508,7 +509,15 @@ given point. */ byte *SV_FatPVS (vec3_t org, qmodel_t *worldmodel) //johnfitz -- added worldmodel as a parameter { - fatbytes = (worldmodel->numleafs+31)>>3; + fatbytes = (worldmodel->numleafs+7)>>3; // ericw -- was +31, assumed to be a bug/typo + if (fatpvs == NULL || fatbytes > fatpvs_capacity) + { + fatpvs_capacity = fatbytes; + fatpvs = (byte *) realloc (fatpvs, fatpvs_capacity); + if (!fatpvs) + Sys_Error ("SV_FatPVS: realloc() failed on %d bytes", fatpvs_capacity); + } + Q_memset (fatpvs, 0, fatbytes); SV_AddToFatPVS (org, worldmodel->nodes, worldmodel); //johnfitz -- worldmodel as a parameter return fatpvs;