From 5c0dbf7b6510dd5abdef8478f89ed2469b190d93 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 15 Oct 2005 14:55:51 +0000 Subject: [PATCH] Don't use the this pointer for referencing the AIModels anymore, this turns out to get problematic on 64-bit systems. Instead use a regular int based approach. --- src/AIModel/AIBase.cxx | 17 ++++++++++++----- src/AIModel/AIBase.hxx | 12 +++++++----- src/AIModel/AIManager.cxx | 2 +- src/AIModel/AIManager.hxx | 2 +- src/Traffic/Schedule.cxx | 3 ++- src/Traffic/Schedule.hxx | 2 +- src/Traffic/TrafficMgr.cxx | 4 ++-- src/Traffic/TrafficMgr.hxx | 8 ++++---- 8 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index db006f9b3..7560ff049 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -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(*this, - &FGAIBase::_getID)); + &FGAIBase::getID)); props->tie("velocities/true-airspeed-kt", SGRawValuePointer(&speed)); props->tie("velocities/vertical-speed-fps", SGRawValueMethods(*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; +} + diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 5def20200..4f1713059 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -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 diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index be872c4a1..96742864e 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -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) { diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index 2ecdbef1c..86eaab9a1 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -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; } diff --git a/src/Traffic/Schedule.cxx b/src/Traffic/Schedule.cxx index 819fa1bed..6af4287f1 100644 --- a/src/Traffic/Schedule.cxx +++ b/src/Traffic/Schedule.cxx @@ -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; diff --git a/src/Traffic/Schedule.hxx b/src/Traffic/Schedule.hxx index 6ccb5db60..b099bd08c 100644 --- a/src/Traffic/Schedule.hxx +++ b/src/Traffic/Schedule.hxx @@ -49,7 +49,7 @@ class FGAISchedule double radius; double groundOffset; double distanceToUser; - void* AIManagerRef; + int AIManagerRef; bool firstRun; diff --git a/src/Traffic/TrafficMgr.cxx b/src/Traffic/TrafficMgr.cxx index b1265bffc..1e3b73a2c 100644 --- a/src/Traffic/TrafficMgr.cxx +++ b/src/Traffic/TrafficMgr.cxx @@ -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()) diff --git a/src/Traffic/TrafficMgr.hxx b/src/Traffic/TrafficMgr.hxx index 4dd3383f7..09f215769 100644 --- a/src/Traffic/TrafficMgr.hxx +++ b/src/Traffic/TrafficMgr.hxx @@ -34,8 +34,8 @@ #include "Schedule.hxx" -typedef vector IdList; -typedef vector::iterator IdListIterator; +typedef vector IdList; +typedef vector::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 ();