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.
This commit is contained in:
parent
54a33c3899
commit
5c0dbf7b65
8 changed files with 30 additions and 20 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -49,7 +49,7 @@ class FGAISchedule
|
|||
double radius;
|
||||
double groundOffset;
|
||||
double distanceToUser;
|
||||
void* AIManagerRef;
|
||||
int AIManagerRef;
|
||||
bool firstRun;
|
||||
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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 ();
|
||||
|
|
Loading…
Reference in a new issue