std::vector<bspLeaf_t> bspLeafs
This commit is contained in:
parent
6267f1d0af
commit
76d2b565b3
|
|
@ -190,7 +190,7 @@ void SwapBSPFile( void ){
|
|||
SwapBlock( (int*) bspNodes, numBSPNodes * sizeof( bspNodes[ 0 ] ) );
|
||||
|
||||
/* leafs */
|
||||
SwapBlock( (int*) bspLeafs, numBSPLeafs * sizeof( bspLeafs[ 0 ] ) );
|
||||
SwapBlock( bspLeafs );
|
||||
|
||||
/* leaffaces */
|
||||
SwapBlock( (int*) bspLeafSurfaces, numBSPLeafSurfaces * sizeof( bspLeafSurfaces[ 0 ] ) );
|
||||
|
|
@ -480,8 +480,8 @@ void PrintBSPFileSizes( void ){
|
|||
|
||||
Sys_Printf( "%9d nodes %9d\n",
|
||||
numBSPNodes, (int) ( numBSPNodes * sizeof( bspNode_t ) ) );
|
||||
Sys_Printf( "%9d leafs %9d\n",
|
||||
numBSPLeafs, (int) ( numBSPLeafs * sizeof( bspLeaf_t ) ) );
|
||||
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( "%9d leafbrushes %9d\n",
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ void LoadIBSPFile( const char *filename ){
|
|||
|
||||
numBSPPlanes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_PLANES, (void **) &bspPlanes, sizeof( bspPlane_t ), &allocatedBSPPlanes );
|
||||
|
||||
numBSPLeafs = CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs, sizeof( bspLeaf_t ) ); // TODO fix overflow
|
||||
CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs );
|
||||
|
||||
numBSPNodes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_NODES, (void **) &bspNodes, sizeof( bspNode_t ), &allocatedBSPNodes );
|
||||
|
||||
|
|
@ -553,7 +553,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, (bspHeader_t*) header, LUMP_LEAFS, bspLeafs, numBSPLeafs * sizeof( bspLeaf_t ) );
|
||||
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 ) );
|
||||
AddBrushSidesLump( file, header );
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ void LoadRBSPFile( const char *filename ){
|
|||
|
||||
numBSPPlanes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_PLANES, (void **) &bspPlanes, sizeof( bspPlane_t ), &allocatedBSPPlanes );
|
||||
|
||||
numBSPLeafs = CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs, sizeof( bspLeaf_t ) );
|
||||
CopyLump( (bspHeader_t*) header, LUMP_LEAFS, bspLeafs );
|
||||
|
||||
numBSPNodes = CopyLump_Allocate( (bspHeader_t*) header, LUMP_NODES, (void **) &bspNodes, sizeof( bspNode_t ), &allocatedBSPNodes );
|
||||
|
||||
|
|
@ -306,7 +306,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, (bspHeader_t*) header, LUMP_LEAFS, bspLeafs, numBSPLeafs * sizeof( bspLeaf_t ) );
|
||||
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 ) );
|
||||
AddLump( file, (bspHeader_t*) header, LUMP_BRUSHSIDES, bspBrushSides, numBSPBrushSides * sizeof( bspBrushSides[ 0 ] ) );
|
||||
|
|
|
|||
|
|
@ -492,10 +492,10 @@ int ScaleBSPMain( Args& args ){
|
|||
}
|
||||
|
||||
/* scale leafs */
|
||||
for ( i = 0; i < numBSPLeafs; i++ )
|
||||
for ( bspLeaf_t& leaf : bspLeafs )
|
||||
{
|
||||
bspLeafs[ i ].minmax.mins *= scale;
|
||||
bspLeafs[ i ].minmax.maxs *= scale;
|
||||
leaf.minmax.mins *= scale;
|
||||
leaf.minmax.maxs *= scale;
|
||||
}
|
||||
|
||||
if ( texscale ) {
|
||||
|
|
@ -661,10 +661,10 @@ int ShiftBSPMain( Args& args ){
|
|||
}
|
||||
|
||||
/* shift leafs */
|
||||
for ( i = 0; i < numBSPLeafs; i++ )
|
||||
for ( bspLeaf_t& leaf : bspLeafs )
|
||||
{
|
||||
bspLeafs[ i ].minmax.mins += shift;
|
||||
bspLeafs[ i ].minmax.maxs += shift;
|
||||
leaf.minmax.mins += shift;
|
||||
leaf.minmax.maxs += shift;
|
||||
}
|
||||
|
||||
/* shift drawverts */
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ static void write_json( const char *directory ){
|
|||
}
|
||||
{
|
||||
doc.RemoveAllMembers();
|
||||
for_indexed( auto&& leaf : Span( bspLeafs, numBSPLeafs ) ){
|
||||
for_indexed( const auto& leaf : bspLeafs ){
|
||||
rapidjson::Value value( rapidjson::kObjectType );
|
||||
value.AddMember( "cluster", leaf.cluster, all );
|
||||
value.AddMember( "area", leaf.area, all );
|
||||
|
|
@ -412,9 +412,8 @@ static void read_json( const char *directory ){
|
|||
}
|
||||
{
|
||||
const auto doc = load_json( StringOutputStream( 256 )( directory, "leafs.json" ) );
|
||||
static std::vector<bspLeaf_t> items;
|
||||
for( auto&& obj : doc.GetObj() ){
|
||||
auto&& item = items.emplace_back();
|
||||
auto&& item = bspLeafs.emplace_back();
|
||||
item.cluster = obj.value["cluster"].GetInt();
|
||||
item.area = obj.value["area"].GetInt();
|
||||
value_to( obj.value["minmax"].GetObj().operator[]("mins"), item.minmax.mins );
|
||||
|
|
@ -424,8 +423,6 @@ static void read_json( const char *directory ){
|
|||
item.firstBSPLeafBrush = obj.value["firstBSPLeafBrush"].GetInt();
|
||||
item.numBSPLeafBrushes = obj.value["numBSPLeafBrushes"].GetInt();
|
||||
}
|
||||
std::copy( items.begin(), items.end(), bspLeafs );
|
||||
numBSPLeafs = items.size();
|
||||
}
|
||||
{
|
||||
const auto doc = load_json( StringOutputStream( 256 )( directory, "nodes.json" ) );
|
||||
|
|
|
|||
|
|
@ -3136,7 +3136,6 @@ int ClusterForPointExt( const Vector3& point, float epsilon ){
|
|||
int i, j, b, leafNum, cluster;
|
||||
bool inside;
|
||||
int *brushes, numBSPBrushes;
|
||||
bspLeaf_t *leaf;
|
||||
bspBrush_t *brush;
|
||||
|
||||
|
||||
|
|
@ -3145,17 +3144,17 @@ int ClusterForPointExt( const Vector3& point, float epsilon ){
|
|||
if ( leafNum < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
leaf = &bspLeafs[ leafNum ];
|
||||
const bspLeaf_t& leaf = bspLeafs[ leafNum ];
|
||||
|
||||
/* get the cluster */
|
||||
cluster = leaf->cluster;
|
||||
cluster = leaf.cluster;
|
||||
if ( cluster < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* transparent leaf, so check point against all brushes in the leaf */
|
||||
brushes = &bspLeafBrushes[ leaf->firstBSPLeafBrush ];
|
||||
numBSPBrushes = leaf->numBSPLeafBrushes;
|
||||
brushes = &bspLeafBrushes[ leaf.firstBSPLeafBrush ];
|
||||
numBSPBrushes = leaf.numBSPLeafBrushes;
|
||||
for ( i = 0; i < numBSPBrushes; i++ )
|
||||
{
|
||||
/* get parts */
|
||||
|
|
@ -3231,7 +3230,6 @@ int ShaderForPointInLeaf( const Vector3& point, int leafNum, float epsilon, int
|
|||
int i, j;
|
||||
bool inside;
|
||||
int *brushes, numBSPBrushes;
|
||||
bspLeaf_t *leaf;
|
||||
bspBrush_t *brush;
|
||||
bspBrushSide_t *side;
|
||||
int allSurfaceFlags, allContentFlags;
|
||||
|
|
@ -3245,11 +3243,11 @@ int ShaderForPointInLeaf( const Vector3& point, int leafNum, float epsilon, int
|
|||
if ( leafNum < 0 ) {
|
||||
return -1;
|
||||
}
|
||||
leaf = &bspLeafs[ leafNum ];
|
||||
const bspLeaf_t& leaf = bspLeafs[ leafNum ];
|
||||
|
||||
/* transparent leaf, so check point against all brushes in the leaf */
|
||||
brushes = &bspLeafBrushes[ leaf->firstBSPLeafBrush ];
|
||||
numBSPBrushes = leaf->numBSPLeafBrushes;
|
||||
brushes = &bspLeafBrushes[ leaf.firstBSPLeafBrush ];
|
||||
numBSPBrushes = leaf.numBSPLeafBrushes;
|
||||
for ( i = 0; i < numBSPBrushes; i++ )
|
||||
{
|
||||
/* get parts */
|
||||
|
|
@ -3323,7 +3321,6 @@ bool ChopBounds( MinMax& minmax, const Vector3& origin, const Vector3& normal ){
|
|||
|
||||
void SetupEnvelopes( bool forGrid, bool fastFlag ){
|
||||
int i, x, y, z, x1, y1, z1;
|
||||
bspLeaf_t *leaf;
|
||||
float radius, intensity;
|
||||
|
||||
|
||||
|
|
@ -3492,21 +3489,18 @@ void SetupEnvelopes( bool forGrid, bool fastFlag ){
|
|||
MinMax minmax;
|
||||
|
||||
/* check all leaves */
|
||||
for ( i = 0; i < numBSPLeafs; i++ )
|
||||
for ( const bspLeaf_t& leaf : bspLeafs )
|
||||
{
|
||||
/* get test leaf */
|
||||
leaf = &bspLeafs[ i ];
|
||||
|
||||
/* in pvs? */
|
||||
if ( leaf->cluster < 0 ) {
|
||||
if ( leaf.cluster < 0 ) {
|
||||
continue;
|
||||
}
|
||||
if ( !ClusterVisible( light->cluster, leaf->cluster ) ) { /* ydnar: thanks Arnout for exposing my stupid error (this never failed before) */
|
||||
if ( !ClusterVisible( light->cluster, leaf.cluster ) ) { /* ydnar: thanks Arnout for exposing my stupid error (this never failed before) */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* add this leafs bbox to the bounds */
|
||||
minmax.extend( leaf->minmax );
|
||||
minmax.extend( leaf.minmax );
|
||||
}
|
||||
|
||||
/* test to see if bounds encompass light */
|
||||
|
|
|
|||
|
|
@ -926,7 +926,6 @@ struct CompareSurfaceInfo
|
|||
|
||||
void SetupSurfaceLightmaps( void ){
|
||||
int i, j, k, s,num, num2;
|
||||
bspLeaf_t *leaf;
|
||||
bspDrawSurface_t *ds;
|
||||
surfaceInfo_t *info, *info2;
|
||||
rawLightmap_t *lm;
|
||||
|
|
@ -1009,24 +1008,21 @@ void SetupSurfaceLightmaps( void ){
|
|||
}
|
||||
|
||||
/* find all the bsp clusters the surface falls into */
|
||||
for ( k = 0; k < numBSPLeafs; k++ )
|
||||
for ( const bspLeaf_t& leaf : bspLeafs )
|
||||
{
|
||||
/* get leaf */
|
||||
leaf = &bspLeafs[ k ];
|
||||
|
||||
/* test bbox */
|
||||
if( !leaf->minmax.test( info->minmax ) ) {
|
||||
if( !leaf.minmax.test( info->minmax ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* test leaf surfaces */
|
||||
for ( s = 0; s < leaf->numBSPLeafSurfaces; s++ )
|
||||
for ( s = 0; s < leaf.numBSPLeafSurfaces; s++ )
|
||||
{
|
||||
if ( bspLeafSurfaces[ leaf->firstBSPLeafSurface + s ] == num ) {
|
||||
if ( bspLeafSurfaces[ leaf.firstBSPLeafSurface + s ] == num ) {
|
||||
if ( numSurfaceClusters >= maxSurfaceClusters ) {
|
||||
Error( "maxSurfaceClusters exceeded" );
|
||||
}
|
||||
surfaceClusters[ numSurfaceClusters ] = leaf->cluster;
|
||||
surfaceClusters[ numSurfaceClusters ] = leaf.cluster;
|
||||
numSurfaceClusters++;
|
||||
info->numSurfaceClusters++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2340,8 +2340,7 @@ Q_EXTERN std::vector<bspShader_t> bspShaders;
|
|||
|
||||
Q_EXTERN std::vector<char> bspEntData;
|
||||
|
||||
Q_EXTERN int numBSPLeafs Q_ASSIGN( 0 );
|
||||
Q_EXTERN 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 int allocatedBSPPlanes Q_ASSIGN( 0 );
|
||||
|
|
|
|||
|
|
@ -120,27 +120,17 @@ void EmitPlanes( void ){
|
|||
*/
|
||||
|
||||
void EmitLeaf( node_t *node ){
|
||||
bspLeaf_t *leaf_p;
|
||||
drawSurfRef_t *dsr;
|
||||
bspLeaf_t& leaf = bspLeafs.emplace_back();
|
||||
|
||||
|
||||
/* check limits */
|
||||
if ( numBSPLeafs >= MAX_MAP_LEAFS ) {
|
||||
Error( "MAX_MAP_LEAFS" );
|
||||
}
|
||||
|
||||
leaf_p = &bspLeafs[numBSPLeafs];
|
||||
numBSPLeafs++;
|
||||
|
||||
leaf_p->cluster = node->cluster;
|
||||
leaf_p->area = node->area;
|
||||
leaf.cluster = node->cluster;
|
||||
leaf.area = node->area;
|
||||
|
||||
/* emit bounding box */
|
||||
leaf_p->minmax.maxs = node->minmax.maxs;
|
||||
leaf_p->minmax.mins = node->minmax.mins;
|
||||
leaf.minmax.maxs = node->minmax.maxs;
|
||||
leaf.minmax.mins = node->minmax.mins;
|
||||
|
||||
/* emit leaf brushes */
|
||||
leaf_p->firstBSPLeafBrush = numBSPLeafBrushes;
|
||||
leaf.firstBSPLeafBrush = numBSPLeafBrushes;
|
||||
for ( const brush_t& b : node->brushlist )
|
||||
{
|
||||
/* something is corrupting brushes */
|
||||
|
|
@ -156,7 +146,7 @@ void EmitLeaf( node_t *node ){
|
|||
numBSPLeafBrushes++;
|
||||
}
|
||||
|
||||
leaf_p->numBSPLeafBrushes = numBSPLeafBrushes - leaf_p->firstBSPLeafBrush;
|
||||
leaf.numBSPLeafBrushes = numBSPLeafBrushes - leaf.firstBSPLeafBrush;
|
||||
|
||||
/* emit leaf surfaces */
|
||||
if ( node->opaque ) {
|
||||
|
|
@ -164,15 +154,15 @@ void EmitLeaf( node_t *node ){
|
|||
}
|
||||
|
||||
/* add the drawSurfRef_t drawsurfs */
|
||||
leaf_p->firstBSPLeafSurface = numBSPLeafSurfaces;
|
||||
for ( dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
|
||||
leaf.firstBSPLeafSurface = numBSPLeafSurfaces;
|
||||
for ( const drawSurfRef_t *dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
|
||||
{
|
||||
AUTOEXPAND_BY_REALLOC_BSP( LeafSurfaces, 1024 );
|
||||
bspLeafSurfaces[ numBSPLeafSurfaces ] = dsr->outputNum;
|
||||
numBSPLeafSurfaces++;
|
||||
}
|
||||
|
||||
leaf_p->numBSPLeafSurfaces = numBSPLeafSurfaces - leaf_p->firstBSPLeafSurface;
|
||||
leaf.numBSPLeafSurfaces = numBSPLeafSurfaces - leaf.firstBSPLeafSurface;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -189,7 +179,7 @@ int EmitDrawNode_r( node_t *node ){
|
|||
/* check for leafnode */
|
||||
if ( node->planenum == PLANENUM_LEAF ) {
|
||||
EmitLeaf( node );
|
||||
return -numBSPLeafs;
|
||||
return -int( bspLeafs.size() );
|
||||
}
|
||||
|
||||
/* emit a node */
|
||||
|
|
@ -212,7 +202,7 @@ int EmitDrawNode_r( node_t *node ){
|
|||
for ( i = 0; i < 2; i++ )
|
||||
{
|
||||
if ( node->children[i]->planenum == PLANENUM_LEAF ) {
|
||||
n->children[i] = -( numBSPLeafs + 1 );
|
||||
n->children[i] = -int( bspLeafs.size() + 1 );
|
||||
EmitLeaf( node->children[i] );
|
||||
}
|
||||
else
|
||||
|
|
@ -343,7 +333,7 @@ void BeginBSPFile( void ){
|
|||
numBSPLeafBrushes = 0;
|
||||
|
||||
/* leave leaf 0 as an error, because leafs are referenced as negative number nodes */
|
||||
numBSPLeafs = 1;
|
||||
bspLeafs.resize( 1 );
|
||||
|
||||
|
||||
/* ydnar: gs mods: set the first 6 drawindexes to 0 1 2 2 1 3 for triangles and quads */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user