Skip to content

Commit

Permalink
fix bobToolz TreePlanter, DropEntity, MakeChain
Browse files Browse the repository at this point in the history
add TreePlanter, DropEntity erroneous use feedback
fix DropEntity crash
fix TreePlanter undo
  • Loading branch information
Garux committed Dec 15, 2024
1 parent ff9aeaf commit 8403e07
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 121 deletions.
81 changes: 21 additions & 60 deletions contrib/bobtoolz/DTreePlanter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "ScriptParser.h"
#include "misc.h"
#include "scenelib.h"
#include "iundo.h"
#include "ientity.h"



Expand All @@ -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];
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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++ ) {
Expand All @@ -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 );

Expand All @@ -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 );
}*/
}
52 changes: 23 additions & 29 deletions contrib/bobtoolz/DTreePlanter.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,9 @@ class DTreePlanter {
typedef Member<DTreePlanter, void, &DTreePlanter::destroyed> 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" );
Expand All @@ -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 ) );
}
Expand Down Expand Up @@ -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 );
10 changes: 2 additions & 8 deletions contrib/bobtoolz/bobToolz-GTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 13 additions & 19 deletions contrib/bobtoolz/funchandlers-GTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ bool el2Loaded = false;

std::unique_ptr<DBobView> g_PathView;
std::unique_ptr<DVisDrawer> g_VisView;
DTrainDrawer* g_TrainView = NULL;
DTreePlanter* g_TreePlanter = NULL;
std::unique_ptr<DTrainDrawer> g_TrainView;
std::unique_ptr<DTreePlanter> g_TreePlanter;
// -------------

//========================//
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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 };
Expand Down
7 changes: 2 additions & 5 deletions contrib/bobtoolz/funchandlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@

#include <memory>

class DTrainDrawer;
class DTreePlanter;

extern std::unique_ptr<class DBobView> g_PathView;
extern std::unique_ptr<class DVisDrawer> g_VisView;
extern DTrainDrawer* g_TrainView;
extern DTreePlanter* g_TreePlanter;
extern std::unique_ptr<class DTrainDrawer> g_TrainView;
extern std::unique_ptr<class DTreePlanter> g_TreePlanter;

// intersect stuff
#define BRUSH_OPT_WHOLE_MAP 0
Expand Down

0 comments on commit 8403e07

Please sign in to comment.