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
|
@ -53,7 +53,8 @@ FGAIBase::FGAIBase()
|
||||||
: fp( NULL ),
|
: fp( NULL ),
|
||||||
model( NULL ),
|
model( NULL ),
|
||||||
props( NULL ),
|
props( NULL ),
|
||||||
manager( NULL )
|
manager( NULL ),
|
||||||
|
_refID( _newAIModelID() )
|
||||||
{
|
{
|
||||||
_type_str = "model";
|
_type_str = "model";
|
||||||
tgt_heading = tgt_altitude = tgt_speed = 0.0;
|
tgt_heading = tgt_altitude = tgt_speed = 0.0;
|
||||||
|
@ -179,7 +180,7 @@ bool FGAIBase::isa( object_type otype ) {
|
||||||
|
|
||||||
void FGAIBase::bind() {
|
void FGAIBase::bind() {
|
||||||
props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
|
props->tie("id", SGRawValueMethods<FGAIBase,int>(*this,
|
||||||
&FGAIBase::_getID));
|
&FGAIBase::getID));
|
||||||
props->tie("velocities/true-airspeed-kt", SGRawValuePointer<double>(&speed));
|
props->tie("velocities/true-airspeed-kt", SGRawValuePointer<double>(&speed));
|
||||||
props->tie("velocities/vertical-speed-fps",
|
props->tie("velocities/vertical-speed-fps",
|
||||||
SGRawValueMethods<FGAIBase,double>(*this,
|
SGRawValueMethods<FGAIBase,double>(*this,
|
||||||
|
@ -399,8 +400,8 @@ bool FGAIBase::_isNight() {
|
||||||
return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
|
return (fgGetFloat("/sim/time/sun-angle-rad") > 1.57);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FGAIBase::_getID() const {
|
int FGAIBase::getID() const {
|
||||||
return (int)(this);
|
return _refID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIBase::CalculateMach() {
|
void FGAIBase::CalculateMach() {
|
||||||
|
@ -438,3 +439,9 @@ void FGAIBase::CalculateMach() {
|
||||||
// cout << "Speed(ft/s) "<< speed <<" Altitude(ft) "<< altitude << " Mach " << Mach;
|
// 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 FGAIManager;
|
||||||
class FGAIFlightPlan;
|
class FGAIFlightPlan;
|
||||||
|
|
||||||
|
|
||||||
struct ParkPosition {
|
struct ParkPosition {
|
||||||
ParkPosition(const ParkPosition& pp)
|
ParkPosition(const ParkPosition& pp)
|
||||||
: name(pp.name), offset(pp.offset), heading_deg(pp.heading_deg)
|
: name(pp.name), offset(pp.offset), heading_deg(pp.heading_deg)
|
||||||
|
@ -129,8 +130,8 @@ public:
|
||||||
void setYoffset( double y_offset );
|
void setYoffset( double y_offset );
|
||||||
void setZoffset( double z_offset );
|
void setZoffset( double z_offset );
|
||||||
|
|
||||||
|
int getID() const;
|
||||||
|
|
||||||
void* getID();
|
|
||||||
void setDie( bool die );
|
void setDie( bool die );
|
||||||
bool getDie();
|
bool getDie();
|
||||||
|
|
||||||
|
@ -194,6 +195,11 @@ protected:
|
||||||
object_type _otype;
|
object_type _otype;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
static int _newAIModelID();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int _refID;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
object_type getType();
|
object_type getType();
|
||||||
|
@ -229,8 +235,6 @@ public:
|
||||||
static const double e;
|
static const double e;
|
||||||
static const double lbs_to_slugs;
|
static const double lbs_to_slugs;
|
||||||
|
|
||||||
int _getID() const;
|
|
||||||
|
|
||||||
inline double _getRange() { return range; };
|
inline double _getRange() { return range; };
|
||||||
ssgBranch * load3DModel(const string& fg_root,
|
ssgBranch * load3DModel(const string& fg_root,
|
||||||
const string &path,
|
const string &path,
|
||||||
|
@ -279,8 +283,6 @@ inline bool FGAIBase::getDie() { return delete_me; }
|
||||||
|
|
||||||
inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
|
inline FGAIBase::object_type FGAIBase::getType() { return _otype; }
|
||||||
|
|
||||||
inline void* FGAIBase::getID() { return this; }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _FG_AIBASE_HXX
|
#endif // _FG_AIBASE_HXX
|
||||||
|
|
|
@ -352,7 +352,7 @@ FGAIManager::createStatic( FGAIModelEntity *entity ) {
|
||||||
return ai_static;
|
return ai_static;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIManager::destroyObject( void* ID ) {
|
void FGAIManager::destroyObject( int ID ) {
|
||||||
ai_list_iterator ai_list_itr = ai_list.begin();
|
ai_list_iterator ai_list_itr = ai_list.begin();
|
||||||
while(ai_list_itr != ai_list.end()) {
|
while(ai_list_itr != ai_list.end()) {
|
||||||
if ((*ai_list_itr)->getID() == ID) {
|
if ((*ai_list_itr)->getID() == ID) {
|
||||||
|
|
|
@ -90,7 +90,7 @@ public:
|
||||||
void* createCarrier( FGAIModelEntity *entity );
|
void* createCarrier( FGAIModelEntity *entity );
|
||||||
void* createStatic( 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_latitude() { return user_latitude; }
|
||||||
inline double get_user_longitude() { return user_longitude; }
|
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
|
// Fixme: A non-existent model path results in an
|
||||||
// abort, due to an unhandled exeption, in fg main loop.
|
// 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 << "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 << "Latitude : " << lat << ". Longitude : " << lon << endl;
|
||||||
//cerr << "Dep : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
|
//cerr << "Dep : " << dep->getLatitude()<< ", "<< dep->getLongitude() << endl;
|
||||||
|
|
|
@ -49,7 +49,7 @@ class FGAISchedule
|
||||||
double radius;
|
double radius;
|
||||||
double groundOffset;
|
double groundOffset;
|
||||||
double distanceToUser;
|
double distanceToUser;
|
||||||
void* AIManagerRef;
|
int AIManagerRef;
|
||||||
bool firstRun;
|
bool firstRun;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -116,12 +116,12 @@ void FGTrafficManager::update(double something)
|
||||||
currAircraft++;
|
currAircraft++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGTrafficManager::release(void *id)
|
void FGTrafficManager::release(int id)
|
||||||
{
|
{
|
||||||
releaseList.push_back(id);
|
releaseList.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FGTrafficManager::isReleased(void *id)
|
bool FGTrafficManager::isReleased(int id)
|
||||||
{
|
{
|
||||||
IdListIterator i = releaseList.begin();
|
IdListIterator i = releaseList.begin();
|
||||||
while (i != releaseList.end())
|
while (i != releaseList.end())
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
#include "Schedule.hxx"
|
#include "Schedule.hxx"
|
||||||
|
|
||||||
|
|
||||||
typedef vector<void *> IdList;
|
typedef vector<int> IdList;
|
||||||
typedef vector<void *>::iterator IdListIterator;
|
typedef vector<int>::iterator IdListIterator;
|
||||||
|
|
||||||
|
|
||||||
class FGTrafficManager : public SGSubsystem, public XMLVisitor
|
class FGTrafficManager : public SGSubsystem, public XMLVisitor
|
||||||
|
@ -61,8 +61,8 @@ public:
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void update(double time);
|
void update(double time);
|
||||||
void release(void *ref);
|
void release(int ref);
|
||||||
bool isReleased(void *id);
|
bool isReleased(int id);
|
||||||
|
|
||||||
// Some overloaded virtual XMLVisitor members
|
// Some overloaded virtual XMLVisitor members
|
||||||
virtual void startXML ();
|
virtual void startXML ();
|
||||||
|
|
Loading…
Reference in a new issue