1
0
Fork 0

Add the this pointer to the tied function calls. This makes it possible to make a distinction between the different aircraft models.

This commit is contained in:
ehofman 2004-05-27 13:16:53 +00:00
parent 78e6d35998
commit b7acd97f2c
9 changed files with 64 additions and 112 deletions

View file

@ -49,10 +49,7 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
}; };
FGAIAircraft *FGAIAircraft::_self = NULL;
FGAIAircraft::FGAIAircraft(FGAIManager* mgr) { FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
_self = this; // This needs to be the first entry.
manager = mgr; manager = mgr;
_type_str = "aircraft"; _type_str = "aircraft";
_otype = otAircraft; _otype = otAircraft;
@ -68,7 +65,6 @@ FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
FGAIAircraft::~FGAIAircraft() { FGAIAircraft::~FGAIAircraft() {
if (fp) delete fp; if (fp) delete fp;
_self = NULL;
} }
@ -79,10 +75,10 @@ bool FGAIAircraft::init() {
void FGAIAircraft::bind() { void FGAIAircraft::bind() {
FGAIBase::bind(); FGAIBase::bind();
/*
props->tie("controls/gear/gear-down", props->tie("controls/gear/gear-down",
SGRawValueFunctions<bool>(FGAIAircraft::_getGearDown)); SGRawValueFunctions<bool>(FGAIAircraft::_getGearDown));
/*
props->getNode("controls/lighting/landing-lights", true) props->getNode("controls/lighting/landing-lights", true)
->alias("controls/gear/gear-down"); ->alias("controls/gear/gear-down");
*/ */
@ -91,7 +87,7 @@ void FGAIAircraft::bind() {
void FGAIAircraft::unbind() { void FGAIAircraft::unbind() {
FGAIBase::unbind(); FGAIBase::unbind();
props->untie("controls/gear/gear-down"); // props->untie("controls/gear/gear-down");
// props->getNode("controls/lighting/landing-lights")->unalias(); // props->getNode("controls/lighting/landing-lights")->unalias();
} }

View file

@ -69,9 +69,6 @@ public:
void ProcessFlightPlan( double dt ); void ProcessFlightPlan( double dt );
//double getHeading(double lat1, double lon1, double lat2, double lon2); //double getHeading(double lat1, double lon1, double lat2, double lon2);
protected:
static FGAIAircraft *_self;
private: private:
bool hdg_lock; bool hdg_lock;
@ -85,16 +82,7 @@ private:
void Run(double dt); void Run(double dt);
double sign(double x); double sign(double x);
static bool _getGearDown();
}; };
inline bool FGAIAircraft::_getGearDown() {
return (!_self) ? false
: ((fgGetFloat("/position/altitude-agl-ft") < 150.0)
&& (fgGetFloat("/velocities/airspeed-kt")
< _self->performance->land_speed*1.5));
}
#endif // _FG_AIAircraft_HXX #endif // _FG_AIAircraft_HXX

View file

@ -43,10 +43,7 @@
#include "AIBase.hxx" #include "AIBase.hxx"
#include "AIManager.hxx" #include "AIManager.hxx"
FGAIBase *FGAIBase::_self = NULL;
FGAIBase::FGAIBase() { FGAIBase::FGAIBase() {
_self = this;
_type_str = "model"; _type_str = "model";
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0; tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
bearing = elevation = range = rdot = 0.0; bearing = elevation = range = rdot = 0.0;
@ -61,10 +58,9 @@ FGAIBase::FGAIBase() {
FGAIBase::~FGAIBase() { FGAIBase::~FGAIBase() {
globals->get_scenery()->get_scene_graph()->removeKid(aip.getSceneGraph()); globals->get_scenery()->get_scene_graph()->removeKid(aip.getSceneGraph());
unbind(); // unbind();
SGPropertyNode *root = globals->get_props()->getNode("ai/models", true); SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
root->removeChild(_type_str.c_str(), index); root->removeChild(_type_str.c_str(), index);
_self = NULL;
} }
void FGAIBase::update(double dt) { void FGAIBase::update(double dt) {
@ -122,30 +118,30 @@ void FGAIBase::bind() {
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",
SGRawValueFunctions<double>(FGAIBase::_getVS_fps, SGRawValueFunctions<double>(FGAIBase::_getVS_fps,
FGAIBase::_setVS_fps)); FGAIBase::_setVS_fps, this));
props->tie("position/altitude-ft", props->tie("position/altitude-ft",
SGRawValueFunctions<double>(FGAIBase::_getAltitude, SGRawValueFunctions<double>(FGAIBase::_getAltitude,
FGAIBase::_setAltitude)); FGAIBase::_setAltitude, this));
props->tie("position/latitude-deg", props->tie("position/latitude-deg",
SGRawValueFunctions<double>(FGAIBase::_getLatitude, SGRawValueFunctions<double>(FGAIBase::_getLatitude,
FGAIBase::_setLatitude)); FGAIBase::_setLatitude, this));
props->tie("position/longitude-deg", props->tie("position/longitude-deg",
SGRawValueFunctions<double>(FGAIBase::_getLongitude, SGRawValueFunctions<double>(FGAIBase::_getLongitude,
FGAIBase::_setLongitude)); FGAIBase::_setLongitude, this));
props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch)); props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll)); props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg)); props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
props->tie("radar/bearing-deg", SGRawValueFunctions<double>(FGAIBase::_getBearing)); props->tie("radar/bearing-deg", SGRawValuePointer<double>(&bearing));
props->tie("radar/elevation-deg", SGRawValueFunctions<double>(FGAIBase::_getElevation)); props->tie("radar/elevation-deg", SGRawValuePointer<double>(&elevation));
props->tie("radar/range-nm", SGRawValueFunctions<double>(FGAIBase::_getRange)); props->tie("radar/range-nm", SGRawValuePointer<double>(&range));
props->tie("radar/h-offset", SGRawValueFunctions<double>(FGAIBase::_getH_offset)); props->tie("radar/h-offset", SGRawValuePointer<double>(&horiz_offset));
props->tie("radar/v-offset", SGRawValueFunctions<double>(FGAIBase::_getV_offset)); props->tie("radar/v-offset", SGRawValuePointer<double>(&vert_offset));
props->tie("radar/x-shift", SGRawValueFunctions<double>(FGAIBase::_getX_shift)); props->tie("radar/x-shift", SGRawValuePointer<double>(&x_shift));
props->tie("radar/y-shift", SGRawValueFunctions<double>(FGAIBase::_getY_shift)); props->tie("radar/y-shift", SGRawValuePointer<double>(&y_shift));
props->tie("radar/rotation", SGRawValueFunctions<double>(FGAIBase::_getRotation)); props->tie("radar/rotation", SGRawValuePointer<double>(&rotation));
props->tie("controls/lighting/nav-lights", props->tie("controls/lighting/nav-lights",
SGRawValueFunctions<bool>(FGAIBase::_isNight)); SGRawValueFunctions<bool>(FGAIBase::_isNight));
@ -182,59 +178,43 @@ void FGAIBase::unbind() {
/* /*
* getters and Setters * getters and Setters
*/ */
void FGAIBase::_setLongitude( double longitude ) { void FGAIBase::_setLongitude( double longitude, void *p ) {
if (_self) _self->pos.setlon(longitude); FGAIBase *self = (FGAIBase *)p;
self->pos.setlon(longitude);
} }
void FGAIBase::_setLatitude ( double latitude ) { void FGAIBase::_setLatitude ( double latitude, void *p ) {
if (_self) _self->pos.setlat(latitude); FGAIBase *self = (FGAIBase *)p;
self->pos.setlat(latitude);
} }
double FGAIBase::_getLongitude() { double FGAIBase::_getLongitude(void *p) {
return (!_self) ? 0.0 :_self->pos.lon(); FGAIBase *self = (FGAIBase *)p;
return self->pos.lon();
} }
double FGAIBase::_getLatitude () { double FGAIBase::_getLatitude (void *p) {
return (!_self) ? 0.0 :_self->pos.lat(); FGAIBase *self = (FGAIBase *)p;
return self->pos.lat();
} }
double FGAIBase::_getBearing() { double FGAIBase::_getRdot(void *p) {
return (!_self) ? 0.0 :_self->bearing; FGAIBase *self = (FGAIBase *)p;
return self->rdot;
} }
double FGAIBase::_getElevation() { double FGAIBase::_getVS_fps(void *p) {
return (!_self) ? 0.0 :_self->elevation; FGAIBase *self = (FGAIBase *)p;
return self->vs*60.0;
} }
double FGAIBase::_getRange() { void FGAIBase::_setVS_fps( double _vs, void *p ) {
return (!_self) ? 0.0 :_self->range; FGAIBase *self = (FGAIBase *)p;
} self->vs = _vs/60.0;
double FGAIBase::_getRdot() {
return (!_self) ? 0.0 :_self->rdot;
}
double FGAIBase::_getH_offset() {
return (!_self) ? 0.0 :_self->horiz_offset;
}
double FGAIBase::_getV_offset() {
return (!_self) ? 0.0 :_self->vert_offset;
}
double FGAIBase::_getX_shift() {
return (!_self) ? 0.0 :_self->x_shift;
}
double FGAIBase::_getY_shift() {
return (!_self) ? 0.0 :_self->y_shift;
}
double FGAIBase::_getRotation() {
return (!_self) ? 0.0 :_self->rotation;
} }
double FGAIBase::_getVS_fps() { double FGAIBase::_getAltitude(void *p) {
return (!_self) ? 0.0 :_self->vs*60.0; FGAIBase *self = (FGAIBase *)p;
return self->altitude;
} }
void FGAIBase::_setVS_fps( double _vs ) { void FGAIBase::_setAltitude( double _alt, void *p ) {
if (_self) _self->vs = _vs/60.0; FGAIBase *self = (FGAIBase *)p;
} self->setAltitude( _alt );
double FGAIBase::_getAltitude() {
return (!_self) ? 0.0 :_self->altitude;
}
void FGAIBase::_setAltitude( double _alt ) {
if (_self) _self->setAltitude( _alt );
} }
bool FGAIBase::_isNight() { bool FGAIBase::_isNight() {

View file

@ -48,8 +48,6 @@ public:
virtual void bind(); virtual void bind();
virtual void unbind(); virtual void unbind();
inline bool isValid() { return (_self != 0); }
void setPath( const char* model ); void setPath( const char* model );
void setSpeed( double speed_KTAS ); void setSpeed( double speed_KTAS );
void setAltitude( double altitude_ft ); void setAltitude( double altitude_ft );
@ -108,7 +106,6 @@ protected:
void Transform(); void Transform();
static FGAIBase *_self;
string _type_str; string _type_str;
object_type _otype; object_type _otype;
int index; int index;
@ -118,29 +115,32 @@ public:
object_type getType(); object_type getType();
bool isa( object_type otype ); bool isa( object_type otype );
static double _getVS_fps(); static double _getVS_fps(void *p);
static void _setVS_fps( double _vs ); static void _setVS_fps( double _vs, void *p );
static double _getAltitude(); static double _getAltitude(void *p);
static void _setAltitude( double _alt ); static void _setAltitude( double _alt, void *p );
static void _setLongitude( double longitude ); static void _setLongitude( double longitude, void *p );
static void _setLatitude ( double latitude ); static void _setLatitude ( double latitude, void *p );
static double _getLongitude(); static double _getLongitude(void *p);
static double _getLatitude (); static double _getLatitude (void *p);
static double _getBearing(); static double _getBearing(void *p);
static double _getElevation(); static double _getElevation(void *p);
static double _getRange(); inline double _getRange() { return range; };
static double _getRdot(); static double _getRdot(void *p);
static double _getH_offset(); static double _getH_offset(void *p);
static double _getV_offset(); static double _getV_offset(void *p);
static double _getX_shift(); static double _getX_shift(void *p);
static double _getY_shift(); static double _getY_shift(void *p);
static double _getRotation(); static double _getRotation(void *p);
static bool _isNight(); static bool _isNight();
private:
FGAIBase *self;
}; };

View file

@ -217,6 +217,7 @@ int FGAIManager::createAircraft( string model_class, string path,
double heading, double speed, double pitch, double roll ) { double heading, double speed, double pitch, double roll ) {
FGAIAircraft* ai_plane = new FGAIAircraft(this); FGAIAircraft* ai_plane = new FGAIAircraft(this);
cout << "ai_plane: " << ai_plane << endl;
ai_list.push_back(ai_plane); ai_list.push_back(ai_plane);
ai_plane->setID( assignID() ); ai_plane->setID( assignID() );
++numObjects; ++numObjects;
@ -248,6 +249,7 @@ int FGAIManager::createAircraft( string model_class, string path,
FGAIFlightPlan* flightplan ) { FGAIFlightPlan* flightplan ) {
FGAIAircraft* ai_plane = new FGAIAircraft(this); FGAIAircraft* ai_plane = new FGAIAircraft(this);
cout << "ai_plane1: " << ai_plane << endl;
ai_list.push_back(ai_plane); ai_list.push_back(ai_plane);
ai_plane->setID( assignID() ); ai_plane->setID( assignID() );
++numObjects; ++numObjects;

View file

@ -34,18 +34,14 @@ SG_USING_STD(string);
#include "AIStorm.hxx" #include "AIStorm.hxx"
FGAIStorm *FGAIStorm::_self = NULL;
FGAIStorm::FGAIStorm(FGAIManager* mgr) { FGAIStorm::FGAIStorm(FGAIManager* mgr) {
manager = mgr; manager = mgr;
_self = this;
_type_str = "thunderstorm"; _type_str = "thunderstorm";
_otype = otStorm; _otype = otStorm;
} }
FGAIStorm::~FGAIStorm() { FGAIStorm::~FGAIStorm() {
_self = NULL;
} }

View file

@ -40,9 +40,6 @@ public:
virtual void unbind(); virtual void unbind();
void update(double dt); void update(double dt);
protected:
static FGAIStorm *_self;
private: private:
double dt; double dt;

View file

@ -34,11 +34,8 @@ SG_USING_STD(string);
#include "AIThermal.hxx" #include "AIThermal.hxx"
FGAIThermal *FGAIThermal::_self = NULL;
FGAIThermal::FGAIThermal(FGAIManager* mgr) { FGAIThermal::FGAIThermal(FGAIManager* mgr) {
manager = mgr; manager = mgr;
_self = this;
_type_str = "thermal"; _type_str = "thermal";
_otype = otThermal; _otype = otThermal;
max_strength = 6.0; max_strength = 6.0;
@ -48,7 +45,6 @@ FGAIThermal::FGAIThermal(FGAIManager* mgr) {
FGAIThermal::~FGAIThermal() { FGAIThermal::~FGAIThermal() {
_self = NULL;
} }

View file

@ -45,9 +45,6 @@ public:
inline double getStrength() const { return strength; }; inline double getStrength() const { return strength; };
inline double getDiameter() const { return diameter; }; inline double getDiameter() const { return diameter; };
protected:
static FGAIThermal *_self;
private: private:
double dt; double dt;