]> git.mxchange.org Git - flightgear.git/commitdiff
Make the AI model export it's internal state to the property tree under /ai/model...
authorehofman <ehofman>
Sun, 21 Dec 2003 20:12:55 +0000 (20:12 +0000)
committerehofman <ehofman>
Sun, 21 Dec 2003 20:12:55 +0000 (20:12 +0000)
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIBallistic.cxx
src/AIModel/AIBallistic.hxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIShip.cxx
src/AIModel/AIShip.hxx

index 49346f99ac2e0aaeb8b81449347f25fa5effeb40..f19c054fab1529cd7017962052bfbc8c4cd21a00 100644 (file)
@@ -62,6 +62,14 @@ bool FGAIAircraft::init() {
    return FGAIBase::init();
 }
 
+void FGAIAircraft::bind() {
+    FGAIBase::bind();
+}
+
+void FGAIAircraft::unbind() {
+    FGAIBase::unbind();
+}
+
 
 void FGAIAircraft::update(double dt) {
 
index 43aab0384390c969dda1899b00d4f1dc2eedaed9..8cf2a40364c53be58b0085269e13dd9fb448d8d2 100644 (file)
@@ -53,6 +53,8 @@ public:
        ~FGAIAircraft();
        
        bool init();
+        virtual void bind();
+        virtual void unbind();
        void update(double dt);
 
         void SetPerformance(const PERF_STRUCT *ps);
index 2d96b7c750014cd85ba84514920f2f443b13f8c5..750096af4e71288ff6520135ba1420393d705201 100644 (file)
@@ -44,6 +44,13 @@ bool FGAIBallistic::init() {
    return true;
 }
 
+void FGAIBallistic::bind() {
+    FGAIBase::bind();
+}
+
+void FGAIBallistic::unbind() {
+    FGAIBase::unbind();
+}
 
 void FGAIBallistic::update(double dt) {
 
index 71951d204447c8894328719de949074e414f7a2c..3878778b9c79b3132484080602c002de9db78065 100644 (file)
@@ -32,6 +32,8 @@ public:
     ~FGAIBallistic();
        
     bool init();
+    virtual void bind();
+    virtual void unbind();
     void update(double dt);
 
     void setAzimuth( double az );
index 11b17dc412c190632d08d11c7cf888dcecd42887..5637ca38f6c0999f4da6a58a441daaba03d9aea0 100644 (file)
 #  include <config.h>
 #endif
 
+#include <simgear/compiler.h>
+
+#include STL_STRING
+
 #include <plib/sg.h>
 #include <plib/ssg.h>
-#include <Main/globals.hxx>
-#include <Scenery/scenery.hxx>
+
 #include <simgear/math/point3d.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/model/location.hxx>
 #include <simgear/scene/model/model.hxx>
 #include <simgear/debug/logstream.hxx>
-#include <string>
+#include <simgear/props/props.hxx>
+
+#include <Main/globals.hxx>
+#include <Scenery/scenery.hxx>
+
 
 #include "AIBase.hxx"
 
@@ -50,9 +57,12 @@ void FGAIBase::Transform() {
 
 
 bool FGAIBase::init() {
+
+   props = globals->get_props()->getNode("ai/model", true);
+
    ssgBranch *model = sgLoad3DModel( globals->get_fg_root(),
                                     model_path.c_str(),
-                                    globals->get_props(),
+                                     props,
                                     globals->get_sim_time_sec() );
    if (model) {
      aip.init( model );
@@ -66,33 +76,28 @@ bool FGAIBase::init() {
    setDie(false);
 }
 
+void FGAIBase::bind() {
+   props->tie("velocities/airspeed-kt",  SGRawValuePointer<double>(&speed));
+   props->tie("velocities/vertical-speed-fps", SGRawValuePointer<double>(&vs));
 
-void FGAIBase::setPath( const char* model ) {
-  model_path.append(model);
-}
+   props->tie("position/altitude-ft", SGRawValuePointer<double>(&altitude));
+   props->tie("position/latitude-deg", SGRawValuePointer<double>(&lat));
+   props->tie("position/longitude-deg", SGRawValuePointer<double>(&lon));
 
-void FGAIBase::setSpeed( double speed_KTAS ) {
-  speed = tgt_speed = speed_KTAS;
+   props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
+   props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
+   props->tie("orientation/heading-deg", SGRawValuePointer<double>(&hdg));
 }
 
-void FGAIBase::setAltitude( double altitude_ft ) {
-  altitude = tgt_altitude = altitude_ft;
-  pos.setelev(altitude * 0.3048);
-}
+void FGAIBase::unbind() {
+    props->untie("velocities/airspeed-kt");
+    props->untie("velocities/vertical-speed-fps");
 
-void FGAIBase::setLongitude( double longitude ) {
-  pos.setlon(longitude);
-}
+    props->untie("position/altitude-ft");
+    props->untie("position/latitude-deg");
+    props->untie("position/longitude-deg");
 
-void FGAIBase::setLatitude( double latitude ) {
-  pos.setlat(latitude);
+    props->untie("orientation/pitch-deg");
+    props->untie("orientation/roll-deg");
+    props->untie("orientation/heading-deg");
 }
-
-void FGAIBase::setHeading( double heading ) {
-  hdg = tgt_heading = heading;
-}
-
-void FGAIBase::setDie( bool die ) {
-  delete_me = die;
-}
-
index 8e562628fce47c6e7089aa2323587d43249e14da..9221ddb4f24894383064161bd58ae0b6e35d1ac0 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef _FG_AIBASE_HXX
 #define _FG_AIBASE_HXX
 
+#include <simgear/constants.h>
 #include <simgear/math/point3d.hxx>
 #include <simgear/scene/model/placement.hxx>
 #include <string>
@@ -33,7 +34,10 @@ public:
     virtual ~FGAIBase();
     virtual void update(double dt);
     inline Point3D GetPos() { return(pos); }
+
     virtual bool init();
+    virtual void bind();
+    virtual void unbind();
 
     void setPath( const char* model );
     void setSpeed( double speed_KTAS );
@@ -41,12 +45,16 @@ public:
     void setLongitude( double longitude );
     void setLatitude( double latitude );
     void setHeading( double heading );
+
     void setDie( bool die );
-    inline bool getDie() { return delete_me; }
+    bool getDie();
 
 protected:
 
+    SGPropertyNode *props;
+
     Point3D pos;       // WGS84 lat & lon in degrees, elev above sea-level in meters
+    double lat, lon;   // As above, this is needed for the property bindings
     double hdg;                // True heading in degrees
     double roll;       // degrees, left is negative
     double pitch;      // degrees, nose-down is negative
@@ -68,7 +76,40 @@ protected:
     bool delete_me;
 
     void Transform();
+
 };
 
+
+inline void FGAIBase::setPath( const char* model ) {
+  model_path.append(model);
+}
+
+inline void FGAIBase::setSpeed( double speed_KTAS ) {
+  speed = tgt_speed = speed_KTAS;
+}
+
+inline void FGAIBase::setAltitude( double altitude_ft ) {
+  altitude = tgt_altitude = altitude_ft;
+  pos.setelev(altitude * SG_FEET_TO_METER);
+}
+
+
+inline void FGAIBase::setLongitude( double longitude ) {
+  lon = longitude;
+  pos.setlon(longitude);
+}
+
+inline void FGAIBase::setLatitude( double latitude ) {
+  lat = latitude;
+  pos.setlat(latitude);
+}
+
+inline void FGAIBase::setHeading( double heading ) {
+  hdg = tgt_heading = heading;
+}
+
+inline void FGAIBase::setDie( bool die ) { delete_me = die; }
+inline bool FGAIBase::getDie() { return delete_me; }
+
 #endif  // _FG_AIBASE_HXX
 
index c6dbda134f277d4c002ff17dd2fbdde60a063300..1b39b9afa317f3ea893c69d8de26ee06cd7bff1c 100644 (file)
@@ -72,6 +72,7 @@ void FGAIManager::init() {
         ai_plane->setLongitude(entry->getDoubleValue("longitude"));
         ai_plane->setLatitude(entry->getDoubleValue("latitude"));
         ai_plane->init();
+        ai_plane->bind();
 
       } else if (!strcmp(entry->getStringValue("type", ""), "ship")) {
         FGAIShip* ai_ship = new FGAIShip;
@@ -83,6 +84,7 @@ void FGAIManager::init() {
         ai_ship->setLongitude(entry->getDoubleValue("longitude"));
         ai_ship->setLatitude(entry->getDoubleValue("latitude"));
         ai_ship->init();
+        ai_ship->bind();
 
       } else if (!strcmp(entry->getStringValue("type", ""), "ballistic")) {
         FGAIBallistic* ai_ballistic = new FGAIBallistic;
@@ -95,6 +97,7 @@ void FGAIManager::init() {
         ai_ballistic->setLongitude(entry->getDoubleValue("longitude"));
         ai_ballistic->setLatitude(entry->getDoubleValue("latitude"));
         ai_ballistic->init();
+        ai_ballistic->bind();
       } 
     }
   }
@@ -108,6 +111,11 @@ void FGAIManager::bind() {
 
 
 void FGAIManager::unbind() {
+    ai_list_itr = ai_list.begin();
+    while(ai_list_itr != ai_list.end()) {
+        (*ai_list_itr)->unbind();
+        ++ai_list_itr;
+    }
 }
 
 
index 4a81972b6a99cefa2c62d19067060679c937e685..650d835832158c84c0a4875d0e9dcb7cd16afc9d 100644 (file)
@@ -40,7 +40,13 @@ bool FGAIShip::init() {
    return FGAIBase::init();
 }
 
+void FGAIShip::bind() {
+    FGAIBase::bind();
+}
 
+void FGAIShip::unbind() {
+    FGAIBase::unbind();
+}
 
 void FGAIShip::update(double dt) {
 
index c36686245e33bc96efa43eb96d67f6290f403c41..d4d29f0223340a001eb465898f608f4beccbb791 100644 (file)
@@ -33,6 +33,8 @@ public:
        ~FGAIShip();
        
        bool init();
+        virtual void bind();
+        virtual void unbind();
        void update(double dt);
 
         void AccelTo(double speed);