From 6a04feabc54f832be565ba9fd6e258466ea30e99 Mon Sep 17 00:00:00 2001 From: divverent Date: Wed, 25 Feb 2009 15:24:29 +0000 Subject: [PATCH] try to eliminate MAX_MAP_PLANES limits git-svn-id: svn://svn.icculus.org/netradiant/trunk@198 61c419a2-8eb2-4b30-bcec-8cead039b335 --- tools/quake3/q3map2/bspfile_ibsp.c | 2 +- tools/quake3/q3map2/bspfile_rbsp.c | 2 +- tools/quake3/q3map2/convert_map.c | 2 +- tools/quake3/q3map2/map.c | 12 +++++++----- tools/quake3/q3map2/model.c | 11 +---------- tools/quake3/q3map2/q3map2.h | 11 ++++++----- tools/quake3/q3map2/writebsp.c | 1 + 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/tools/quake3/q3map2/bspfile_ibsp.c b/tools/quake3/q3map2/bspfile_ibsp.c index 7874b922..591d4d14 100644 --- a/tools/quake3/q3map2/bspfile_ibsp.c +++ b/tools/quake3/q3map2/bspfile_ibsp.c @@ -481,7 +481,7 @@ void LoadIBSPFile( const char *filename ) numBSPModels = CopyLump_Allocate( (bspHeader_t*) header, LUMP_MODELS, (void **) &bspModels, sizeof( bspModel_t ), &allocatedBSPModels ); - numBSPPlanes = CopyLump( (bspHeader_t*) header, LUMP_PLANES, bspPlanes, sizeof( bspPlane_t ) ); + numBSPPlanes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_PLANES, (void **) &bspPlanes, sizeof( bspPlane_t ), &allocatedBSPPlanes ); numBSPLeafs = CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs, sizeof( bspLeaf_t ) ); diff --git a/tools/quake3/q3map2/bspfile_rbsp.c b/tools/quake3/q3map2/bspfile_rbsp.c index c31da09e..6868f974 100644 --- a/tools/quake3/q3map2/bspfile_rbsp.c +++ b/tools/quake3/q3map2/bspfile_rbsp.c @@ -233,7 +233,7 @@ void LoadRBSPFile( const char *filename ) numBSPModels = CopyLump_Allocate( (bspHeader_t*) header, LUMP_MODELS, (void **) &bspModels, sizeof( bspModel_t ), &allocatedBSPModels ); - numBSPPlanes = CopyLump( (bspHeader_t*) header, LUMP_PLANES, bspPlanes, sizeof( bspPlane_t ) ); + numBSPPlanes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_PLANES, (void **) &bspPlanes, sizeof( bspPlane_t ), &allocatedBSPPlanes ); numBSPLeafs = CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs, sizeof( bspLeaf_t ) ); diff --git a/tools/quake3/q3map2/convert_map.c b/tools/quake3/q3map2/convert_map.c index 38fc738f..8e1a143e 100644 --- a/tools/quake3/q3map2/convert_map.c +++ b/tools/quake3/q3map2/convert_map.c @@ -482,7 +482,7 @@ static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, vec3_t origi VectorCopy( bspPlanes[ i ].normal, mapplanes[ i ].normal ); mapplanes[ i ].dist = bspPlanes[ i ].dist; mapplanes[ i ].type = PlaneTypeForNormal( mapplanes[ i ].normal ); - mapplanes[ i ].hash_chain = NULL; + mapplanes[ i ].hash_chain = 0; } /* allocate a build brush */ diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index 51d87afa..1bf1ddcd 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -44,7 +44,7 @@ several games based on the Quake III Arena engine, in the form of "Q3Map2." #define USE_HASHING #define PLANE_HASHES 8192 -plane_t *planehash[ PLANE_HASHES ]; +int planehash[ PLANE_HASHES ]; int c_boxbevels; int c_edgebevels; @@ -96,7 +96,7 @@ void AddPlaneToHash( plane_t *p ) hash = (PLANE_HASHES - 1) & (int) fabs( p->dist ); p->hash_chain = planehash[hash]; - planehash[hash] = p; + planehash[hash] = p - mapplanes + 1; } /* @@ -115,8 +115,7 @@ int CreateNewFloatPlane (vec3_t normal, vec_t dist) } // create a new plane - if (nummapplanes+2 > MAX_MAP_PLANES) - Error ("MAX_MAP_PLANES"); + AUTOEXPAND_BY_REALLOC(mapplanes, nummapplanes+1, allocatedmapplanes, 1024); p = &mapplanes[nummapplanes]; VectorCopy (normal, p->normal); @@ -219,6 +218,7 @@ int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ) / { int i, j, hash, h; + int pidx; plane_t *p; vec_t d; vec3_t centerofweight; @@ -235,8 +235,10 @@ int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ) / for( i = -1; i <= 1; i++ ) { h = (hash + i) & (PLANE_HASHES - 1); - for( p = planehash[ h ]; p != NULL; p = p->hash_chain ) + for( pidx = planehash[ h ] - 1; pidx != -1; pidx = mapplanes[pidx].hash_chain - 1 ) { + p = &mapplanes[pidx]; + /* do standard plane compare */ if( !PlaneEqual( p, normal, dist ) ) continue; diff --git a/tools/quake3/q3map2/model.c b/tools/quake3/q3map2/model.c index f2a04c10..9847f664 100644 --- a/tools/quake3/q3map2/model.c +++ b/tools/quake3/q3map2/model.c @@ -409,20 +409,11 @@ void InsertModel( char *name, int frame, m4x4_t transform, remap_t *remap, shade ((si->compileFlags & C_TRANSLUCENT) || !(si->compileFlags & C_SOLID)) ) continue; - /* overflow check */ - if( (nummapplanes + 64) >= (MAX_MAP_PLANES >> 1) ) - continue; - /* walk triangle list */ for( i = 0; i < ds->numIndexes; i += 3 ) { /* overflow hack */ - if( (nummapplanes + 64) >= (MAX_MAP_PLANES >> 1) ) - { - Sys_Printf( "WARNING: MAX_MAP_PLANES (%d) hit generating clip brushes for model %s.\n", - MAX_MAP_PLANES, name ); - break; - } + AUTOEXPAND_BY_REALLOC(mapplanes, (nummapplanes+64) << 1, allocatedmapplanes, 1024); /* make points and back points */ for( j = 0; j < 3; j++ ) diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 29e1c791..53ec4c54 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -310,7 +310,6 @@ abstracted bsp file #define MAX_MAP_AREAS 0x100 /* MAX_MAP_AREA_BYTES in q_shared must match! */ #define MAX_MAP_FOGS 30 //& 0x100 /* RBSP (32 - world fog - goggles) */ -#define MAX_MAP_PLANES 0x200000 //% 0x20000 /* ydnar for md */ #define MAX_MAP_LEAFS 0x20000 #define MAX_MAP_PORTALS 0x20000 #define MAX_MAP_LIGHTING 0x800000 @@ -791,7 +790,7 @@ typedef struct plane_s vec3_t normal; vec_t dist; int type; - struct plane_s *hash_chain; + int hash_chain; } plane_t; @@ -1961,8 +1960,9 @@ Q_EXTERN int mapEntityNum Q_ASSIGN( 0 ); Q_EXTERN int entitySourceBrushes; -Q_EXTERN plane_t mapplanes[ MAX_MAP_PLANES ]; /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */ -Q_EXTERN int nummapplanes; /* nummapplanes will always be even */ +Q_EXTERN plane_t *mapplanes Q_ASSIGN(NULL); /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */ +Q_EXTERN int nummapplanes Q_ASSIGN(0); /* nummapplanes will always be even */ +Q_EXTERN int allocatedmapplanes Q_ASSIGN(0); Q_EXTERN int numMapPatches; Q_EXTERN vec3_t mapMins, mapMaxs; @@ -2317,7 +2317,8 @@ Q_EXTERN int numBSPLeafs Q_ASSIGN( 0 ); Q_EXTERN bspLeaf_t bspLeafs[ MAX_MAP_LEAFS ]; Q_EXTERN int numBSPPlanes Q_ASSIGN( 0 ); -Q_EXTERN bspPlane_t bspPlanes[ MAX_MAP_PLANES ]; +Q_EXTERN int allocatedBSPPlanes Q_ASSIGN(0); +Q_EXTERN bspPlane_t *bspPlanes; Q_EXTERN int numBSPNodes Q_ASSIGN( 0 ); Q_EXTERN int allocatedBSPNodes Q_ASSIGN( 0 ); diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c index 96e8ce29..c9f5f731 100644 --- a/tools/quake3/q3map2/writebsp.c +++ b/tools/quake3/q3map2/writebsp.c @@ -116,6 +116,7 @@ void EmitPlanes( void ) mp = mapplanes; for( i = 0; i < nummapplanes; i++, mp++ ) { + AUTOEXPAND_BY_REALLOC_BSP(Planes, 1024); bp = &bspPlanes[ numBSPPlanes ]; VectorCopy( mp->normal, bp->normal ); bp->dist = mp->dist; -- 2.39.2