bobToolz: remove brush ID, store brushes & patches in vector

This commit is contained in:
Garux 2023-09-01 07:19:28 +06:00
parent 7bd11485d0
commit bf4db60613
6 changed files with 45 additions and 123 deletions

View File

@ -47,8 +47,7 @@
// Construction/Destruction // Construction/Destruction
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
DBrush::DBrush( int ID ){ DBrush::DBrush(){
m_nBrushID = ID;
bBoundsBuilt = false; bBoundsBuilt = false;
QER_entity = NULL; QER_entity = NULL;
QER_brush = NULL; QER_brush = NULL;

View File

@ -91,7 +91,7 @@ public:
DPlane* FindPlaneWithClosestNormal( vec_t* normal ); DPlane* FindPlaneWithClosestNormal( vec_t* normal );
int FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts ); int FindPointsForPlane( DPlane* plane, DPoint** pnts, int maxpnts );
DBrush( int ID = -1 ); DBrush();
virtual ~DBrush(); virtual ~DBrush();
bool operator==( const DBrush* other ) const; bool operator==( const DBrush* other ) const;
@ -101,7 +101,6 @@ public:
scene::Node* QER_brush; scene::Node* QER_brush;
std::list<DPlane*> faceList; std::list<DPlane*> faceList;
std::list<DPoint*> pointList; std::list<DPoint*> pointList;
int m_nBrushID;
vec3_t bbox_min, bbox_max; vec3_t bbox_min, bbox_max;
bool bBoundsBuilt; bool bBoundsBuilt;
}; };

View File

@ -24,6 +24,7 @@
#include "DEntity.h" #include "DEntity.h"
#include <list> #include <list>
#include <utility>
#include "str.h" #include "str.h"
#include "DPoint.h" #include "DPoint.h"
@ -107,19 +108,11 @@ void DEntity::ClearPatches(){
} }
DPatch* DEntity::NewPatch(){ DPatch* DEntity::NewPatch(){
DPatch* newPatch = new DPatch; return patchList.emplace_back( new DPatch );
patchList.push_back( newPatch );
return newPatch;
} }
DBrush* DEntity::NewBrush( int ID ){ DBrush* DEntity::NewBrush(){
DBrush* newBrush = new DBrush( ID ); return brushList.emplace_back( new DBrush );
brushList.push_back( newBrush );
return newBrush;
} }
char* getNextBracket( char* s ){ char* getNextBracket( char* s ){
@ -191,30 +184,6 @@ bool DEntity::LoadFromPrt( char *filename ){
return true; return true;
} }
DPlane* DEntity::AddFaceToBrush( vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID ){
DBrush* buildBrush = GetBrushForID( ID );
return buildBrush->AddFace( va, vb, vc, faceData );
// slow, dont use much
}
DBrush* DEntity::GetBrushForID( int ID ){
DBrush* buildBrush = NULL;
for ( DBrush *brush : brushList )
{
if ( brush->m_nBrushID == ID ) {
buildBrush = brush;
break;
}
}
if ( !buildBrush ) {
buildBrush = NewBrush( ID );
}
return buildBrush;
}
template<typename Functor> template<typename Functor>
class BrushSelectedVisitor : public SelectionSystem::Visitor class BrushSelectedVisitor : public SelectionSystem::Visitor
{ {
@ -236,8 +205,7 @@ inline const Functor& Scene_forEachSelectedBrush( const Functor& functor ){
} }
void DEntity_loadBrush( DEntity& entity, scene::Instance& brush ){ void DEntity_loadBrush( DEntity& entity, scene::Instance& brush ){
DBrush* loadBrush = entity.NewBrush( static_cast<int>( entity.brushList.size() ) ); entity.NewBrush()->LoadFromBrush( brush, true );
loadBrush->LoadFromBrush( brush, true );
} }
typedef ReferenceCaller1<DEntity, scene::Instance&, DEntity_loadBrush> DEntityLoadBrushCaller; typedef ReferenceCaller1<DEntity, scene::Instance&, DEntity_loadBrush> DEntityLoadBrushCaller;
@ -282,22 +250,19 @@ void DEntity::LoadSelectedPatches(){
} }
bool* DEntity::BuildIntersectList(){ bool* DEntity::BuildIntersectList(){
int max = GetIDMax(); if ( brushList.empty() ) {
if ( max == 0 ) { return nullptr;
return NULL;
} }
bool* pbIntList = new bool[max]; bool* pbIntList = new bool[brushList.size()] (); // () zero initialize
memset( pbIntList, 0, sizeof( bool ) * ( max ) );
for ( std::list<DBrush *>::const_iterator pB1 = brushList.begin(); pB1 != brushList.end(); pB1++ ) for ( size_t i = 0; i < brushList.size(); ++i )
{ {
std::list<DBrush *>::const_iterator pB2 = pB1; for ( size_t j = i + 1; j < brushList.size(); ++j )
for ( pB2++; pB2 != brushList.end(); pB2++ )
{ {
if ( ( *pB1 )->IntersectsWith( ( *pB2 ) ) ) { if ( brushList[i]->IntersectsWith( brushList[j] ) ) {
pbIntList[( *pB1 )->m_nBrushID] = true; pbIntList[i] = true;
pbIntList[( *pB2 )->m_nBrushID] = true; pbIntList[j] = true;
} }
} }
} }
@ -306,22 +271,19 @@ bool* DEntity::BuildIntersectList(){
} }
bool* DEntity::BuildDuplicateList(){ bool* DEntity::BuildDuplicateList(){
int max = GetIDMax(); if ( brushList.empty() ) {
if ( max == 0 ) { return nullptr;
return NULL;
} }
bool* pbDupList = new bool[max]; bool* pbDupList = new bool[brushList.size()] (); // () zero initialize
memset( pbDupList, 0, sizeof( bool ) * ( max ) );
for ( std::list<DBrush *>::const_iterator pB1 = brushList.begin(); pB1 != brushList.end(); pB1++ ) for ( size_t i = 0; i < brushList.size(); ++i )
{ {
std::list<DBrush *>::const_iterator pB2 = pB1; for ( size_t j = i + 1; j < brushList.size(); ++j )
for ( pB2++; pB2 != brushList.end(); pB2++ )
{ {
if ( **pB1 == *pB2 ) { if ( brushList[i]->operator==( brushList[j] ) ) {
pbDupList[( *pB1 )->m_nBrushID] = true; pbDupList[i] = true;
pbDupList[( *pB2 )->m_nBrushID] = true; pbDupList[j] = true;
} }
} }
} }
@ -339,10 +301,10 @@ void DEntity::SelectBrushes( bool *selectList ){
scene::Path path( NodeReference( GlobalSceneGraph().root() ) ); scene::Path path( NodeReference( GlobalSceneGraph().root() ) );
path.push( NodeReference( *QER_Entity ) ); path.push( NodeReference( *QER_Entity ) );
for ( DBrush *brush : brushList ) for ( size_t i = 0; i < brushList.size(); ++i )
{ {
if ( selectList[brush->m_nBrushID] ) { if ( selectList[i] ) {
path.push( NodeReference( *brush->QER_brush ) ); path.push( NodeReference( *brushList[i]->QER_brush ) );
Instance_getSelectable( *GlobalSceneGraph().find( path ) )->setSelected( true ); Instance_getSelectable( *GlobalSceneGraph().find( path ) )->setSelected( true );
path.pop(); path.pop();
} }
@ -383,10 +345,9 @@ bool DEntity::LoadFromEntity( scene::Node& ent, bool bLoadPatches ) {
class load_brushes_t : public scene::Traversable::Walker class load_brushes_t : public scene::Traversable::Walker
{ {
DEntity* m_entity; DEntity* m_entity;
mutable int m_count;
public: public:
load_brushes_t( DEntity* entity ) load_brushes_t( DEntity* entity )
: m_entity( entity ), m_count( 0 ){ : m_entity( entity ){
} }
bool pre( scene::Node& node ) const { bool pre( scene::Node& node ) const {
scene::Path path( NodeReference( GlobalSceneGraph().root() ) ); scene::Path path( NodeReference( GlobalSceneGraph().root() ) );
@ -396,12 +357,10 @@ bool DEntity::LoadFromEntity( scene::Node& ent, bool bLoadPatches ) {
ASSERT_MESSAGE( instance != 0, "" ); ASSERT_MESSAGE( instance != 0, "" );
if ( Node_isPatch( node ) ) { if ( Node_isPatch( node ) ) {
DPatch* loadPatch = m_entity->NewPatch(); m_entity->NewPatch()->LoadFromPatch( *instance );
loadPatch->LoadFromPatch( *instance );
} }
else if ( Node_isBrush( node ) ) { else if ( Node_isBrush( node ) ) {
DBrush* loadBrush = m_entity->NewBrush( m_count++ ); m_entity->NewBrush()->LoadFromBrush( *instance, true );
loadBrush->LoadFromBrush( *instance, true );
} }
return false; return false;
} }
@ -414,33 +373,14 @@ bool DEntity::LoadFromEntity( scene::Node& ent, bool bLoadPatches ) {
} }
void DEntity::RemoveNonCheckBrushes( std::list<Str>* exclusionList, bool useDetail ){ void DEntity::RemoveNonCheckBrushes( std::list<Str>* exclusionList, bool useDetail ){
std::list<DBrush *>::iterator chkBrush = brushList.begin(); brushList.erase( std::remove_if( brushList.begin(), brushList.end(), [&]( DBrush *brush ){
if ( ( !useDetail && brush->IsDetail() )
while ( chkBrush != brushList.end() ) || std::any_of( exclusionList->cbegin(), exclusionList->cend(), [brush]( const Str& tex ){ return brush->HasTexture( tex.GetBuffer() ); } ) ) {
{ delete brush;
if ( !useDetail ) { return true;
if ( ( *chkBrush )->IsDetail() ) {
delete *chkBrush;
chkBrush = brushList.erase( chkBrush );
continue;
}
} }
return false;
std::list<Str>::iterator eTexture; } ), brushList.end() );
for ( eTexture = exclusionList->begin(); eTexture != exclusionList->end(); eTexture++ )
{
if ( ( *chkBrush )->HasTexture( ( *eTexture ).GetBuffer() ) ) {
delete *chkBrush;
chkBrush = brushList.erase( chkBrush );
break;
}
}
if ( eTexture == exclusionList->end() ) {
chkBrush++;
}
}
} }
void DEntity::ResetChecks( std::list<Str>* exclusionList ){ void DEntity::ResetChecks( std::list<Str>* exclusionList ){
@ -494,16 +434,6 @@ void DEntity::BuildInRadiant( bool allowDestruction ){
int DEntity::GetIDMax( void ) {
int max = -1;
for ( const DBrush *brush : brushList ) {
if ( brush->m_nBrushID > max ) {
max = brush->m_nBrushID;
}
}
return max + 1;
}
void DEntity::SetClassname( const char *classname ) { void DEntity::SetClassname( const char *classname ) {
m_Classname = classname; m_Classname = classname;
} }

View File

@ -24,6 +24,7 @@
#pragma once #pragma once
#include <list> #include <list>
#include <vector>
#include "str.h" #include "str.h"
#include "mathlib.h" #include "mathlib.h"
@ -62,13 +63,11 @@ public:
bool ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, bool bResetTextureName, bool bResetScale[2], bool bResetShift[2], bool bResetRotation, bool rebuild ); bool ResetTextures( const char* textureName, float fScale[2], float fShift[2], int rotation, const char* newTextureName, bool bResetTextureName, bool bResetScale[2], bool bResetShift[2], bool bResetRotation, bool rebuild );
void SaveToFile( FILE* pFile ); void SaveToFile( FILE* pFile );
void SetClassname( const char* classname ); void SetClassname( const char* classname );
int GetIDMax();
void BuildInRadiant( bool allowDestruction ); void BuildInRadiant( bool allowDestruction );
void ResetChecks( std::list<Str>* exclusionList ); void ResetChecks( std::list<Str>* exclusionList );
void RemoveNonCheckBrushes( std::list<Str>* exclusionList, bool useDetail ); void RemoveNonCheckBrushes( std::list<Str>* exclusionList, bool useDetail );
DPlane* AddFaceToBrush( vec3_t va, vec3_t vb, vec3_t vc, _QERFaceData* faceData, int ID ); // slow, try not to use much
int GetBrushCount( void ); int GetBrushCount( void );
DBrush* FindBrushByPointer( scene::Node& brush ); DBrush* FindBrushByPointer( scene::Node& brush );
// --------------------------------------------- // ---------------------------------------------
@ -84,8 +83,7 @@ public:
// brush operations // brush operations
void ClearBrushes(); // clears brush list and frees memory for brushes void ClearBrushes(); // clears brush list and frees memory for brushes
DBrush* GetBrushForID( int ID ); DBrush* NewBrush();
DBrush* NewBrush( int ID = -1 );
// --------------------------------------------- // ---------------------------------------------
// patch operations // patch operations
@ -96,9 +94,9 @@ public:
// vars // vars
std::list<DEPair*> epairList; std::list<DEPair*> epairList;
std::list<DBrush*> brushList; std::vector<DBrush*> brushList;
// new patches, wahey!!! // new patches, wahey!!!
std::list<DPatch*> patchList; std::vector<DPatch*> patchList;
Str m_Classname; Str m_Classname;
// --------------------------------------------- // ---------------------------------------------

View File

@ -44,7 +44,6 @@
bool bFacesAll[6] = {true, true, true, true, true, true}; bool bFacesAll[6] = {true, true, true, true, true, true};
DShape::DShape(){ DShape::DShape(){
m_nNextBrush = 0;
} }
DShape::~DShape(){ DShape::~DShape(){
@ -95,7 +94,7 @@ void DShape::BuildRegularPrism( vec3_t min, vec3_t max, int nSides, bool bAlignT
//---------------------------------- //----------------------------------
DBrush* pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ ); DBrush* pB = m_Container.GetWorldSpawn()->NewBrush();
for ( i = 1; i <= nSides; i++ ) for ( i = 1; i <= nSides; i++ )
pB->AddFace( vc[i - 1], vc[i], vd[i], GetCurrentTexture(), false ); pB->AddFace( vc[i - 1], vc[i], vd[i], GetCurrentTexture(), false );
@ -308,10 +307,10 @@ DBrush* DShape::GetBoundingCube_Ext( vec3_t min, vec3_t max, const char *texture
DBrush* DShape::GetBoundingCube( vec3_t min, vec3_t max, const char *textureName, DEntity* ent, bool* bUseFaces ){ DBrush* DShape::GetBoundingCube( vec3_t min, vec3_t max, const char *textureName, DEntity* ent, bool* bUseFaces ){
DBrush* pB; DBrush* pB;
if ( ent == NULL ) { if ( ent == NULL ) {
pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ ); pB = m_Container.GetWorldSpawn()->NewBrush();
} }
else{ else{
pB = ent->NewBrush( m_nNextBrush++ ); pB = ent->NewBrush();
} }
//----- Build Outer Bounds --------- //----- Build Outer Bounds ---------

View File

@ -148,11 +148,8 @@ bool DTreePlanter::FindDropPoint( vec3_t in, vec3_t out ) {
bool found = false; bool found = false;
vec3_t temp; vec3_t temp;
vec_t dist; vec_t dist;
int cnt = m_world.GetIDMax(); for ( auto *brush : m_world.brushList ) {
for ( int i = 0; i < cnt; i++ ) { if ( brush->IntersectsWith( &p1, &p2, temp ) ) {
DBrush* pBrush = m_world.GetBrushForID( i );
if ( pBrush->IntersectsWith( &p1, &p2, temp ) ) {
vec3_t diff; vec3_t diff;
vec_t tempdist; vec_t tempdist;
VectorSubtract( in, temp, diff ); VectorSubtract( in, temp, diff );