]> git.mxchange.org Git - flightgear.git/commitdiff
Don't use the this pointer for referencing the AIModels anymore, this
authorehofman <ehofman>
Sat, 15 Oct 2005 14:55:51 +0000 (14:55 +0000)
committerehofman <ehofman>
Sat, 15 Oct 2005 14:55:51 +0000 (14:55 +0000)
turns out to get problematic on 64-bit systems. Instead use a regular
int based approach.

src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx
src/Traffic/Schedule.cxx
src/Traffic/Schedule.hxx
src/Traffic/TrafficMgr.cxx
src/Traffic/TrafficMgr.hxx

index db006f9b3bb350b7de415b768c66822cbeab8e12..7560ff0493192fd7110e7bfdcf45c25346e017e4 100644 (file)
@@ -50,10 +50,11 @@ const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
 
 
 FGAIBase::FGAIBase()
 fp( NULL ),
 : fp( NULL ),
     model( NULL ),
     props( NULL ),
-    manager( NULL )
+    manager( NULL ),
+    _refID( _newAIModelID() )
 {
     _type_str = "model";
     tgt_heading = tgt_altitude = tgt_speed = 0.0;
@@ -179,7 +180,7 @@ bool FGAIBase::isa( object_type otype ) {
 
 void FGAIBase::bind() {
    props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
-                                         &FGAIBase::_getID));
+                                         &FGAIBase::getID));
    props->tie("velocities/true-airspeed-kt",  SGRawValuePointer<double>(&speed));
    props->tie("velocities/vertical-speed-fps",
                SGRawValueMethods<FGAIBase,double>(*this,
@@ -399,8 +400,8 @@ bool FGAIBase::_isNight() {
     return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
 }
 
-int FGAIBase::_getID() const {
-    return (int)(this);
+int FGAIBase::getID() const {
+    return  _refID;
 }
 
 void FGAIBase::CalculateMach() {
@@ -438,3 +439,9 @@ void FGAIBase::CalculateMach() {
  //    cout  << "Speed(ft/s) "<< speed <<" Altitude(ft) "<< altitude << " Mach " << Mach;
 }
 
+int FGAIBase::_newAIModelID() {
+   static int id = 0;
+   if (!++id) id++;    // id = 0 is not allowed.
+   return id;
+}
+
index 5def20200be6eb0c3313cb1777aca75dec8f73ff..4f17130592d5ef908ca436b5ea60f1b3f7ed74d1 100644 (file)
@@ -36,6 +36,7 @@ SG_USING_STD(list);
 class FGAIManager;
 class FGAIFlightPlan;
 
+
 struct ParkPosition {
   ParkPosition(const ParkPosition& pp)
     : name(pp.name), offset(pp.offset), heading_deg(pp.heading_deg)
@@ -129,8 +130,8 @@ public:
     void setYoffset( double y_offset );
     void setZoffset( double z_offset );
 
+    int getID() const;
 
-    void* getID();
     void setDie( bool die );
     bool getDie();
 
@@ -194,6 +195,11 @@ protected:
     object_type _otype;
     int index;
 
+    static int _newAIModelID();
+
+private:
+    const int _refID;
+
 public:
 
     object_type getType();
@@ -229,8 +235,6 @@ public:
     static const double e;
     static const double lbs_to_slugs;
 
-    int _getID() const;
-
     inline double _getRange() { return range; };
   ssgBranch * load3DModel(const string& fg_root, 
                          const string &path,
@@ -279,8 +283,6 @@ inline bool FGAIBase::getDie() { return delete_me; }
 
 inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
 
-inline void* FGAIBase::getID() { return this; }
-
 
 
 #endif // _FG_AIBASE_HXX
index be872c4a19c58a4d2eb274b1b15ac30f8313466f..96742864e3fb574593e04a542ef3fa9ee0b84cd3 100644 (file)
@@ -352,7 +352,7 @@ FGAIManager::createStatic( FGAIModelEntity *entity ) {
         return ai_static;
 }
 
-void FGAIManager::destroyObject( void* ID ) {
+void FGAIManager::destroyObject( int ID ) {
         ai_list_iterator ai_list_itr = ai_list.begin();
         while(ai_list_itr != ai_list.end()) {
             if ((*ai_list_itr)->getID() == ID) {
index 2ecdbef1c4f41c8834505768d886d220c4d34792..86eaab9a1b9fe5971bb75d8e4e564b00e4bd351a 100644 (file)
@@ -90,7 +90,7 @@ public:
     void* createCarrier( FGAIModelEntity *entity );
     void* createStatic( FGAIModelEntity *entity );
 
-    void destroyObject( void* ID );
+    void destroyObject( int ID );
 
     inline double get_user_latitude() { return user_latitude; }
     inline double get_user_longitude() { return user_longitude; }
index 819fa1bedf16be4e316270b1c1cac199abc91b97..6af4287f1029f1b530ed15c1d94f4254dc8c86be 100644 (file)
@@ -367,7 +367,8 @@ bool FGAISchedule::update(time_t now)
              
              // Fixme: A non-existent model path results in an
              // abort, due to an unhandled exeption, in fg main loop.
-             AIManagerRef = aimgr->createAircraft( &entity, this);
+              FGAIBase *aircraft = (FGAIBase*)aimgr->createAircraft( &entity, this);
+             AIManagerRef = aircraft->getID();
              //cerr << "Class: " << m_class << ". acType: " << acType << ". Airline: " << airline << ". Speed = " << speed << ". From " << dep->getId() << " to " << arr->getId() << ". Time Fraction = " << (remainingTimeEnroute/(double) totalTimeEnroute) << endl;
              //cerr << "Latitude : " << lat << ". Longitude : " << lon << endl;
              //cerr << "Dep      : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
index 6ccb5db6017306226df8ca6aab6fc5abad247b3d..b099bd08c20f27cc0a54586174c70492b0139602 100644 (file)
@@ -49,7 +49,7 @@ class FGAISchedule
   double radius;
   double groundOffset;
   double distanceToUser;
-  void* AIManagerRef;
+  int AIManagerRef;
   bool firstRun;
 
 
index b1265bffcea752cce7189f17a0fe5aff387d04c3..1e3b73a2ce8cc034f917e6790edd0e333e164fd9 100644 (file)
@@ -116,12 +116,12 @@ void FGTrafficManager::update(double something)
   currAircraft++;
 }
 
-void FGTrafficManager::release(void *id)
+void FGTrafficManager::release(int id)
 {
   releaseList.push_back(id);
 }
 
-bool FGTrafficManager::isReleased(void *id)
+bool FGTrafficManager::isReleased(int id)
 {
   IdListIterator i = releaseList.begin();
   while (i != releaseList.end())
index 4dd3383f76ff388c14bb734ee3e6c9e06d2fa79d..09f2157697db22af0e37a5aa4166b3d04dc20710 100644 (file)
@@ -34,8 +34,8 @@
 #include "Schedule.hxx"
 
 
-typedef vector<void *> IdList;
-typedef vector<void *>::iterator IdListIterator;
+typedef vector<int> IdList;
+typedef vector<int>::iterator IdListIterator;
 
 
 class FGTrafficManager : public SGSubsystem, public XMLVisitor
@@ -61,8 +61,8 @@ public:
   
   void init();
   void update(double time);
-  void release(void *ref);
-  bool isReleased(void *id);
+  void release(int ref);
+  bool isReleased(int id);
 
   // Some overloaded virtual XMLVisitor members
   virtual void startXML ();