std::vector<bspNode_t> bspNodes

This commit is contained in:
Garux 2021-09-24 16:06:34 +03:00
parent bccd3bafd7
commit b1f32e6faa
8 changed files with 37 additions and 48 deletions

View File

@ -187,7 +187,7 @@ void SwapBSPFile( void ){
SwapBlock( bspPlanes ); SwapBlock( bspPlanes );
/* nodes */ /* nodes */
SwapBlock( (int*) bspNodes, numBSPNodes * sizeof( bspNodes[ 0 ] ) ); SwapBlock( bspNodes );
/* leafs */ /* leafs */
SwapBlock( bspLeafs ); SwapBlock( bspLeafs );
@ -478,8 +478,8 @@ void PrintBSPFileSizes( void ){
entities.size(), bspEntData.size() ); entities.size(), bspEntData.size() );
Sys_Printf( "\n" ); Sys_Printf( "\n" );
Sys_Printf( "%9d nodes %9d\n", Sys_Printf( "%9zu nodes %9zu\n",
numBSPNodes, (int) ( numBSPNodes * sizeof( bspNode_t ) ) ); bspNodes.size(), bspNodes.size() * sizeof( bspNodes[0] ) );
Sys_Printf( "%9zu leafs %9zu\n", Sys_Printf( "%9zu leafs %9zu\n",
bspLeafs.size(), bspLeafs.size() * sizeof( bspLeafs[0] ) ); bspLeafs.size(), bspLeafs.size() * sizeof( bspLeafs[0] ) );
Sys_Printf( "%9d leafsurfaces %9d\n", Sys_Printf( "%9d leafsurfaces %9d\n",

View File

@ -441,7 +441,7 @@ void LoadIBSPFile( const char *filename ){
CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs ); CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs );
numBSPNodes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_NODES, (void **) &bspNodes, sizeof( bspNode_t ), &allocatedBSPNodes ); CopyLump( (bspHeader_t*) header, LUMP_NODES, bspNodes );
numBSPLeafSurfaces = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFSURFACES, (void **) &bspLeafSurfaces, sizeof( bspLeafSurfaces[ 0 ] ), &allocatedBSPLeafSurfaces ); numBSPLeafSurfaces = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFSURFACES, (void **) &bspLeafSurfaces, sizeof( bspLeafSurfaces[ 0 ] ), &allocatedBSPLeafSurfaces );
@ -554,7 +554,7 @@ void WriteIBSPFile( const char *filename ){
AddLump( file, header->lumps[LUMP_SHADERS], bspShaders ); AddLump( file, header->lumps[LUMP_SHADERS], bspShaders );
AddLump( file, header->lumps[LUMP_PLANES], bspPlanes ); 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, header->lumps[LUMP_NODES], bspNodes );
AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) );
AddBrushSidesLump( file, header ); AddBrushSidesLump( file, header );
AddLump( file, (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) ); AddLump( file, (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) );

View File

@ -232,7 +232,7 @@ void LoadRBSPFile( const char *filename ){
CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs ); CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs );
numBSPNodes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_NODES, (void **) &bspNodes, sizeof( bspNode_t ), &allocatedBSPNodes ); CopyLump( (bspHeader_t*) header, LUMP_NODES, bspNodes );
numBSPLeafSurfaces = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFSURFACES, (void **) &bspLeafSurfaces, sizeof( bspLeafSurfaces[ 0 ] ), &allocatedBSPLeafSurfaces ); numBSPLeafSurfaces = CopyLump_Allocate( (bspHeader_t*) header, LUMP_LEAFSURFACES, (void **) &bspLeafSurfaces, sizeof( bspLeafSurfaces[ 0 ] ), &allocatedBSPLeafSurfaces );
@ -307,7 +307,7 @@ void WriteRBSPFile( const char *filename ){
AddLump( file, header->lumps[LUMP_SHADERS], bspShaders ); AddLump( file, header->lumps[LUMP_SHADERS], bspShaders );
AddLump( file, header->lumps[LUMP_PLANES], bspPlanes ); 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, header->lumps[LUMP_NODES], bspNodes );
AddLump( file, (bspHeader_t*) header, LUMP_BRUSHES, bspBrushes, numBSPBrushes * sizeof( bspBrush_t ) ); 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_BRUSHSIDES, bspBrushSides, numBSPBrushSides * sizeof( bspBrushSides[ 0 ] ) );
AddLump( file, (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) ); AddLump( file, (bspHeader_t*) header, LUMP_LEAFSURFACES, bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) );

View File

@ -485,10 +485,10 @@ int ScaleBSPMain( Args& args ){
} }
/* scale nodes */ /* scale nodes */
for ( i = 0; i < numBSPNodes; i++ ) for ( bspNode_t& node : bspNodes )
{ {
bspNodes[ i ].minmax.mins *= scale; node.minmax.mins *= scale;
bspNodes[ i ].minmax.maxs *= scale; node.minmax.maxs *= scale;
} }
/* scale leafs */ /* scale leafs */
@ -654,10 +654,10 @@ int ShiftBSPMain( Args& args ){
} }
/* shift nodes */ /* shift nodes */
for ( i = 0; i < numBSPNodes; i++ ) for ( bspNode_t& node : bspNodes )
{ {
bspNodes[ i ].minmax.mins += shift; node.minmax.mins += shift;
bspNodes[ i ].minmax.maxs += shift; node.minmax.maxs += shift;
} }
/* shift leafs */ /* shift leafs */

View File

@ -205,7 +205,7 @@ static void write_json( const char *directory ){
} }
{ {
doc.RemoveAllMembers(); doc.RemoveAllMembers();
for_indexed( auto&& node : Span( bspNodes, numBSPNodes ) ){ for_indexed( const auto& node : bspNodes ){
rapidjson::Value value( rapidjson::kObjectType ); rapidjson::Value value( rapidjson::kObjectType );
value.AddMember( "planeNum", node.planeNum, all ); value.AddMember( "planeNum", node.planeNum, all );
value.AddMember( "children", value_for_array( node.children, all ), all ); value.AddMember( "children", value_for_array( node.children, all ), all );
@ -423,17 +423,14 @@ static void read_json( const char *directory ){
} }
{ {
const auto doc = load_json( StringOutputStream( 256 )( directory, "nodes.json" ) ); const auto doc = load_json( StringOutputStream( 256 )( directory, "nodes.json" ) );
static std::vector<bspNode_t> items;
for( auto&& obj : doc.GetObj() ){ for( auto&& obj : doc.GetObj() ){
auto&& item = items.emplace_back(); auto&& item = bspNodes.emplace_back();
item.planeNum = obj.value["planeNum"].GetInt(); item.planeNum = obj.value["planeNum"].GetInt();
item.children[0] = obj.value["children"].operator[]( 0 ).GetInt(); item.children[0] = obj.value["children"].operator[]( 0 ).GetInt();
item.children[1] = obj.value["children"].operator[]( 1 ).GetInt(); item.children[1] = obj.value["children"].operator[]( 1 ).GetInt();
value_to( obj.value["minmax"].GetObj().operator[]("mins"), item.minmax.mins ); value_to( obj.value["minmax"].GetObj().operator[]("mins"), item.minmax.mins );
value_to( obj.value["minmax"].GetObj().operator[]("maxs"), item.minmax.maxs ); value_to( obj.value["minmax"].GetObj().operator[]("maxs"), item.minmax.maxs );
} }
bspNodes = items.data();
numBSPNodes = items.size();
} }
{ {
const auto doc = load_json( StringOutputStream( 256 )( directory, "LeafSurfaces.json" ) ); const auto doc = load_json( StringOutputStream( 256 )( directory, "LeafSurfaces.json" ) );

View File

@ -3320,7 +3320,6 @@ bool ChopBounds( MinMax& minmax, const Vector3& origin, const Vector3& normal ){
#define LIGHT_NUDGE 2.0f #define LIGHT_NUDGE 2.0f
void SetupEnvelopes( bool forGrid, bool fastFlag ){ void SetupEnvelopes( bool forGrid, bool fastFlag ){
int i, x, y, z, x1, y1, z1;
float radius, intensity; float radius, intensity;
@ -3361,18 +3360,18 @@ void SetupEnvelopes( bool forGrid, bool fastFlag ){
/* invalid cluster? */ /* invalid cluster? */
if ( light->cluster < 0 ) { if ( light->cluster < 0 ) {
/* nudge the sample point around a bit */ /* nudge the sample point around a bit */
for ( x = 0; x < 4; x++ ) for ( int x = 0; x < 4; x++ )
{ {
/* two's complement 0, 1, -1, 2, -2, etc */ /* two's complement 0, 1, -1, 2, -2, etc */
x1 = ( ( x >> 1 ) ^ ( x & 1 ? -1 : 0 ) ) + ( x & 1 ); const int x1 = ( ( x >> 1 ) ^ ( x & 1 ? -1 : 0 ) ) + ( x & 1 );
for ( y = 0; y < 4; y++ ) for ( int y = 0; y < 4; y++ )
{ {
y1 = ( ( y >> 1 ) ^ ( y & 1 ? -1 : 0 ) ) + ( y & 1 ); const int y1 = ( ( y >> 1 ) ^ ( y & 1 ? -1 : 0 ) ) + ( y & 1 );
for ( z = 0; z < 4; z++ ) for ( int z = 0; z < 4; z++ )
{ {
z1 = ( ( z >> 1 ) ^ ( z & 1 ? -1 : 0 ) ) + ( z & 1 ); const int z1 = ( ( z >> 1 ) ^ ( z & 1 ? -1 : 0 ) ) + ( z & 1 );
/* nudge origin */ /* nudge origin */
const Vector3 origin = light->origin + Vector3( x1, y1, z1 ) * LIGHT_NUDGE; const Vector3 origin = light->origin + Vector3( x1, y1, z1 ) * LIGHT_NUDGE;

View File

@ -2344,9 +2344,7 @@ Q_EXTERN std::vector<bspLeaf_t> bspLeafs; // MAX_MAP_LEAFS
Q_EXTERN std::vector<bspPlane_t> bspPlanes; Q_EXTERN std::vector<bspPlane_t> bspPlanes;
Q_EXTERN int numBSPNodes Q_ASSIGN( 0 ); Q_EXTERN std::vector<bspNode_t> bspNodes;
Q_EXTERN int allocatedBSPNodes Q_ASSIGN( 0 );
Q_EXTERN bspNode_t* bspNodes Q_ASSIGN( NULL );
Q_EXTERN int numBSPLeafSurfaces Q_ASSIGN( 0 ); Q_EXTERN int numBSPLeafSurfaces Q_ASSIGN( 0 );
Q_EXTERN int allocatedBSPLeafSurfaces Q_ASSIGN( 0 ); Q_EXTERN int allocatedBSPLeafSurfaces Q_ASSIGN( 0 );

View File

@ -171,10 +171,6 @@ void EmitLeaf( node_t *node ){
*/ */
int EmitDrawNode_r( node_t *node ){ int EmitDrawNode_r( node_t *node ){
bspNode_t *n;
int i, n0;
/* check for leafnode */ /* check for leafnode */
if ( node->planenum == PLANENUM_LEAF ) { if ( node->planenum == PLANENUM_LEAF ) {
EmitLeaf( node ); EmitLeaf( node );
@ -182,38 +178,37 @@ int EmitDrawNode_r( node_t *node ){
} }
/* emit a node */ /* emit a node */
AUTOEXPAND_BY_REALLOC_BSP( Nodes, 1024 ); const int id = bspNodes.size();
n0 = numBSPNodes; {
n = &bspNodes[ n0 ]; bspNode_t& bnode = bspNodes.emplace_back();
numBSPNodes++;
n->minmax.mins = node->minmax.mins; bnode.minmax.mins = node->minmax.mins;
n->minmax.maxs = node->minmax.maxs; bnode.minmax.maxs = node->minmax.maxs;
if ( node->planenum & 1 ) { if ( node->planenum & 1 ) {
Error( "WriteDrawNodes_r: odd planenum" ); Error( "WriteDrawNodes_r: odd planenum" );
}
bnode.planeNum = node->planenum;
} }
n->planeNum = node->planenum;
// //
// recursively output the other nodes // recursively output the other nodes
// //
for ( i = 0; i < 2; i++ ) for ( int i = 0; i < 2; i++ )
{ {
// reference node by id, as it may be reallocated
if ( node->children[i]->planenum == PLANENUM_LEAF ) { if ( node->children[i]->planenum == PLANENUM_LEAF ) {
n->children[i] = -int( bspLeafs.size() + 1 ); bspNodes[id].children[i] = -int( bspLeafs.size() + 1 );
EmitLeaf( node->children[i] ); EmitLeaf( node->children[i] );
} }
else else
{ {
n->children[i] = numBSPNodes; bspNodes[id].children[i] = bspNodes.size();
EmitDrawNode_r( node->children[i] ); EmitDrawNode_r( node->children[i] );
// n may have become invalid here, so...
n = &bspNodes[ n0 ];
} }
} }
return n - bspNodes; return id;
} }
@ -326,7 +321,7 @@ void SetLightStyles( void ){
void BeginBSPFile( void ){ void BeginBSPFile( void ){
/* these values may actually be initialized if the file existed when loaded, so clear them explicitly */ /* these values may actually be initialized if the file existed when loaded, so clear them explicitly */
bspModels.clear(); bspModels.clear();
numBSPNodes = 0; bspNodes.clear();
numBSPBrushSides = 0; numBSPBrushSides = 0;
numBSPLeafSurfaces = 0; numBSPLeafSurfaces = 0;
numBSPLeafBrushes = 0; numBSPLeafBrushes = 0;