diff --git a/contrib/bobtoolz/DTreePlanter.cpp b/contrib/bobtoolz/DTreePlanter.cpp index ac5cf24e..ba49e70f 100644 --- a/contrib/bobtoolz/DTreePlanter.cpp +++ b/contrib/bobtoolz/DTreePlanter.cpp @@ -29,6 +29,8 @@ #include "ScriptParser.h" #include "misc.h" #include "scenelib.h" +#include "iundo.h" +#include "ientity.h" @@ -43,7 +45,9 @@ SignalHandlerResult DTreePlanter::mouseDown( const WindowVector& position, Butto pt = vector3_snapped( GlobalRadiant().XYWindow_windowToWorld( position ), GlobalRadiant().getGridSize() ); - if ( FindDropPoint( vector3_to_array( pt ), vector3_to_array( vhit ) ) ) { + if ( FindDropPoint( vector3_to_array( pt ), vector3_to_array( vhit ) ) && !string_empty( m_entType ) ) { + UndoableCommand undo( "bobToolz.treePlanter" ); + vhit[2] += m_offset; char buffer[128]; @@ -117,7 +121,7 @@ SignalHandlerResult DTreePlanter::mouseDown( const WindowVector& position, Butto return SIGNAL_STOP_EMISSION; } -bool DTreePlanter::FindDropPoint( vec3_t in, vec3_t out ) { +bool DTreePlanter::FindDropPoint( vec3_t in, vec3_t out ) const { DPlane p1; DPlane p2; @@ -170,34 +174,27 @@ class TreePlanterDropEntityIfSelected TreePlanterDropEntityIfSelected( DTreePlanter& planter ) : planter( planter ){ } void operator()( scene::Instance& instance ) const { - if ( !instance.isSelected() ) { - return; - } - ent.LoadFromEntity( instance.path().top() ); - - DEPair* pEpair = ent.FindEPairByKey( "origin" ); - if ( !pEpair ) { - return; + if ( instance.isSelected() ) { + Entity *entity = Node_getEntity( instance.path().top() ); + if( const char *origin = entity->getKeyValue( "origin" ); !string_empty( origin ) ){ + vec3_t vec, out; + sscanf( origin, "%f %f %f", &vec[0], &vec[1], &vec[2] ); + + if( planter.FindDropPoint( vec, out ) ){ + char buffer[256]; + sprintf( buffer, "%g %g %g", out[0], out[1], out[2] ); + entity->setKeyValue( "origin", buffer ); + } + } } - - vec3_t vec, out; - sscanf( pEpair->value.c_str(), "%f %f %f", &vec[0], &vec[1], &vec[2] ); - - planter.FindDropPoint( vec, out ); - - char buffer[256]; - sprintf( buffer, "%f %f %f", out[0], out[1], out[2] ); - ent.AddEPair( "origin", buffer ); - ent.RemoveFromRadiant(); - ent.BuildInRadiant( false ); } }; -void DTreePlanter::DropEntsToGround( void ) { +void DTreePlanter::DropEntsToGround() { Scene_forEachEntity( TreePlanterDropEntityIfSelected( *this ) ); } -void DTreePlanter::MakeChain( int linkNum, const char* linkName ) { +void MakeChain( int linkNum, const char* linkName ) { char buffer[256]; int i; for ( i = 0; i < linkNum; i++ ) { @@ -209,7 +206,7 @@ void DTreePlanter::MakeChain( int linkNum, const char* linkName ) { sprintf( buffer, "0 %i 0", i * 64 ); e.AddEPair( "origin", buffer ); - if ( i != m_linkNum - 1 ) { + if ( i != linkNum - 1 ) { sprintf( buffer, "%s_pt%i", linkName, i + 1 ); e.AddEPair( "target", buffer ); @@ -231,39 +228,3 @@ void DTreePlanter::MakeChain( int linkNum, const char* linkName ) { e.BuildInRadiant( false ); } } - -void DTreePlanter::SelectChain( void ) { -/* char buffer[256]; - - for(int i = 0; i < m_linkNum; i++) { - DEntity e("info_train_spline_main"); - - sprintf( buffer, "%s_pt%i", m_linkName, i ); - e.AddEPair( "targetname", buffer ); - - sprintf( buffer, "0 %i 0", i * 64 ); - e.AddEPair( "origin", buffer ); - - if(i != m_linkNum-1) { - sprintf( buffer, "%s_pt%i", m_linkName, i+1 ); - e.AddEPair( "target", buffer ); - - sprintf( buffer, "%s_ctl%i", m_linkName, i ); - e.AddEPair( "control", buffer ); - } - - e.BuildInRadiant( false ); - } - - for(int i = 0; i < m_linkNum-1; i++) { - DEntity e("info_train_spline_control"); - - sprintf( buffer, "%s_ctl%i", m_linkName, i ); - e.AddEPair( "targetname", buffer ); - - sprintf( buffer, "0 %i 0", (i * 64) + 32); - e.AddEPair( "origin", buffer ); - - e.BuildInRadiant( false ); - }*/ -} diff --git a/contrib/bobtoolz/DTreePlanter.h b/contrib/bobtoolz/DTreePlanter.h index 4ee41443..0413b4a3 100644 --- a/contrib/bobtoolz/DTreePlanter.h +++ b/contrib/bobtoolz/DTreePlanter.h @@ -49,18 +49,9 @@ class DTreePlanter { typedef Member DestroyedCaller; DTreePlanter() { - m_numModels = 0; - m_offset = 0; - m_maxPitch = 0; - m_minPitch = 0; - m_maxYaw = 0; - m_minYaw = 0; - m_setAngles = false; - m_useScale = false; - m_autoLink = false; - m_linkNum = 0; - m_world.LoadSelectedBrushes(); + if( m_world.brushList.size() == 0 ) + globalErrorStream() << "bobToolz::TreePlanter requires selected brushes to plant on!\n"; char buffer[256]; GetFilename( buffer, "bt/tp_ent.txt" ); @@ -87,6 +78,9 @@ class DTreePlanter { fclose( file ); } + if( string_empty( m_entType ) ) + globalErrorStream() << "bobToolz::TreePlanter parsed no entity name from " << makeQuoted( buffer ) << '\n'; + m_mouseDown = GlobalRadiant().XYWindowMouseDown_connect( makeSignalHandler3( MouseDownCaller(), *this ) ); m_destroyed = GlobalRadiant().XYWindowDestroyed_connect( makeSignalHandler( DestroyedCaller(), *this ) ); } @@ -195,31 +189,31 @@ class DTreePlanter { } while ( true ); } - bool FindDropPoint( vec3_t in, vec3_t out ); - void DropEntsToGround( void ); - void MakeChain( int linkNum, const char* linkName ); - void SelectChain( void ); + bool FindDropPoint( vec3_t in, vec3_t out ) const; + void DropEntsToGround(); private: DEntity m_world; treeModel_t m_trees[MAX_TP_MODELS]; - int m_numModels; - int m_offset; - int m_maxPitch; - int m_minPitch; - int m_maxYaw; - int m_minYaw; + int m_numModels = 0; + int m_offset = 0; + int m_maxPitch = 0; + int m_minPitch = 0; + int m_maxYaw = 0; + int m_minYaw = 0; - char m_entType[MAX_QPATH]; - char m_linkName[MAX_QPATH]; - int m_linkNum; + char m_entType[MAX_QPATH] = {}; + char m_linkName[MAX_QPATH] = {}; + int m_linkNum = 0; - float m_minScale; - float m_maxScale; + float m_minScale = 0; + float m_maxScale = 0; - bool m_useScale; - bool m_setAngles; - bool m_autoLink; + bool m_useScale = false; + bool m_setAngles = false; + bool m_autoLink = false; }; + +void MakeChain( int linkNum, const char* linkName ); diff --git a/contrib/bobtoolz/bobToolz-GTK.cpp b/contrib/bobtoolz/bobToolz-GTK.cpp index 1948d64d..4f8d257e 100644 --- a/contrib/bobtoolz/bobToolz-GTK.cpp +++ b/contrib/bobtoolz/bobToolz-GTK.cpp @@ -41,14 +41,8 @@ void BobToolz_construct(){ void BobToolz_destroy(){ g_PathView.reset(); g_VisView.reset(); - if ( g_TrainView ) { - delete g_TrainView; - g_TrainView = NULL; - } - if ( g_TreePlanter ) { - delete g_TreePlanter; - g_TreePlanter = NULL; - } + g_TrainView.reset(); + g_TreePlanter.reset(); } // plugin name diff --git a/contrib/bobtoolz/funchandlers-GTK.cpp b/contrib/bobtoolz/funchandlers-GTK.cpp index c58fc539..fdb3c24d 100644 --- a/contrib/bobtoolz/funchandlers-GTK.cpp +++ b/contrib/bobtoolz/funchandlers-GTK.cpp @@ -59,8 +59,8 @@ bool el2Loaded = false; std::unique_ptr g_PathView; std::unique_ptr g_VisView; -DTrainDrawer* g_TrainView = NULL; -DTreePlanter* g_TreePlanter = NULL; +std::unique_ptr g_TrainView; +std::unique_ptr g_TreePlanter; // ------------- //========================// @@ -644,12 +644,8 @@ void DoVisAnalyse(){ } void DoTrainPathPlot() { - if ( g_TrainView ) { - delete g_TrainView; - g_TrainView = NULL; - } - - g_TrainView = new DTrainDrawer(); + g_TrainView.reset(); + g_TrainView.reset( new DTrainDrawer() ); } void DoCaulkSelection() { @@ -668,21 +664,22 @@ void DoCaulkSelection() { } void DoTreePlanter() { - UndoableCommand undo( "bobToolz.treePlanter" ); if ( g_TreePlanter ) { - delete g_TreePlanter; - g_TreePlanter = NULL; - return; + g_TreePlanter.reset(); + } + else{ + g_TreePlanter.reset( new DTreePlanter() ); } - - g_TreePlanter = new DTreePlanter(); } void DoDropEnts() { - UndoableCommand undo( "bobToolz.dropEntities" ); if ( g_TreePlanter ) { + UndoableCommand undo( "bobToolz.dropEntities" ); g_TreePlanter->DropEntsToGround(); } + else{ + globalErrorStream() << "bobToolz::DropEntity error: bobToolz::TreePlanter must be active\n"; + } } void DoMakeChain() { @@ -693,15 +690,12 @@ void DoMakeChain() { return; } UndoableCommand undo( "bobToolz.makeChain" ); - DTreePlanter pl; - pl.MakeChain( rs.linkNum,rs.linkName ); + MakeChain( rs.linkNum, rs.linkName ); } } typedef DPoint* pntTripple[3]; -bool bFacesNoTop[6] = {true, true, true, true, true, false}; - void DoFlipTerrain() { UndoableCommand undo( "bobToolz.flipTerrain" ); vec3_t vUp = { 0.f, 0.f, 1.f }; diff --git a/contrib/bobtoolz/funchandlers.h b/contrib/bobtoolz/funchandlers.h index 05982573..c53668ee 100644 --- a/contrib/bobtoolz/funchandlers.h +++ b/contrib/bobtoolz/funchandlers.h @@ -21,13 +21,10 @@ #include -class DTrainDrawer; -class DTreePlanter; - extern std::unique_ptr g_PathView; extern std::unique_ptr g_VisView; -extern DTrainDrawer* g_TrainView; -extern DTreePlanter* g_TreePlanter; +extern std::unique_ptr g_TrainView; +extern std::unique_ptr g_TreePlanter; // intersect stuff #define BRUSH_OPT_WHOLE_MAP 0