std::vector<bspPlane_t> bspPlanes

This commit is contained in:
Garux 2021-09-24 15:43:24 +03:00
parent 76d2b565b3
commit bccd3bafd7
8 changed files with 25 additions and 31 deletions

View File

@ -184,7 +184,7 @@ void SwapBSPFile( void ){
} }
/* planes */ /* planes */
SwapBlock( (int*) bspPlanes, numBSPPlanes * sizeof( bspPlanes[ 0 ] ) ); SwapBlock( bspPlanes );
/* nodes */ /* nodes */
SwapBlock( (int*) bspNodes, numBSPNodes * sizeof( bspNodes[ 0 ] ) ); SwapBlock( (int*) bspNodes, numBSPNodes * sizeof( bspNodes[ 0 ] ) );
@ -472,8 +472,8 @@ void PrintBSPFileSizes( void ){
numBSPBrushSides, (int) ( numBSPBrushSides * sizeof( bspBrushSide_t ) ) ); numBSPBrushSides, (int) ( numBSPBrushSides * sizeof( bspBrushSide_t ) ) );
Sys_Printf( "%9d fogs %9d\n", Sys_Printf( "%9d fogs %9d\n",
numBSPFogs, (int) ( numBSPFogs * sizeof( bspFog_t ) ) ); numBSPFogs, (int) ( numBSPFogs * sizeof( bspFog_t ) ) );
Sys_Printf( "%9d planes %9d\n", Sys_Printf( "%9zu planes %9zu\n",
numBSPPlanes, (int) ( numBSPPlanes * sizeof( bspPlane_t ) ) ); bspPlanes.size(), bspPlanes.size() * sizeof( bspPlanes[0] ) );
Sys_Printf( "%9zu entdata %9zu\n", Sys_Printf( "%9zu entdata %9zu\n",
entities.size(), bspEntData.size() ); entities.size(), bspEntData.size() );
Sys_Printf( "\n" ); Sys_Printf( "\n" );

View File

@ -437,7 +437,7 @@ void LoadIBSPFile( const char *filename ){
CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels ); 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 ); CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs );
@ -552,7 +552,7 @@ void WriteIBSPFile( const char *filename ){
/* add lumps */ /* add lumps */
AddLump( file, header->lumps[LUMP_SHADERS], bspShaders ); 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, header->lumps[LUMP_LEAFS], bspLeafs );
AddLump( file, (bspHeader_t*) header, LUMP_NODES, bspNodes, numBSPNodes * sizeof( bspNode_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_NODES, bspNodes, numBSPNodes * sizeof( bspNode_t ) );
AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) );

View File

@ -228,7 +228,7 @@ void LoadRBSPFile( const char *filename ){
CopyLump( (bspHeader_t*) header, LUMP_MODELS, bspModels ); 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 ); CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs );
@ -305,7 +305,7 @@ void WriteRBSPFile( const char *filename ){
/* add lumps */ /* add lumps */
AddLump( file, header->lumps[LUMP_SHADERS], bspShaders ); 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, header->lumps[LUMP_LEAFS], bspLeafs );
AddLump( file, (bspHeader_t*) header, LUMP_NODES, bspNodes, numBSPNodes * sizeof( bspNode_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_NODES, bspNodes, numBSPNodes * sizeof( bspNode_t ) );
AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) );

View File

@ -552,19 +552,19 @@ int ScaleBSPMain( Args& args ){
/* scale planes */ /* scale planes */
if ( uniform ) { if ( uniform ) {
for ( i = 0; i < numBSPPlanes; i++ ) for ( bspPlane_t& plane : bspPlanes )
{ {
bspPlanes[ i ].dist() *= scale[0]; plane.dist() *= scale[0];
} }
} }
else else
{ {
for ( i = 0; i < numBSPPlanes; i++ ) for ( bspPlane_t& plane : bspPlanes )
{ {
bspPlanes[i].normal() /= scale; plane.normal() /= scale;
const double len = vector3_length( bspPlanes[i].normal() ); const double len = vector3_length( plane.normal() );
bspPlanes[i].normal() /= len; plane.normal() /= len;
bspPlanes[i].dist() /= len; plane.dist() /= len;
} }
} }
@ -674,9 +674,9 @@ int ShiftBSPMain( Args& args ){
} }
/* shift planes */ /* 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 // fixme: engine says 'light grid mismatch', unless translation is multiple of grid size

View File

@ -173,7 +173,7 @@ static void write_json( const char *directory ){
} }
{ {
doc.RemoveAllMembers(); doc.RemoveAllMembers();
for_indexed( auto&& plane : Span( bspPlanes, numBSPPlanes ) ){ for_indexed( const auto& plane : bspPlanes ){
rapidjson::Value value( rapidjson::kArrayType ); rapidjson::Value value( rapidjson::kArrayType );
value.PushBack( plane.a, all ); value.PushBack( plane.a, all );
value.PushBack( plane.b, 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" ) ); const auto doc = load_json( StringOutputStream( 256 )( directory, "planes.json" ) );
static std::vector<bspPlane_t> items;
for( auto&& obj : doc.GetObj() ){ for( auto&& obj : doc.GetObj() ){
auto&& item = items.emplace_back(); auto&& item = bspPlanes.emplace_back();
item.a = obj.value[0].GetFloat(); item.a = obj.value[0].GetFloat();
item.b = obj.value[1].GetFloat(); item.b = obj.value[1].GetFloat();
item.c = obj.value[2].GetFloat(); item.c = obj.value[2].GetFloat();
item.d = obj.value[3].GetFloat(); item.d = obj.value[3].GetFloat();
} }
bspPlanes = items.data();
numBSPPlanes = items.size();
} }
{ {
const auto doc = load_json( StringOutputStream( 256 )( directory, "leafs.json" ) ); const auto doc = load_json( StringOutputStream( 256 )( directory, "leafs.json" ) );

View File

@ -823,8 +823,8 @@ static void ConvertModel( FILE *f, const bspModel_t& model, const Vector3& origi
/* convert bsp planes to map planes */ /* convert bsp planes to map planes */
mapplanes.resize( numBSPPlanes ); mapplanes.resize( bspPlanes.size() );
for ( i = 0; i < numBSPPlanes; i++ ) for ( size_t i = 0; i < bspPlanes.size(); ++i )
{ {
plane_t& plane = mapplanes[i]; plane_t& plane = mapplanes[i];
plane.plane = bspPlanes[ i ]; plane.plane = bspPlanes[ i ];

View File

@ -2342,9 +2342,7 @@ Q_EXTERN std::vector<char> bspEntData;
Q_EXTERN std::vector<bspLeaf_t> bspLeafs; // MAX_MAP_LEAFS Q_EXTERN std::vector<bspLeaf_t> bspLeafs; // MAX_MAP_LEAFS
Q_EXTERN int numBSPPlanes Q_ASSIGN( 0 ); Q_EXTERN std::vector<bspPlane_t> bspPlanes;
Q_EXTERN int allocatedBSPPlanes Q_ASSIGN( 0 );
Q_EXTERN bspPlane_t *bspPlanes;
Q_EXTERN int numBSPNodes Q_ASSIGN( 0 ); Q_EXTERN int numBSPNodes Q_ASSIGN( 0 );
Q_EXTERN int allocatedBSPNodes Q_ASSIGN( 0 ); Q_EXTERN int allocatedBSPNodes Q_ASSIGN( 0 );

View File

@ -100,16 +100,15 @@ int EmitShader( const char *shader, const int *contentFlags, const int *surfaceF
*/ */
void EmitPlanes( void ){ void EmitPlanes( void ){
bspPlanes.reserve( mapplanes.size() );
/* walk plane list */ /* 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.push_back( plane.plane );
bspPlanes[ numBSPPlanes ] = mapplanes[i].plane;
numBSPPlanes++;
} }
/* emit some statistics */ /* emit some statistics */
Sys_FPrintf( SYS_VRB, "%9d BSP planes\n", numBSPPlanes ); Sys_FPrintf( SYS_VRB, "%9zu BSP planes\n", bspPlanes.size() );
} }