]> git.mxchange.org Git - flightgear.git/commitdiff
Add the this pointer to the tied function calls. This makes it possible to make a...
authorehofman <ehofman>
Thu, 27 May 2004 13:16:53 +0000 (13:16 +0000)
committerehofman <ehofman>
Thu, 27 May 2004 13:16:53 +0000 (13:16 +0000)
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIStorm.cxx
src/AIModel/AIStorm.hxx
src/AIModel/AIThermal.cxx
src/AIModel/AIThermal.hxx

index c725fee679fa7a3573e81899e3c1169586000902..e18217a7c92ad146d89717824eab85ba9218a68c 100644 (file)
@@ -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<bool>(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();
 }
 
index 43bcaa1f34ee830cf32418468fe97e32545ef457..0b8739fda50f63734832bbc2d4e0b77bb15cab45 100644 (file)
@@ -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
index 78d50aa3df6f16711cb2fbcd676940641a58a82a..8759b3a662be25cb771abcde00715a7940a6a469 100644 (file)
 #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<double>(&speed));
    props->tie("velocities/vertical-speed-fps",
                SGRawValueFunctions<double>(FGAIBase::_getVS_fps,
-                                           FGAIBase::_setVS_fps));
+                                           FGAIBase::_setVS_fps, this));
 
    props->tie("position/altitude-ft",
                SGRawValueFunctions<double>(FGAIBase::_getAltitude,
-                                           FGAIBase::_setAltitude));
+                                           FGAIBase::_setAltitude, this));
    props->tie("position/latitude-deg",
                SGRawValueFunctions<double>(FGAIBase::_getLatitude,
-                                           FGAIBase::_setLatitude));
+                                           FGAIBase::_setLatitude, this));
    props->tie("position/longitude-deg",
                SGRawValueFunctions<double>(FGAIBase::_getLongitude,
-                                           FGAIBase::_setLongitude));
+                                           FGAIBase::_setLongitude, this));
 
    props->tie("orientation/pitch-deg",   SGRawValuePointer<double>(&pitch));
    props->tie("orientation/roll-deg",    SGRawValuePointer<double>(&roll));
    props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
 
-   props->tie("radar/bearing-deg",   SGRawValueFunctions<double>(FGAIBase::_getBearing));
-   props->tie("radar/elevation-deg", SGRawValueFunctions<double>(FGAIBase::_getElevation));
-   props->tie("radar/range-nm",      SGRawValueFunctions<double>(FGAIBase::_getRange));
-   props->tie("radar/h-offset", SGRawValueFunctions<double>(FGAIBase::_getH_offset));
-   props->tie("radar/v-offset", SGRawValueFunctions<double>(FGAIBase::_getV_offset)); 
-   props->tie("radar/x-shift", SGRawValueFunctions<double>(FGAIBase::_getX_shift));
-   props->tie("radar/y-shift", SGRawValueFunctions<double>(FGAIBase::_getY_shift));
-   props->tie("radar/rotation", SGRawValueFunctions<double>(FGAIBase::_getRotation));
+   props->tie("radar/bearing-deg",   SGRawValuePointer<double>(&bearing));
+   props->tie("radar/elevation-deg", SGRawValuePointer<double>(&elevation));
+   props->tie("radar/range-nm", SGRawValuePointer<double>(&range));
+   props->tie("radar/h-offset", SGRawValuePointer<double>(&horiz_offset));
+   props->tie("radar/v-offset", SGRawValuePointer<double>(&vert_offset)); 
+   props->tie("radar/x-shift", SGRawValuePointer<double>(&x_shift));
+   props->tie("radar/y-shift", SGRawValuePointer<double>(&y_shift));
+   props->tie("radar/rotation", SGRawValuePointer<double>(&rotation));
 
    props->tie("controls/lighting/nav-lights",
                SGRawValueFunctions<bool>(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::_getLatitude () {
-    return (!_self) ? 0.0 :_self->pos.lat();
-}
-double FGAIBase::_getBearing()   {
-    return (!_self) ? 0.0 :_self->bearing;
-}
-double FGAIBase::_getElevation() {
-    return (!_self) ? 0.0 :_self->elevation;
-}
-double FGAIBase::_getRange()     {
-    return (!_self) ? 0.0 :_self->range;
+double FGAIBase::_getLongitude(void *p) {
+    FGAIBase *self = (FGAIBase *)p;
+    return self->pos.lon();
 }
-double FGAIBase::_getRdot()      {
-    return (!_self) ? 0.0 :_self->rdot;
+double FGAIBase::_getLatitude (void *p) {
+    FGAIBase *self = (FGAIBase *)p;
+    return self->pos.lat();
 }
-double FGAIBase::_getH_offset()  {
-    return (!_self) ? 0.0 :_self->horiz_offset;
+double FGAIBase::_getRdot(void *p)      {
+    FGAIBase *self = (FGAIBase *)p;
+    return self->rdot;
 }
-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;
-}
-
-double FGAIBase::_getVS_fps() {
-    return (!_self) ? 0.0 :_self->vs*60.0;
+double FGAIBase::_getVS_fps(void *p) {
+    FGAIBase *self = (FGAIBase *)p;
+    return self->vs*60.0;
 }
-void FGAIBase::_setVS_fps( double _vs ) {
-    if (_self) _self->vs = _vs/60.0;
+void FGAIBase::_setVS_fps( double _vs, void *p ) {
+    FGAIBase *self = (FGAIBase *)p;
+    self->vs = _vs/60.0;
 }
 
-double FGAIBase::_getAltitude() {
-    return (!_self) ? 0.0 :_self->altitude;
+double FGAIBase::_getAltitude(void *p) {
+    FGAIBase *self = (FGAIBase *)p;
+    return 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() {
index 14e07fb31ed4ae3e275e37a4fe1edffccfcd9e25..cdca809f5066a4acc4903575e3c6f31da5717271 100644 (file)
@@ -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;
 };
 
 
index b53ac439b3686443dfcff2a3bd6ba7e9d62dde15..dad75ddac63232ab953e82c079b68efc54639d25 100644 (file)
@@ -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;
index 8879216f4eb97880774991aa21eb8491e1abb157..06c5d1b3201623b7e0c056c27cc3a0a29139d145 100644 (file)
@@ -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;
 }
 
 
index 2f8d45feb7cf8eb4bb15fc7836b38b04c259a6fd..6e72393f55e6ccf633210e50d7e7d6238dad402f 100644 (file)
@@ -40,9 +40,6 @@ public:
         virtual void unbind();
        void update(double dt);
 
-protected:
-        static FGAIStorm *_self;
-       
 private:
 
         double dt; 
index 0a38f4889b82d589e820053733f7dd3bc7c21216..c94a6e22cc1ef2606e4bf9f6d7fbe1154bb42d14 100644 (file)
@@ -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;
 }
 
 
index 1da663ff864602f553121c0d2692adb8d2090573..be772c733ced52a831bbd19ed66ce88e6d1fd984 100644 (file)
@@ -45,9 +45,6 @@ public:
         inline double getStrength() const { return strength; };
         inline double getDiameter() const { return diameter; };
 
-protected:
-        static FGAIThermal *_self;
-       
 private:
 
         double dt;