diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index f92e81c7..dd574452 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -193,7 +193,7 @@ void SwapBSPFile( void ){ SwapBlock( bspLeafs ); /* leaffaces */ - SwapBlock( (int*) bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) ); + SwapBlock( bspLeafSurfaces ); /* leafbrushes */ SwapBlock( (int*) bspLeafBrushes, numBSPLeafBrushes * sizeof( bspLeafBrushes[ 0 ] ) ); @@ -482,8 +482,8 @@ void PrintBSPFileSizes( void ){ bspNodes.size(), bspNodes.size() * sizeof( bspNodes[0] ) ); Sys_Printf( "%9zu leafs %9zu\n", bspLeafs.size(), bspLeafs.size() * sizeof( bspLeafs[0] ) ); - Sys_Printf( "%9d leafsurfaces %9d\n", - numBSPLeafSurfaces, (int) ( numBSPLeafSurfaces * sizeof( *bspLeafSurfaces ) ) ); + Sys_Printf( "%zu leafsurfaces %zu\n", + bspLeafSurfaces.size(), bspLeafSurfaces.size() * sizeof( bspLeafSurfaces[0] ) ); Sys_Printf( "%9d leafbrushes %9d\n", numBSPLeafBrushes, (int) ( numBSPLeafBrushes * sizeof( *bspLeafBrushes ) ) ); Sys_Printf( "\n" ); diff --git a/tools/quake3/q3map2/bspfile_ibsp.cpp b/tools/quake3/q3map2/bspfile_ibsp.cpp index e3c54af9..3128a4f6 100644 --- a/tools/quake3/q3map2/bspfile_ibsp.cpp +++ b/tools/quake3/q3map2/bspfile_ibsp.cpp @@ -443,7 +443,7 @@ void LoadIBSPFile( const char *filename ){ CopyLump( (bspHeader_t*) header, LUMP_NODES, bspNodes ); - numBSPLeafSurfaces = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFSURFACES, (void **) &bspLeafSurfaces, sizeof( bspLeafSurfaces[ 0 ] ), &allocatedBSPLeafSurfaces ); + CopyLump( (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces ); numBSPLeafBrushes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFBRUSHES, (void **) &bspLeafBrushes, sizeof( bspLeafBrushes[ 0 ] ), &allocatedBSPLeafBrushes ); @@ -557,7 +557,7 @@ void WriteIBSPFile( const char *filename ){ AddLump( file, header->lumps[LUMP_NODES], bspNodes ); AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); AddBrushSidesLump( file, header ); - AddLump( file, (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) ); + AddLump( file, header->lumps[LUMP_LEAFSURFACES], bspLeafSurfaces ); AddLump( file, (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes, numBSPLeafBrushes * sizeof( bspLeafBrushes[ 0 ] ) ); AddLump( file, header->lumps[LUMP_MODELS], bspModels ); AddDrawVertsLump( file, header ); diff --git a/tools/quake3/q3map2/bspfile_rbsp.cpp b/tools/quake3/q3map2/bspfile_rbsp.cpp index 27b4246b..63dc0c17 100644 --- a/tools/quake3/q3map2/bspfile_rbsp.cpp +++ b/tools/quake3/q3map2/bspfile_rbsp.cpp @@ -234,7 +234,7 @@ void LoadRBSPFile( const char *filename ){ CopyLump( (bspHeader_t*) header, LUMP_NODES, bspNodes ); - numBSPLeafSurfaces = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFSURFACES, (void **) &bspLeafSurfaces, sizeof( bspLeafSurfaces[ 0 ] ), &allocatedBSPLeafSurfaces ); + CopyLump( (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces ); numBSPLeafBrushes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFBRUSHES, (void **) &bspLeafBrushes, sizeof( bspLeafBrushes[ 0 ] ), &allocatedBSPLeafBrushes ); @@ -310,7 +310,7 @@ void WriteRBSPFile( const char *filename ){ AddLump( file, header->lumps[LUMP_NODES], bspNodes ); AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_BRUSHSIDES, bspBrushSides, numBSPBrushSides * sizeof( bspBrushSides[ 0 ] ) ); - AddLump( file, (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) ); + AddLump( file, header->lumps[LUMP_LEAFSURFACES], bspLeafSurfaces ); AddLump( file, (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes, numBSPLeafBrushes * sizeof( bspLeafBrushes[ 0 ] ) ); AddLump( file, header->lumps[LUMP_MODELS], bspModels ); AddLump( file, (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVerts[ 0 ] ) ); diff --git a/tools/quake3/q3map2/convert_json.cpp b/tools/quake3/q3map2/convert_json.cpp index f21d2849..ad77138d 100644 --- a/tools/quake3/q3map2/convert_json.cpp +++ b/tools/quake3/q3map2/convert_json.cpp @@ -221,7 +221,7 @@ static void write_json( const char *directory ){ } { doc.RemoveAllMembers(); - for_indexed( auto&& ls : Span( bspLeafSurfaces, numBSPLeafSurfaces ) ){ + for_indexed( const auto& ls : bspLeafSurfaces ){ rapidjson::Value value( rapidjson::kObjectType ); value.AddMember( "Num", ls, all ); doc.AddMember( rapidjson::Value( StringOutputStream( 16 )( "LeafSurface#", i ).c_str(), all ), value, all ); @@ -434,13 +434,10 @@ static void read_json( const char *directory ){ } { const auto doc = load_json( StringOutputStream( 256 )( directory, "LeafSurfaces.json" ) ); - static std::vector items; for( auto&& obj : doc.GetObj() ){ - auto&& item = items.emplace_back(); + auto&& item = bspLeafSurfaces.emplace_back(); item = obj.value["Num"].GetInt(); } - bspLeafSurfaces = items.data(); - numBSPLeafSurfaces = items.size(); } { const auto doc = load_json( StringOutputStream( 256 )( directory, "LeafBrushes.json" ) ); diff --git a/tools/quake3/q3map2/lightmaps_ydnar.cpp b/tools/quake3/q3map2/lightmaps_ydnar.cpp index 40c2040f..7c4ddeff 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.cpp +++ b/tools/quake3/q3map2/lightmaps_ydnar.cpp @@ -947,7 +947,7 @@ void SetupSurfaceLightmaps( void ){ /* allocate a list of surface clusters */ numSurfaceClusters = 0; - maxSurfaceClusters = numBSPLeafSurfaces; + maxSurfaceClusters = bspLeafSurfaces.size(); surfaceClusters = safe_calloc( maxSurfaceClusters * sizeof( *surfaceClusters ) ); /* allocate a list for per-surface info */ diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 0be95c93..06db6fd7 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2346,9 +2346,7 @@ Q_EXTERN std::vector bspPlanes; Q_EXTERN std::vector bspNodes; -Q_EXTERN int numBSPLeafSurfaces Q_ASSIGN( 0 ); -Q_EXTERN int allocatedBSPLeafSurfaces Q_ASSIGN( 0 ); -Q_EXTERN int* bspLeafSurfaces Q_ASSIGN( NULL ); +Q_EXTERN std::vector bspLeafSurfaces; Q_EXTERN int numBSPLeafBrushes Q_ASSIGN( 0 ); Q_EXTERN int allocatedBSPLeafBrushes Q_ASSIGN( 0 ); diff --git a/tools/quake3/q3map2/writebsp.cpp b/tools/quake3/q3map2/writebsp.cpp index 0fb60ff1..247b31ec 100644 --- a/tools/quake3/q3map2/writebsp.cpp +++ b/tools/quake3/q3map2/writebsp.cpp @@ -153,15 +153,13 @@ void EmitLeaf( node_t *node ){ } /* add the drawSurfRef_t drawsurfs */ - leaf.firstBSPLeafSurface = numBSPLeafSurfaces; + leaf.firstBSPLeafSurface = bspLeafSurfaces.size(); for ( const drawSurfRef_t *dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef ) { - AUTOEXPAND_BY_REALLOC_BSP( LeafSurfaces, 1024 ); - bspLeafSurfaces[ numBSPLeafSurfaces ] = dsr->outputNum; - numBSPLeafSurfaces++; + bspLeafSurfaces.push_back( dsr->outputNum ); } - leaf.numBSPLeafSurfaces = numBSPLeafSurfaces - leaf.firstBSPLeafSurface; + leaf.numBSPLeafSurfaces = bspLeafSurfaces.size() - leaf.firstBSPLeafSurface; } @@ -323,7 +321,7 @@ void BeginBSPFile( void ){ bspModels.clear(); bspNodes.clear(); numBSPBrushSides = 0; - numBSPLeafSurfaces = 0; + bspLeafSurfaces.clear(); numBSPLeafBrushes = 0; /* leave leaf 0 as an error, because leafs are referenced as negative number nodes */