From b7acd97f2c0cfd347dc7198be7447a1039fd850d Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 27 May 2004 13:16:53 +0000 Subject: [PATCH] Add the this pointer to the tied function calls. This makes it possible to make a distinction between the different aircraft models. --- src/AIModel/AIAircraft.cxx | 8 +-- src/AIModel/AIAircraft.hxx | 12 ----- src/AIModel/AIBase.cxx | 100 +++++++++++++++---------------------- src/AIModel/AIBase.hxx | 40 +++++++-------- src/AIModel/AIManager.cxx | 2 + src/AIModel/AIStorm.cxx | 4 -- src/AIModel/AIStorm.hxx | 3 -- src/AIModel/AIThermal.cxx | 4 -- src/AIModel/AIThermal.hxx | 3 -- 9 files changed, 64 insertions(+), 112 deletions(-) diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index c725fee67..e18217a7c 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -49,10 +49,7 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = { }; -FGAIAircraft *FGAIAircraft::_self = NULL; - FGAIAircraft::FGAIAircraft(FGAIManager* mgr) { - _self = this; // This needs to be the first entry. manager = mgr; _type_str = "aircraft"; _otype = otAircraft; @@ -68,7 +65,6 @@ FGAIAircraft::FGAIAircraft(FGAIManager* mgr) { FGAIAircraft::~FGAIAircraft() { if (fp) delete fp; - _self = NULL; } @@ -79,10 +75,10 @@ bool FGAIAircraft::init() { void FGAIAircraft::bind() { FGAIBase::bind(); +/* props->tie("controls/gear/gear-down", SGRawValueFunctions(FGAIAircraft::_getGearDown)); -/* props->getNode("controls/lighting/landing-lights", true) ->alias("controls/gear/gear-down"); */ @@ -91,7 +87,7 @@ void FGAIAircraft::bind() { void FGAIAircraft::unbind() { FGAIBase::unbind(); - props->untie("controls/gear/gear-down"); +// props->untie("controls/gear/gear-down"); // props->getNode("controls/lighting/landing-lights")->unalias(); } diff --git a/src/AIModel/AIAircraft.hxx b/src/AIModel/AIAircraft.hxx index 43bcaa1f3..0b8739fda 100644 --- a/src/AIModel/AIAircraft.hxx +++ b/src/AIModel/AIAircraft.hxx @@ -69,9 +69,6 @@ public: void ProcessFlightPlan( double dt ); //double getHeading(double lat1, double lon1, double lat2, double lon2); -protected: - static FGAIAircraft *_self; - private: bool hdg_lock; @@ -85,16 +82,7 @@ private: void Run(double dt); double sign(double x); - - static bool _getGearDown(); }; -inline bool FGAIAircraft::_getGearDown() { - return (!_self) ? false - : ((fgGetFloat("/position/altitude-agl-ft") < 150.0) - && (fgGetFloat("/velocities/airspeed-kt") - < _self->performance->land_speed*1.5)); -} - #endif // _FG_AIAircraft_HXX diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 78d50aa3d..8759b3a66 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -43,10 +43,7 @@ #include "AIBase.hxx" #include "AIManager.hxx" -FGAIBase *FGAIBase::_self = NULL; - FGAIBase::FGAIBase() { - _self = this; _type_str = "model"; tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0; bearing = elevation = range = rdot = 0.0; @@ -61,10 +58,9 @@ FGAIBase::FGAIBase() { FGAIBase::~FGAIBase() { globals->get_scenery()->get_scene_graph()->removeKid(aip.getSceneGraph()); - unbind(); + // unbind(); SGPropertyNode *root = globals->get_props()->getNode("ai/models", true); root->removeChild(_type_str.c_str(), index); - _self = NULL; } void FGAIBase::update(double dt) { @@ -122,30 +118,30 @@ void FGAIBase::bind() { props->tie("velocities/true-airspeed-kt", SGRawValuePointer(&speed)); props->tie("velocities/vertical-speed-fps", SGRawValueFunctions(FGAIBase::_getVS_fps, - FGAIBase::_setVS_fps)); + FGAIBase::_setVS_fps, this)); props->tie("position/altitude-ft", SGRawValueFunctions(FGAIBase::_getAltitude, - FGAIBase::_setAltitude)); + FGAIBase::_setAltitude, this)); props->tie("position/latitude-deg", SGRawValueFunctions(FGAIBase::_getLatitude, - FGAIBase::_setLatitude)); + FGAIBase::_setLatitude, this)); props->tie("position/longitude-deg", SGRawValueFunctions(FGAIBase::_getLongitude, - FGAIBase::_setLongitude)); + FGAIBase::_setLongitude, this)); props->tie("orientation/pitch-deg", SGRawValuePointer(&pitch)); props->tie("orientation/roll-deg", SGRawValuePointer(&roll)); props->tie("orientation/true-heading-deg", SGRawValuePointer(&hdg)); - props->tie("radar/bearing-deg", SGRawValueFunctions(FGAIBase::_getBearing)); - props->tie("radar/elevation-deg", SGRawValueFunctions(FGAIBase::_getElevation)); - props->tie("radar/range-nm", SGRawValueFunctions(FGAIBase::_getRange)); - props->tie("radar/h-offset", SGRawValueFunctions(FGAIBase::_getH_offset)); - props->tie("radar/v-offset", SGRawValueFunctions(FGAIBase::_getV_offset)); - props->tie("radar/x-shift", SGRawValueFunctions(FGAIBase::_getX_shift)); - props->tie("radar/y-shift", SGRawValueFunctions(FGAIBase::_getY_shift)); - props->tie("radar/rotation", SGRawValueFunctions(FGAIBase::_getRotation)); + props->tie("radar/bearing-deg", SGRawValuePointer(&bearing)); + props->tie("radar/elevation-deg", SGRawValuePointer(&elevation)); + props->tie("radar/range-nm", SGRawValuePointer(&range)); + props->tie("radar/h-offset", SGRawValuePointer(&horiz_offset)); + props->tie("radar/v-offset", SGRawValuePointer(&vert_offset)); + props->tie("radar/x-shift", SGRawValuePointer(&x_shift)); + props->tie("radar/y-shift", SGRawValuePointer(&y_shift)); + props->tie("radar/rotation", SGRawValuePointer(&rotation)); props->tie("controls/lighting/nav-lights", SGRawValueFunctions(FGAIBase::_isNight)); @@ -182,59 +178,43 @@ void FGAIBase::unbind() { /* * getters and Setters */ -void FGAIBase::_setLongitude( double longitude ) { - if (_self) _self->pos.setlon(longitude); +void FGAIBase::_setLongitude( double longitude, void *p ) { + FGAIBase *self = (FGAIBase *)p; + self->pos.setlon(longitude); } -void FGAIBase::_setLatitude ( double latitude ) { - if (_self) _self->pos.setlat(latitude); +void FGAIBase::_setLatitude ( double latitude, void *p ) { + FGAIBase *self = (FGAIBase *)p; + self->pos.setlat(latitude); } -double FGAIBase::_getLongitude() { - return (!_self) ? 0.0 :_self->pos.lon(); +double FGAIBase::_getLongitude(void *p) { + FGAIBase *self = (FGAIBase *)p; + return self->pos.lon(); } -double FGAIBase::_getLatitude () { - return (!_self) ? 0.0 :_self->pos.lat(); +double FGAIBase::_getLatitude (void *p) { + FGAIBase *self = (FGAIBase *)p; + return self->pos.lat(); } -double FGAIBase::_getBearing() { - return (!_self) ? 0.0 :_self->bearing; +double FGAIBase::_getRdot(void *p) { + FGAIBase *self = (FGAIBase *)p; + return self->rdot; } -double FGAIBase::_getElevation() { - return (!_self) ? 0.0 :_self->elevation; +double FGAIBase::_getVS_fps(void *p) { + FGAIBase *self = (FGAIBase *)p; + return self->vs*60.0; } -double FGAIBase::_getRange() { - return (!_self) ? 0.0 :_self->range; -} -double FGAIBase::_getRdot() { - return (!_self) ? 0.0 :_self->rdot; -} -double FGAIBase::_getH_offset() { - return (!_self) ? 0.0 :_self->horiz_offset; -} -double FGAIBase::_getV_offset() { - return (!_self) ? 0.0 :_self->vert_offset; -} -double FGAIBase::_getX_shift() { - return (!_self) ? 0.0 :_self->x_shift; -} -double FGAIBase::_getY_shift() { - return (!_self) ? 0.0 :_self->y_shift; -} -double FGAIBase::_getRotation() { - return (!_self) ? 0.0 :_self->rotation; +void FGAIBase::_setVS_fps( double _vs, void *p ) { + FGAIBase *self = (FGAIBase *)p; + self->vs = _vs/60.0; } -double FGAIBase::_getVS_fps() { - return (!_self) ? 0.0 :_self->vs*60.0; +double FGAIBase::_getAltitude(void *p) { + FGAIBase *self = (FGAIBase *)p; + return self->altitude; } -void FGAIBase::_setVS_fps( double _vs ) { - if (_self) _self->vs = _vs/60.0; -} - -double FGAIBase::_getAltitude() { - return (!_self) ? 0.0 :_self->altitude; -} -void FGAIBase::_setAltitude( double _alt ) { - if (_self) _self->setAltitude( _alt ); +void FGAIBase::_setAltitude( double _alt, void *p ) { + FGAIBase *self = (FGAIBase *)p; + self->setAltitude( _alt ); } bool FGAIBase::_isNight() { diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 14e07fb31..cdca809f5 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -48,8 +48,6 @@ public: virtual void bind(); virtual void unbind(); - inline bool isValid() { return (_self != 0); } - void setPath( const char* model ); void setSpeed( double speed_KTAS ); void setAltitude( double altitude_ft ); @@ -108,7 +106,6 @@ protected: void Transform(); - static FGAIBase *_self; string _type_str; object_type _otype; int index; @@ -118,29 +115,32 @@ public: object_type getType(); bool isa( object_type otype ); - static double _getVS_fps(); - static void _setVS_fps( double _vs ); + static double _getVS_fps(void *p); + static void _setVS_fps( double _vs, void *p ); - static double _getAltitude(); - static void _setAltitude( double _alt ); + static double _getAltitude(void *p); + static void _setAltitude( double _alt, void *p ); - static void _setLongitude( double longitude ); - static void _setLatitude ( double latitude ); + static void _setLongitude( double longitude, void *p ); + static void _setLatitude ( double latitude, void *p ); - static double _getLongitude(); - static double _getLatitude (); + static double _getLongitude(void *p); + static double _getLatitude (void *p); - static double _getBearing(); - static double _getElevation(); - static double _getRange(); - static double _getRdot(); - static double _getH_offset(); - static double _getV_offset(); - static double _getX_shift(); - static double _getY_shift(); - static double _getRotation(); + static double _getBearing(void *p); + static double _getElevation(void *p); + inline double _getRange() { return range; }; + static double _getRdot(void *p); + static double _getH_offset(void *p); + static double _getV_offset(void *p); + static double _getX_shift(void *p); + static double _getY_shift(void *p); + static double _getRotation(void *p); static bool _isNight(); + +private: + FGAIBase *self; }; diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index b53ac439b..dad75ddac 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -217,6 +217,7 @@ int FGAIManager::createAircraft( string model_class, string path, double heading, double speed, double pitch, double roll ) { FGAIAircraft* ai_plane = new FGAIAircraft(this); +cout << "ai_plane: " << ai_plane << endl; ai_list.push_back(ai_plane); ai_plane->setID( assignID() ); ++numObjects; @@ -248,6 +249,7 @@ int FGAIManager::createAircraft( string model_class, string path, FGAIFlightPlan* flightplan ) { FGAIAircraft* ai_plane = new FGAIAircraft(this); +cout << "ai_plane1: " << ai_plane << endl; ai_list.push_back(ai_plane); ai_plane->setID( assignID() ); ++numObjects; diff --git a/src/AIModel/AIStorm.cxx b/src/AIModel/AIStorm.cxx index 8879216f4..06c5d1b32 100644 --- a/src/AIModel/AIStorm.cxx +++ b/src/AIModel/AIStorm.cxx @@ -34,18 +34,14 @@ SG_USING_STD(string); #include "AIStorm.hxx" -FGAIStorm *FGAIStorm::_self = NULL; - FGAIStorm::FGAIStorm(FGAIManager* mgr) { manager = mgr; - _self = this; _type_str = "thunderstorm"; _otype = otStorm; } FGAIStorm::~FGAIStorm() { - _self = NULL; } diff --git a/src/AIModel/AIStorm.hxx b/src/AIModel/AIStorm.hxx index 2f8d45feb..6e72393f5 100644 --- a/src/AIModel/AIStorm.hxx +++ b/src/AIModel/AIStorm.hxx @@ -40,9 +40,6 @@ public: virtual void unbind(); void update(double dt); -protected: - static FGAIStorm *_self; - private: double dt; diff --git a/src/AIModel/AIThermal.cxx b/src/AIModel/AIThermal.cxx index 0a38f4889..c94a6e22c 100644 --- a/src/AIModel/AIThermal.cxx +++ b/src/AIModel/AIThermal.cxx @@ -34,11 +34,8 @@ SG_USING_STD(string); #include "AIThermal.hxx" -FGAIThermal *FGAIThermal::_self = NULL; - FGAIThermal::FGAIThermal(FGAIManager* mgr) { manager = mgr; - _self = this; _type_str = "thermal"; _otype = otThermal; max_strength = 6.0; @@ -48,7 +45,6 @@ FGAIThermal::FGAIThermal(FGAIManager* mgr) { FGAIThermal::~FGAIThermal() { - _self = NULL; } diff --git a/src/AIModel/AIThermal.hxx b/src/AIModel/AIThermal.hxx index 1da663ff8..be772c733 100644 --- a/src/AIModel/AIThermal.hxx +++ b/src/AIModel/AIThermal.hxx @@ -45,9 +45,6 @@ public: inline double getStrength() const { return strength; }; inline double getDiameter() const { return diameter; }; -protected: - static FGAIThermal *_self; - private: double dt;