From bccd3bafd744b543512a065c55339bf668e0c001 Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 24 Sep 2021 15:43:24 +0300 Subject: [PATCH] std::vector bspPlanes --- tools/quake3/q3map2/bspfile_abstract.cpp | 6 +++--- tools/quake3/q3map2/bspfile_ibsp.cpp | 4 ++-- tools/quake3/q3map2/bspfile_rbsp.cpp | 4 ++-- tools/quake3/q3map2/convert_bsp.cpp | 18 +++++++++--------- tools/quake3/q3map2/convert_json.cpp | 7 ++----- tools/quake3/q3map2/convert_map.cpp | 4 ++-- tools/quake3/q3map2/q3map2.h | 4 +--- tools/quake3/q3map2/writebsp.cpp | 9 ++++----- 8 files changed, 25 insertions(+), 31 deletions(-) diff --git a/tools/quake3/q3map2/bspfile_abstract.cpp b/tools/quake3/q3map2/bspfile_abstract.cpp index 0ced3681..4b6e9f7a 100644 --- a/tools/quake3/q3map2/bspfile_abstract.cpp +++ b/tools/quake3/q3map2/bspfile_abstract.cpp @@ -184,7 +184,7 @@ void SwapBSPFile( void ){ } /* planes */ - SwapBlock( (int*) bspPlanes, numBSPPlanes * sizeof( bspPlanes[ 0 ] ) ); + SwapBlock( bspPlanes ); /* nodes */ SwapBlock( (int*) bspNodes, numBSPNodes * sizeof( bspNodes[ 0 ] ) ); @@ -472,8 +472,8 @@ void PrintBSPFileSizes( void ){ numBSPBrushSides, (int) ( numBSPBrushSides * sizeof( bspBrushSide_t ) ) ); Sys_Printf( "%9d fogs %9d\n", numBSPFogs, (int) ( numBSPFogs * sizeof( bspFog_t ) ) ); - Sys_Printf( "%9d planes %9d\n", - numBSPPlanes, (int) ( numBSPPlanes * sizeof( bspPlane_t ) ) ); + Sys_Printf( "%9zu planes %9zu\n", + bspPlanes.size(), bspPlanes.size() * sizeof( bspPlanes[0] ) ); Sys_Printf( "%9zu entdata %9zu\n", entities.size(), bspEntData.size() ); Sys_Printf( "\n" ); diff --git a/tools/quake3/q3map2/bspfile_ibsp.cpp b/tools/quake3/q3map2/bspfile_ibsp.cpp index ad613778..d6e60822 100644 --- a/tools/quake3/q3map2/bspfile_ibsp.cpp +++ b/tools/quake3/q3map2/bspfile_ibsp.cpp @@ -437,7 +437,7 @@ void LoadIBSPFile( const char *filename ){ CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels ); - numBSPPlanes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_PLANES, (void **) &bspPlanes, sizeof( bspPlane_t ), &allocatedBSPPlanes ); + CopyLump( (bspHeader_t*) header, LUMP_PLANES, bspPlanes ); CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs ); @@ -552,7 +552,7 @@ void WriteIBSPFile( const char *filename ){ /* add lumps */ AddLump( file, header->lumps[LUMP_SHADERS], bspShaders ); - AddLump( file, (bspHeader_t*) header, LUMP_PLANES, bspPlanes, numBSPPlanes * sizeof( bspPlane_t ) ); + AddLump( file, header->lumps[LUMP_PLANES], bspPlanes ); AddLump( file, header->lumps[LUMP_LEAFS], bspLeafs ); AddLump( file, (bspHeader_t*) header, LUMP_NODES, bspNodes, numBSPNodes * sizeof( bspNode_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); diff --git a/tools/quake3/q3map2/bspfile_rbsp.cpp b/tools/quake3/q3map2/bspfile_rbsp.cpp index d5338133..89e8979a 100644 --- a/tools/quake3/q3map2/bspfile_rbsp.cpp +++ b/tools/quake3/q3map2/bspfile_rbsp.cpp @@ -228,7 +228,7 @@ void LoadRBSPFile( const char *filename ){ CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels ); - numBSPPlanes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_PLANES, (void **) &bspPlanes, sizeof( bspPlane_t ), &allocatedBSPPlanes ); + CopyLump( (bspHeader_t*) header, LUMP_PLANES, bspPlanes ); CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs ); @@ -305,7 +305,7 @@ void WriteRBSPFile( const char *filename ){ /* add lumps */ AddLump( file, header->lumps[LUMP_SHADERS], bspShaders ); - AddLump( file, (bspHeader_t*) header, LUMP_PLANES, bspPlanes, numBSPPlanes * sizeof( bspPlane_t ) ); + AddLump( file, header->lumps[LUMP_PLANES], bspPlanes ); AddLump( file, header->lumps[LUMP_LEAFS], bspLeafs ); AddLump( file, (bspHeader_t*) header, LUMP_NODES, bspNodes, numBSPNodes * sizeof( bspNode_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); diff --git a/tools/quake3/q3map2/convert_bsp.cpp b/tools/quake3/q3map2/convert_bsp.cpp index f27877a4..ae21f996 100644 --- a/tools/quake3/q3map2/convert_bsp.cpp +++ b/tools/quake3/q3map2/convert_bsp.cpp @@ -552,19 +552,19 @@ int ScaleBSPMain( Args& args ){ /* scale planes */ if ( uniform ) { - for ( i = 0; i < numBSPPlanes; i++ ) + for ( bspPlane_t& plane : bspPlanes ) { - bspPlanes[ i ].dist() *= scale[0]; + plane.dist() *= scale[0]; } } else { - for ( i = 0; i < numBSPPlanes; i++ ) + for ( bspPlane_t& plane : bspPlanes ) { - bspPlanes[i].normal() /= scale; - const double len = vector3_length( bspPlanes[i].normal() ); - bspPlanes[i].normal() /= len; - bspPlanes[i].dist() /= len; + plane.normal() /= scale; + const double len = vector3_length( plane.normal() ); + plane.normal() /= len; + plane.dist() /= len; } } @@ -674,9 +674,9 @@ int ShiftBSPMain( Args& args ){ } /* shift planes */ - for ( i = 0; i < numBSPPlanes; i++ ) + for ( bspPlane_t& plane : bspPlanes ) { - bspPlanes[i].dist() = vector3_dot( bspPlanes[i].normal(), bspPlanes[i].normal() * bspPlanes[i].dist() + shift ); + plane.dist() = vector3_dot( plane.normal(), plane.normal() * plane.dist() + shift ); } // fixme: engine says 'light grid mismatch', unless translation is multiple of grid size diff --git a/tools/quake3/q3map2/convert_json.cpp b/tools/quake3/q3map2/convert_json.cpp index 4f9ed723..11793c23 100644 --- a/tools/quake3/q3map2/convert_json.cpp +++ b/tools/quake3/q3map2/convert_json.cpp @@ -173,7 +173,7 @@ static void write_json( const char *directory ){ } { doc.RemoveAllMembers(); - for_indexed( auto&& plane : Span( bspPlanes, numBSPPlanes ) ){ + for_indexed( const auto& plane : bspPlanes ){ rapidjson::Value value( rapidjson::kArrayType ); value.PushBack( plane.a, all ); value.PushBack( plane.b, all ); @@ -399,16 +399,13 @@ static void read_json( const char *directory ){ } { const auto doc = load_json( StringOutputStream( 256 )( directory, "planes.json" ) ); - static std::vector items; for( auto&& obj : doc.GetObj() ){ - auto&& item = items.emplace_back(); + auto&& item = bspPlanes.emplace_back(); item.a = obj.value[0].GetFloat(); item.b = obj.value[1].GetFloat(); item.c = obj.value[2].GetFloat(); item.d = obj.value[3].GetFloat(); } - bspPlanes = items.data(); - numBSPPlanes = items.size(); } { const auto doc = load_json( StringOutputStream( 256 )( directory, "leafs.json" ) ); diff --git a/tools/quake3/q3map2/convert_map.cpp b/tools/quake3/q3map2/convert_map.cpp index b2ed58ef..4ffef132 100644 --- a/tools/quake3/q3map2/convert_map.cpp +++ b/tools/quake3/q3map2/convert_map.cpp @@ -823,8 +823,8 @@ static void ConvertModel( FILE *f, const bspModel_t& model, const Vector3& origi /* convert bsp planes to map planes */ - mapplanes.resize( numBSPPlanes ); - for ( i = 0; i < numBSPPlanes; i++ ) + mapplanes.resize( bspPlanes.size() ); + for ( size_t i = 0; i < bspPlanes.size(); ++i ) { plane_t& plane = mapplanes[i]; plane.plane = bspPlanes[ i ]; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index e1498f69..ce0b93cc 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2342,9 +2342,7 @@ Q_EXTERN std::vector bspEntData; Q_EXTERN std::vector bspLeafs; // MAX_MAP_LEAFS -Q_EXTERN int numBSPPlanes Q_ASSIGN( 0 ); -Q_EXTERN int allocatedBSPPlanes Q_ASSIGN( 0 ); -Q_EXTERN bspPlane_t *bspPlanes; +Q_EXTERN std::vector bspPlanes; Q_EXTERN int numBSPNodes Q_ASSIGN( 0 ); Q_EXTERN int allocatedBSPNodes Q_ASSIGN( 0 ); diff --git a/tools/quake3/q3map2/writebsp.cpp b/tools/quake3/q3map2/writebsp.cpp index 8adefd07..286a37fe 100644 --- a/tools/quake3/q3map2/writebsp.cpp +++ b/tools/quake3/q3map2/writebsp.cpp @@ -100,16 +100,15 @@ int EmitShader( const char *shader, const int *contentFlags, const int *surfaceF */ void EmitPlanes( void ){ + bspPlanes.reserve( mapplanes.size() ); /* walk plane list */ - for ( size_t i = 0; i < mapplanes.size(); ++i ) + for ( const plane_t& plane : mapplanes ) { - AUTOEXPAND_BY_REALLOC_BSP( Planes, 1024 ); - bspPlanes[ numBSPPlanes ] = mapplanes[i].plane; - numBSPPlanes++; + bspPlanes.push_back( plane.plane ); } /* emit some statistics */ - Sys_FPrintf( SYS_VRB, "%9d BSP planes\n", numBSPPlanes ); + Sys_FPrintf( SYS_VRB, "%9zu BSP planes\n", bspPlanes.size() ); }