]> git.mxchange.org Git - flightgear.git/commitdiff
Rearrange ID related code. The (this) pointer is now the unique ID of the AIModel...
authorehofman <ehofman>
Wed, 8 Sep 2004 13:21:40 +0000 (13:21 +0000)
committerehofman <ehofman>
Wed, 8 Sep 2004 13:21:40 +0000 (13:21 +0000)
src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx
src/Systems/submodel.cxx
src/Traffic/Schedule.hxx

index cf20462f00118cdb4d9c6d07ac285a07b3e158a3..566b6068f48f1d624438962a68f3d38642ff30bb 100644 (file)
@@ -78,20 +78,19 @@ bool FGAIAircraft::init() {
 void FGAIAircraft::bind() {
     FGAIBase::bind();
 
-/*
     props->tie("controls/gear/gear-down",
-               SGRawValueFunctions<bool>(FGAIAircraft::_getGearDown));
+               SGRawValueMethods<FGAIAircraft,bool>(*this,
+                                              &FGAIAircraft::_getGearDown));
 
     props->getNode("controls/lighting/landing-lights", true)
            ->alias("controls/gear/gear-down");
-*/
 }
 
 void FGAIAircraft::unbind() {
     FGAIBase::unbind();
 
-//    props->untie("controls/gear/gear-down");
-//    props->getNode("controls/lighting/landing-lights")->unalias();
+    props->untie("controls/gear/gear-down");
+    props->getNode("controls/lighting/landing-lights")->unalias();
 }
 
 
@@ -384,4 +383,8 @@ void FGAIAircraft::ProcessFlightPlan( double dt ) {
 
 }
 
-
+bool FGAIAircraft::_getGearDown() const {
+   return ((props->getFloatValue("position/altitude-agl-ft") < 900.0)
+            && (props->getFloatValue("velocities/airspeed-kt")
+                 < performance->land_speed*1.25));
+}
index bcacae266f63d32bcef7c2764d0099c6a938a9c8..33cf99e5e4e402c5964def17eec688fb7bd11cf2 100644 (file)
@@ -83,6 +83,8 @@ private:
 
        void Run(double dt);
         double sign(double x); 
+
+        bool _getGearDown() const;
 };
 
 
index e69602253bc19755fbc01d34d58fcf68c1661410..9757c5d545f4ebc73fc87074c83809ab1301d9e5 100644 (file)
@@ -124,7 +124,8 @@ bool FGAIBase::isa( object_type otype ) {
 
 
 void FGAIBase::bind() {
-   props->tie("id", SGRawValuePointer<int>(&id));
+   props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
+                                         &FGAIBase::_getID));
    props->tie("velocities/true-airspeed-kt",  SGRawValuePointer<double>(&speed));
    props->tie("velocities/vertical-speed-fps",
                SGRawValueMethods<FGAIBase,double>(*this,
@@ -313,3 +314,6 @@ bool FGAIBase::_isNight() {
     return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
 }
 
+int FGAIBase::_getID() const {
+    return (int)(this);
+}
index 90c3a4b6d2bfdc2f6c506fd5c962741a20372326..071abe7887adb0060db6c51dd43712fb44034d4d 100644 (file)
@@ -91,8 +91,7 @@ public:
     void setLongitude( double longitude );
     void setBank( double bank );
 
-    void setID( int ID );
-    int  getID();
+    void* getID();
     void setDie( bool die );
     bool getDie();
 
@@ -139,7 +138,6 @@ protected:
     ssgBranch * model;     //The 3D model object
     SGModelPlacement aip;
     bool delete_me;
-    int id;
     bool invisible;
     bool no_roll;
     double life;
@@ -179,6 +177,8 @@ public:
     double _getY_shift() const;
     double _getRotation() const;
 
+    int _getID() const;
+
     inline double _getRange() { return range; };
 
     static bool _isNight();
@@ -217,10 +217,9 @@ inline void FGAIBase::setLatitude ( double latitude ) {
 inline void FGAIBase::setDie( bool die ) { delete_me = die; }
 inline bool FGAIBase::getDie() { return delete_me; }
 
-inline void FGAIBase::setID( int ID ) { id = ID; }
-inline int  FGAIBase::getID() { return id; }
-
 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
 
+inline void* FGAIBase::getID() { return this; }
+
 #endif // _FG_AIBASE_HXX
 
index 0c8b1c02878407cca83feddec08160dd975b5f7b..97769619c9224996f43cd9641405db6eb8fdedcc 100644 (file)
@@ -42,7 +42,6 @@ FGAIManager::FGAIManager() {
   dt_count = 9;
   scenario_filename = "";
   ai_list.clear();
-  ids.clear();
 }
 
 FGAIManager::~FGAIManager() {
@@ -52,7 +51,6 @@ FGAIManager::~FGAIManager() {
       ++ai_list_itr;
     }
   ai_list.clear();
-  ids.clear();
 }
 
 
@@ -97,7 +95,6 @@ void FGAIManager::update(double dt) {
         ai_list_itr = ai_list.begin();
         while(ai_list_itr != ai_list.end()) {
                 if ((*ai_list_itr)->getDie()) {      
-                   freeID((*ai_list_itr)->getID());
                    delete (*ai_list_itr);
                    --numObjects[(*ai_list_itr)->getType()];
                    --numObjects[0];
@@ -123,45 +120,11 @@ void FGAIManager::update(double dt) {
 }
 
 
-// This function returns the next available ID
-int FGAIManager::assignID() {
-  int maxint = 30000;
-  int x; 
-  bool used;
-  for (x=1; x<maxint; x++) {
-     used = false;
-     id_itr = ids.begin();
-     while( id_itr != ids.end() ) {
-       if ((*id_itr) == x) used = true;
-       ++id_itr;
-     }
-     if (!used) {
-       ids.push_back(x);
-       return x;
-     } 
-  }
-  return -1;  // no available ID's
-}
-
-
-// This function removes an ID from the ID array, making it
-// available for assignment to another AI object
-void FGAIManager::freeID( int ID ) {
-    id_itr = ids.begin();
-    while( id_itr != ids.end() ) {
-      if (*id_itr == ID) {
-        ids.erase( id_itr );
-        return;
-      }
-      ++id_itr;
-    }  
-}
-
-int FGAIManager::createAircraft( FGAIModelEntity *entity ) {
+void*
+FGAIManager::createAircraft( FGAIModelEntity *entity ) {
      
         FGAIAircraft* ai_plane = new FGAIAircraft(this);
         ai_list.push_back(ai_plane);
-        ai_plane->setID( assignID() );
         ++numObjects[0];
         ++numObjects[FGAIBase::otAircraft];
         if (entity->m_class == "light") {
@@ -192,14 +155,14 @@ int FGAIManager::createAircraft( FGAIModelEntity *entity ) {
 
         ai_plane->init();
         ai_plane->bind();
-        return ai_plane->getID();
+        return ai_plane;
 }
 
-int FGAIManager::createShip( FGAIModelEntity *entity ) {
+void*
+FGAIManager::createShip( FGAIModelEntity *entity ) {
 
         FGAIShip* ai_ship = new FGAIShip(this);
         ai_list.push_back(ai_ship);
-        ai_ship->setID( assignID() );
         ++numObjects[0];
         ++numObjects[FGAIBase::otShip];
         ai_ship->setHeading(entity->heading);
@@ -216,14 +179,14 @@ int FGAIManager::createShip( FGAIModelEntity *entity ) {
 
         ai_ship->init();
         ai_ship->bind();
-        return ai_ship->getID();
+        return ai_ship;
 }
 
-int FGAIManager::createBallistic( FGAIModelEntity *entity ) {
+void*
+FGAIManager::createBallistic( FGAIModelEntity *entity ) {
 
         FGAIBallistic* ai_ballistic = new FGAIBallistic(this);
         ai_list.push_back(ai_ballistic);
-        ai_ballistic->setID( assignID() );    
         ++numObjects[0];
         ++numObjects[FGAIBase::otBallistic];
         ai_ballistic->setAzimuth(entity->azimuth);
@@ -241,14 +204,14 @@ int FGAIManager::createBallistic( FGAIModelEntity *entity ) {
        ai_ballistic->setWind(entity->wind);
         ai_ballistic->init();
         ai_ballistic->bind();
-        return ai_ballistic->getID();
+        return ai_ballistic;
 }
 
-int FGAIManager::createStorm( FGAIModelEntity *entity ) {
+void*
+FGAIManager::createStorm( FGAIModelEntity *entity ) {
 
         FGAIStorm* ai_storm = new FGAIStorm(this);
         ai_list.push_back(ai_storm);
-        ai_storm->setID( assignID() );
         ++numObjects[0];
         ++numObjects[FGAIBase::otStorm];
         ai_storm->setHeading(entity->heading);
@@ -259,14 +222,14 @@ int FGAIManager::createStorm( FGAIModelEntity *entity ) {
         ai_storm->setLatitude(entity->latitude);
         ai_storm->init();
         ai_storm->bind();
-        return ai_storm->getID();
+        return ai_storm;
 }
 
-int FGAIManager::createThermal( FGAIModelEntity *entity ) {
+void*
+FGAIManager::createThermal( FGAIModelEntity *entity ) {
 
         FGAIThermal* ai_thermal = new FGAIThermal(this);
         ai_list.push_back(ai_thermal);
-        ai_thermal->setID( assignID() );
         ++numObjects[0];
         ++numObjects[FGAIBase::otThermal];
         ai_thermal->setLongitude(entity->longitude);
@@ -275,20 +238,19 @@ int FGAIManager::createThermal( FGAIModelEntity *entity ) {
         ai_thermal->setDiameter(entity->diameter / 6076.11549);
         ai_thermal->init();
         ai_thermal->bind();
-        return ai_thermal->getID();
+        return ai_thermal;
 }
 
-void FGAIManager::destroyObject( int ID ) {
+void FGAIManager::destroyObject( void* ID ) {
         ai_list_itr = ai_list.begin();
         while(ai_list_itr != ai_list.end()) {
             if ((*ai_list_itr)->getID() == ID) {
-              freeID( ID );
               --numObjects[0];
               --numObjects[(*ai_list_itr)->getType()];
               delete (*ai_list_itr);
               ai_list.erase(ai_list_itr);
-              --ai_list_itr;
-              return;
+
+              break;
             }
             ++ai_list_itr;
         }
@@ -353,7 +315,3 @@ void FGAIManager::processScenario( string filename ) {
   delete s;
 }
 
-int FGAIManager::getNum( FGAIBase::object_type ot ) {
-  return numObjects[ot];
-}
-
index 560e82e7926821eb813a64f2fe9714a885c1bdbd..fd3357f5bb23ac8bf099614ea463777fff897e9f 100644 (file)
@@ -52,11 +52,6 @@ private:
     ai_list_type ai_list;
     ai_list_iterator ai_list_itr;
 
-    // array of already-assigned ID's
-    typedef vector <int> id_vector_type;
-    id_vector_type ids;                    
-    id_vector_type::iterator id_itr;
-
 public:
 
     FGAIManager();
@@ -67,16 +62,13 @@ public:
     void unbind();
     void update(double dt);
 
-    int assignID();
-    void freeID(int ID);
-
-    int createBallistic( FGAIModelEntity *entity );
-    int createAircraft( FGAIModelEntity *entity );
-    int createThermal( FGAIModelEntity *entity );
-    int createStorm( FGAIModelEntity *entity );
-    int createShip( FGAIModelEntity *entity );
+    void* createBallistic( FGAIModelEntity *entity );
+    void* createAircraft( FGAIModelEntity *entity );
+    void* createThermal( FGAIModelEntity *entity );
+    void* createStorm( FGAIModelEntity *entity );
+    void* createShip( FGAIModelEntity *entity );
 
-    void destroyObject( int ID );
+    void destroyObject( void* ID );
 
     inline double get_user_latitude() { return user_latitude; }
     inline double get_user_longitude() { return user_longitude; }
@@ -86,8 +78,9 @@ public:
     inline double get_user_yaw() { return user_yaw; }
     inline double get_user_speed() {return user_speed; }
 
+    inline int getNum( FGAIBase::object_type ot ) { return numObjects[ot]; }
+
     void processScenario( string filename );
-    int getNum( FGAIBase::object_type ot);
 
 private:
 
index f936b4d0648bcda7d767a79ac63069d196f0d746..28b7bc61cfc13f7ce99ce3ca290fd737cf79315f 100644 (file)
@@ -112,7 +112,7 @@ SubmodelSystem::release (submodel* sm, double dt)
   entity.wind_from_east = IC.wind_from_east;
   entity.wind_from_north = IC.wind_from_north;
   entity.wind = sm->wind;
-  int rval = ai->createBallistic( &entity );
+  ai->createBallistic( &entity );
 
   //cout << "Submodel created." << endl;
   if (sm->count > 0) (sm->count)--; 
index 689524a54db2a58465c33f5617020ac5c29a35e5..0664e36be4a9cf3c6158b05b9b98df28246e85c4 100644 (file)
@@ -40,7 +40,7 @@ class FGAISchedule
   FGScheduledFlightVec flights;
   float lat;
   float lon; 
-  int AIManagerRef;
+  void* AIManagerRef;
   bool firstRun;
 
  public: