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
//////////////////////////////////////////////////////////////////////
DBrush::DBrush( int ID ){
m_nBrushID = ID;
DBrush::DBrush(){
bBoundsBuilt = false;
QER_entity = NULL;
QER_brush = NULL;

View File

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

View File

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

View File

@ -24,6 +24,7 @@
#pragma once
#include <list>
#include <vector>
#include "str.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 );
void SaveToFile( FILE* pFile );
void SetClassname( const char* classname );
int GetIDMax();
void BuildInRadiant( bool allowDestruction );
void ResetChecks( std::list<Str>* exclusionList );
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 );
DBrush* FindBrushByPointer( scene::Node& brush );
// ---------------------------------------------
@ -84,8 +83,7 @@ public:
// brush operations
void ClearBrushes(); // clears brush list and frees memory for brushes
DBrush* GetBrushForID( int ID );
DBrush* NewBrush( int ID = -1 );
DBrush* NewBrush();
// ---------------------------------------------
// patch operations
@ -96,9 +94,9 @@ public:
// vars
std::list<DEPair*> epairList;
std::list<DBrush*> brushList;
std::vector<DBrush*> brushList;
// new patches, wahey!!!
std::list<DPatch*> patchList;
std::vector<DPatch*> patchList;
Str m_Classname;
// ---------------------------------------------

View File

@ -44,7 +44,6 @@
bool bFacesAll[6] = {true, true, true, true, true, true};
DShape::DShape(){
m_nNextBrush = 0;
}
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++ )
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* pB;
if ( ent == NULL ) {
pB = m_Container.GetWorldSpawn()->NewBrush( m_nNextBrush++ );
pB = m_Container.GetWorldSpawn()->NewBrush();
}
else{
pB = ent->NewBrush( m_nNextBrush++ );
pB = ent->NewBrush();
}
//----- Build Outer Bounds ---------

View File

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