From a20717c364c6873bb9a6ca76874c49cc6c734f98 Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 24 Sep 2021 16:27:10 +0300 Subject: [PATCH] std::vector bspLeafBrushes --- tools/quake3/q3map2/bspfile_abstract.cpp | 6 +++--- tools/quake3/q3map2/bspfile_ibsp.cpp | 6 +++--- tools/quake3/q3map2/bspfile_rbsp.cpp | 6 +++--- tools/quake3/q3map2/convert_json.cpp | 7 ++----- tools/quake3/q3map2/light_ydnar.cpp | 10 ++++------ tools/quake3/q3map2/q3map2.h | 4 +--- tools/quake3/q3map2/writebsp.cpp | 18 ++++-------------- 7 files changed, 20 insertions(+), 37 deletions(-) diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index dd574452..17236eef 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -196,7 +196,7 @@ void SwapBSPFile( void ){ SwapBlock( bspLeafSurfaces ); /* leafbrushes */ - SwapBlock( (int*) bspLeafBrushes, numBSPLeafBrushes * sizeof( bspLeafBrushes[ 0 ] ) ); + SwapBlock( bspLeafBrushes ); // brushes SwapBlock( (int*) bspBrushes, numBSPBrushes * sizeof( bspBrushes[ 0 ] ) ); @@ -484,8 +484,8 @@ void PrintBSPFileSizes( void ){ bspLeafs.size(), bspLeafs.size() * sizeof( bspLeafs[0] ) ); 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( "%9zu leafbrushes %9zu\n", + bspLeafBrushes.size(), bspLeafBrushes.size() * sizeof( bspLeafBrushes[0] ) ); Sys_Printf( "\n" ); Sys_Printf( "%9d drawsurfaces %9d *\n", diff --git a/tools/quake3/q3map2/bspfile_ibsp.cpp b/tools/quake3/q3map2/bspfile_ibsp.cpp index 3128a4f6..2bdf372d 100644 --- a/tools/quake3/q3map2/bspfile_ibsp.cpp +++ b/tools/quake3/q3map2/bspfile_ibsp.cpp @@ -445,9 +445,9 @@ void LoadIBSPFile( const char *filename ){ CopyLump( (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces ); - numBSPLeafBrushes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFBRUSHES, (void **) &bspLeafBrushes, sizeof( bspLeafBrushes[ 0 ] ), &allocatedBSPLeafBrushes ); + CopyLump( (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes ); - numBSPBrushes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_BRUSHES, (void **) &bspBrushes, sizeof( bspBrush_t ), &allocatedBSPLeafBrushes ); + numBSPBrushes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_BRUSHES, (void **) &bspBrushes, sizeof( bspBrush_t ), &allocatedBSPBrushes ); CopyBrushSidesLump( header ); @@ -558,7 +558,7 @@ void WriteIBSPFile( const char *filename ){ AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); AddBrushSidesLump( file, header ); AddLump( file, header->lumps[LUMP_LEAFSURFACES], bspLeafSurfaces ); - AddLump( file, (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes, numBSPLeafBrushes * sizeof( bspLeafBrushes[ 0 ] ) ); + AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes ); AddLump( file, header->lumps[LUMP_MODELS], bspModels ); AddDrawVertsLump( file, header ); AddDrawSurfacesLump( file, header ); diff --git a/tools/quake3/q3map2/bspfile_rbsp.cpp b/tools/quake3/q3map2/bspfile_rbsp.cpp index 63dc0c17..60a76932 100644 --- a/tools/quake3/q3map2/bspfile_rbsp.cpp +++ b/tools/quake3/q3map2/bspfile_rbsp.cpp @@ -236,9 +236,9 @@ void LoadRBSPFile( const char *filename ){ CopyLump( (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces ); - numBSPLeafBrushes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFBRUSHES, (void **) &bspLeafBrushes, sizeof( bspLeafBrushes[ 0 ] ), &allocatedBSPLeafBrushes ); + CopyLump( (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes ); - numBSPBrushes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_BRUSHES, (void **) &bspBrushes, sizeof( bspBrush_t ), &allocatedBSPLeafBrushes ); + numBSPBrushes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_BRUSHES, (void **) &bspBrushes, sizeof( bspBrush_t ), &allocatedBSPBrushes ); numBSPBrushSides = CopyLump_Allocate( (bspHeader_t*) header, LUMP_BRUSHSIDES, (void **) &bspBrushSides, sizeof( bspBrushSide_t ), &allocatedBSPBrushSides ); @@ -311,7 +311,7 @@ void WriteRBSPFile( const char *filename ){ 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, header->lumps[LUMP_LEAFSURFACES], bspLeafSurfaces ); - AddLump( file, (bspHeader_t*) header, LUMP_LEAFBRUSHES, bspLeafBrushes, numBSPLeafBrushes * sizeof( bspLeafBrushes[ 0 ] ) ); + AddLump( file, header->lumps[LUMP_LEAFBRUSHES], bspLeafBrushes ); AddLump( file, header->lumps[LUMP_MODELS], bspModels ); AddLump( file, (bspHeader_t*) header, LUMP_DRAWVERTS, bspDrawVerts, numBSPDrawVerts * sizeof( bspDrawVerts[ 0 ] ) ); AddLump( file, (bspHeader_t*) header, LUMP_SURFACES, bspDrawSurfaces, numBSPDrawSurfaces * sizeof( bspDrawSurfaces[ 0 ] ) ); diff --git a/tools/quake3/q3map2/convert_json.cpp b/tools/quake3/q3map2/convert_json.cpp index ad77138d..a6ab900b 100644 --- a/tools/quake3/q3map2/convert_json.cpp +++ b/tools/quake3/q3map2/convert_json.cpp @@ -230,7 +230,7 @@ static void write_json( const char *directory ){ } { doc.RemoveAllMembers(); - for_indexed( auto&& lb : Span( bspLeafBrushes, numBSPLeafBrushes ) ){ + for_indexed( const auto& lb : bspLeafBrushes ){ rapidjson::Value value( rapidjson::kObjectType ); value.AddMember( "Num", lb, all ); doc.AddMember( rapidjson::Value( StringOutputStream( 16 )( "LeafBrush#", i ).c_str(), all ), value, all ); @@ -441,13 +441,10 @@ static void read_json( const char *directory ){ } { const auto doc = load_json( StringOutputStream( 256 )( directory, "LeafBrushes.json" ) ); - static std::vector items; for( auto&& obj : doc.GetObj() ){ - auto&& item = items.emplace_back(); + auto&& item = bspLeafBrushes.emplace_back(); item = obj.value["Num"].GetInt(); } - bspLeafBrushes = items.data(); - numBSPLeafBrushes = items.size(); } { const auto doc = load_json( StringOutputStream( 256 )( directory, "Brushes.json" ) ); diff --git a/tools/quake3/q3map2/light_ydnar.cpp b/tools/quake3/q3map2/light_ydnar.cpp index e3aa920f..a5eb02f4 100644 --- a/tools/quake3/q3map2/light_ydnar.cpp +++ b/tools/quake3/q3map2/light_ydnar.cpp @@ -3135,7 +3135,6 @@ int ClusterForPoint( const Vector3& point ){ int ClusterForPointExt( const Vector3& point, float epsilon ){ int i, j, b, leafNum, cluster; bool inside; - int *brushes, numBSPBrushes; bspBrush_t *brush; @@ -3153,8 +3152,8 @@ int ClusterForPointExt( const Vector3& point, float epsilon ){ } /* transparent leaf, so check point against all brushes in the leaf */ - brushes = &bspLeafBrushes[ leaf.firstBSPLeafBrush ]; - numBSPBrushes = leaf.numBSPLeafBrushes; + const int *brushes = &bspLeafBrushes[ leaf.firstBSPLeafBrush ]; + const int numBSPBrushes = leaf.numBSPLeafBrushes; for ( i = 0; i < numBSPBrushes; i++ ) { /* get parts */ @@ -3229,7 +3228,6 @@ int ClusterForPointExtFilter( const Vector3& point, float epsilon, int numCluste int ShaderForPointInLeaf( const Vector3& point, int leafNum, float epsilon, int wantContentFlags, int wantSurfaceFlags, int *contentFlags, int *surfaceFlags ){ int i, j; bool inside; - int *brushes, numBSPBrushes; bspBrush_t *brush; bspBrushSide_t *side; int allSurfaceFlags, allContentFlags; @@ -3246,8 +3244,8 @@ int ShaderForPointInLeaf( const Vector3& point, int leafNum, float epsilon, int const bspLeaf_t& leaf = bspLeafs[ leafNum ]; /* transparent leaf, so check point against all brushes in the leaf */ - brushes = &bspLeafBrushes[ leaf.firstBSPLeafBrush ]; - numBSPBrushes = leaf.numBSPLeafBrushes; + const int *brushes = &bspLeafBrushes[ leaf.firstBSPLeafBrush ]; + const int numBSPBrushes = leaf.numBSPLeafBrushes; for ( i = 0; i < numBSPBrushes; i++ ) { /* get parts */ diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 06db6fd7..cb79a544 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2348,9 +2348,7 @@ Q_EXTERN std::vector bspNodes; Q_EXTERN std::vector bspLeafSurfaces; -Q_EXTERN int numBSPLeafBrushes Q_ASSIGN( 0 ); -Q_EXTERN int allocatedBSPLeafBrushes Q_ASSIGN( 0 ); -Q_EXTERN int* bspLeafBrushes Q_ASSIGN( NULL ); +Q_EXTERN std::vector bspLeafBrushes; Q_EXTERN int numBSPBrushes Q_ASSIGN( 0 ); Q_EXTERN int allocatedBSPBrushes Q_ASSIGN( 0 ); diff --git a/tools/quake3/q3map2/writebsp.cpp b/tools/quake3/q3map2/writebsp.cpp index 247b31ec..6ebd3037 100644 --- a/tools/quake3/q3map2/writebsp.cpp +++ b/tools/quake3/q3map2/writebsp.cpp @@ -129,23 +129,13 @@ void EmitLeaf( node_t *node ){ leaf.minmax.mins = node->minmax.mins; /* emit leaf brushes */ - leaf.firstBSPLeafBrush = numBSPLeafBrushes; + leaf.firstBSPLeafBrush = bspLeafBrushes.size(); for ( const brush_t& b : node->brushlist ) { - /* something is corrupting brushes */ - // if ( (size_t) b < 256 ) { - // Sys_Warning( "Node brush list corrupted (0x%08X)\n", b ); - // break; - // } - //% if( b->guard != 0xDEADBEEF ) - //% Sys_Printf( "Brush %6d: 0x%08X Guard: 0x%08X Next: 0x%08X Original: 0x%08X Sides: %d\n", b->brushNum, b, b, b->next, b->original, b->numsides ); - - AUTOEXPAND_BY_REALLOC_BSP( LeafBrushes, 1024 ); - bspLeafBrushes[ numBSPLeafBrushes ] = b.original->outputNum; - numBSPLeafBrushes++; + bspLeafBrushes.push_back( b.original->outputNum ); } - leaf.numBSPLeafBrushes = numBSPLeafBrushes - leaf.firstBSPLeafBrush; + leaf.numBSPLeafBrushes = bspLeafBrushes.size() - leaf.firstBSPLeafBrush; /* emit leaf surfaces */ if ( node->opaque ) { @@ -322,7 +312,7 @@ void BeginBSPFile( void ){ bspNodes.clear(); numBSPBrushSides = 0; bspLeafSurfaces.clear(); - numBSPLeafBrushes = 0; + bspLeafBrushes.clear(); /* leave leaf 0 as an error, because leafs are referenced as negative number nodes */ bspLeafs.resize( 1 );