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:
parent
78e6d35998
commit
b7acd97f2c
9 changed files with 64 additions and 112 deletions
|
@ -49,10 +49,7 @@ const FGAIAircraft::PERF_STRUCT FGAIAircraft::settings[] = {
|
|||
};
|
||||
|
||||
|
||||
FGAIAircraft *FGAIAircraft::_self = NULL;
|
||||
|
||||
FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
|
||||
_self = this; // This needs to be the first entry.
|
||||
manager = mgr;
|
||||
_type_str = "aircraft";
|
||||
_otype = otAircraft;
|
||||
|
@ -68,7 +65,6 @@ FGAIAircraft::FGAIAircraft(FGAIManager* mgr) {
|
|||
|
||||
FGAIAircraft::~FGAIAircraft() {
|
||||
if (fp) delete fp;
|
||||
_self = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,10 +75,10 @@ bool FGAIAircraft::init() {
|
|||
void FGAIAircraft::bind() {
|
||||
FGAIBase::bind();
|
||||
|
||||
/*
|
||||
props->tie("controls/gear/gear-down",
|
||||
SGRawValueFunctions<bool>(FGAIAircraft::_getGearDown));
|
||||
|
||||
/*
|
||||
props->getNode("controls/lighting/landing-lights", true)
|
||||
->alias("controls/gear/gear-down");
|
||||
*/
|
||||
|
@ -91,7 +87,7 @@ void FGAIAircraft::bind() {
|
|||
void FGAIAircraft::unbind() {
|
||||
FGAIBase::unbind();
|
||||
|
||||
props->untie("controls/gear/gear-down");
|
||||
// props->untie("controls/gear/gear-down");
|
||||
// props->getNode("controls/lighting/landing-lights")->unalias();
|
||||
}
|
||||
|
||||
|
|
|
@ -69,9 +69,6 @@ public:
|
|||
void ProcessFlightPlan( double dt );
|
||||
//double getHeading(double lat1, double lon1, double lat2, double lon2);
|
||||
|
||||
protected:
|
||||
static FGAIAircraft *_self;
|
||||
|
||||
private:
|
||||
|
||||
bool hdg_lock;
|
||||
|
@ -85,16 +82,7 @@ private:
|
|||
|
||||
void Run(double dt);
|
||||
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
|
||||
|
|
|
@ -43,10 +43,7 @@
|
|||
#include "AIBase.hxx"
|
||||
#include "AIManager.hxx"
|
||||
|
||||
FGAIBase *FGAIBase::_self = NULL;
|
||||
|
||||
FGAIBase::FGAIBase() {
|
||||
_self = this;
|
||||
_type_str = "model";
|
||||
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
|
||||
bearing = elevation = range = rdot = 0.0;
|
||||
|
@ -61,10 +58,9 @@ FGAIBase::FGAIBase() {
|
|||
|
||||
FGAIBase::~FGAIBase() {
|
||||
globals->get_scenery()->get_scene_graph()->removeKid(aip.getSceneGraph());
|
||||
unbind();
|
||||
// unbind();
|
||||
SGPropertyNode *root = globals->get_props()->getNode("ai/models", true);
|
||||
root->removeChild(_type_str.c_str(), index);
|
||||
_self = NULL;
|
||||
}
|
||||
|
||||
void FGAIBase::update(double dt) {
|
||||
|
@ -122,30 +118,30 @@ void FGAIBase::bind() {
|
|||
props->tie("velocities/true-airspeed-kt", SGRawValuePointer<double>(&speed));
|
||||
props->tie("velocities/vertical-speed-fps",
|
||||
SGRawValueFunctions<double>(FGAIBase::_getVS_fps,
|
||||
FGAIBase::_setVS_fps));
|
||||
FGAIBase::_setVS_fps, this));
|
||||
|
||||
props->tie("position/altitude-ft",
|
||||
SGRawValueFunctions<double>(FGAIBase::_getAltitude,
|
||||
FGAIBase::_setAltitude));
|
||||
FGAIBase::_setAltitude, this));
|
||||
props->tie("position/latitude-deg",
|
||||
SGRawValueFunctions<double>(FGAIBase::_getLatitude,
|
||||
FGAIBase::_setLatitude));
|
||||
FGAIBase::_setLatitude, this));
|
||||
props->tie("position/longitude-deg",
|
||||
SGRawValueFunctions<double>(FGAIBase::_getLongitude,
|
||||
FGAIBase::_setLongitude));
|
||||
FGAIBase::_setLongitude, this));
|
||||
|
||||
props->tie("orientation/pitch-deg", SGRawValuePointer<double>(&pitch));
|
||||
props->tie("orientation/roll-deg", SGRawValuePointer<double>(&roll));
|
||||
props->tie("orientation/true-heading-deg", SGRawValuePointer<double>(&hdg));
|
||||
|
||||
props->tie("radar/bearing-deg", SGRawValueFunctions<double>(FGAIBase::_getBearing));
|
||||
props->tie("radar/elevation-deg", SGRawValueFunctions<double>(FGAIBase::_getElevation));
|
||||
props->tie("radar/range-nm", SGRawValueFunctions<double>(FGAIBase::_getRange));
|
||||
props->tie("radar/h-offset", SGRawValueFunctions<double>(FGAIBase::_getH_offset));
|
||||
props->tie("radar/v-offset", SGRawValueFunctions<double>(FGAIBase::_getV_offset));
|
||||
props->tie("radar/x-shift", SGRawValueFunctions<double>(FGAIBase::_getX_shift));
|
||||
props->tie("radar/y-shift", SGRawValueFunctions<double>(FGAIBase::_getY_shift));
|
||||
props->tie("radar/rotation", SGRawValueFunctions<double>(FGAIBase::_getRotation));
|
||||
props->tie("radar/bearing-deg", SGRawValuePointer<double>(&bearing));
|
||||
props->tie("radar/elevation-deg", SGRawValuePointer<double>(&elevation));
|
||||
props->tie("radar/range-nm", SGRawValuePointer<double>(&range));
|
||||
props->tie("radar/h-offset", SGRawValuePointer<double>(&horiz_offset));
|
||||
props->tie("radar/v-offset", SGRawValuePointer<double>(&vert_offset));
|
||||
props->tie("radar/x-shift", SGRawValuePointer<double>(&x_shift));
|
||||
props->tie("radar/y-shift", SGRawValuePointer<double>(&y_shift));
|
||||
props->tie("radar/rotation", SGRawValuePointer<double>(&rotation));
|
||||
|
||||
props->tie("controls/lighting/nav-lights",
|
||||
SGRawValueFunctions<bool>(FGAIBase::_isNight));
|
||||
|
@ -182,59 +178,43 @@ void FGAIBase::unbind() {
|
|||
/*
|
||||
* getters and Setters
|
||||
*/
|
||||
void FGAIBase::_setLongitude( double longitude ) {
|
||||
if (_self) _self->pos.setlon(longitude);
|
||||
void FGAIBase::_setLongitude( double longitude, void *p ) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
self->pos.setlon(longitude);
|
||||
}
|
||||
void FGAIBase::_setLatitude ( double latitude ) {
|
||||
if (_self) _self->pos.setlat(latitude);
|
||||
void FGAIBase::_setLatitude ( double latitude, void *p ) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
self->pos.setlat(latitude);
|
||||
}
|
||||
|
||||
double FGAIBase::_getLongitude() {
|
||||
return (!_self) ? 0.0 :_self->pos.lon();
|
||||
double FGAIBase::_getLongitude(void *p) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
return self->pos.lon();
|
||||
}
|
||||
double FGAIBase::_getLatitude () {
|
||||
return (!_self) ? 0.0 :_self->pos.lat();
|
||||
double FGAIBase::_getLatitude (void *p) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
return self->pos.lat();
|
||||
}
|
||||
double FGAIBase::_getBearing() {
|
||||
return (!_self) ? 0.0 :_self->bearing;
|
||||
double FGAIBase::_getRdot(void *p) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
return self->rdot;
|
||||
}
|
||||
double FGAIBase::_getElevation() {
|
||||
return (!_self) ? 0.0 :_self->elevation;
|
||||
double FGAIBase::_getVS_fps(void *p) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
return self->vs*60.0;
|
||||
}
|
||||
double FGAIBase::_getRange() {
|
||||
return (!_self) ? 0.0 :_self->range;
|
||||
}
|
||||
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;
|
||||
void FGAIBase::_setVS_fps( double _vs, void *p ) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
self->vs = _vs/60.0;
|
||||
}
|
||||
|
||||
double FGAIBase::_getVS_fps() {
|
||||
return (!_self) ? 0.0 :_self->vs*60.0;
|
||||
double FGAIBase::_getAltitude(void *p) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
return self->altitude;
|
||||
}
|
||||
void FGAIBase::_setVS_fps( double _vs ) {
|
||||
if (_self) _self->vs = _vs/60.0;
|
||||
}
|
||||
|
||||
double FGAIBase::_getAltitude() {
|
||||
return (!_self) ? 0.0 :_self->altitude;
|
||||
}
|
||||
void FGAIBase::_setAltitude( double _alt ) {
|
||||
if (_self) _self->setAltitude( _alt );
|
||||
void FGAIBase::_setAltitude( double _alt, void *p ) {
|
||||
FGAIBase *self = (FGAIBase *)p;
|
||||
self->setAltitude( _alt );
|
||||
}
|
||||
|
||||
bool FGAIBase::_isNight() {
|
||||
|
|
|
@ -48,8 +48,6 @@ public:
|
|||
virtual void bind();
|
||||
virtual void unbind();
|
||||
|
||||
inline bool isValid() { return (_self != 0); }
|
||||
|
||||
void setPath( const char* model );
|
||||
void setSpeed( double speed_KTAS );
|
||||
void setAltitude( double altitude_ft );
|
||||
|
@ -108,7 +106,6 @@ protected:
|
|||
|
||||
void Transform();
|
||||
|
||||
static FGAIBase *_self;
|
||||
string _type_str;
|
||||
object_type _otype;
|
||||
int index;
|
||||
|
@ -118,29 +115,32 @@ public:
|
|||
object_type getType();
|
||||
bool isa( object_type otype );
|
||||
|
||||
static double _getVS_fps();
|
||||
static void _setVS_fps( double _vs );
|
||||
static double _getVS_fps(void *p);
|
||||
static void _setVS_fps( double _vs, void *p );
|
||||
|
||||
static double _getAltitude();
|
||||
static void _setAltitude( double _alt );
|
||||
static double _getAltitude(void *p);
|
||||
static void _setAltitude( double _alt, void *p );
|
||||
|
||||
static void _setLongitude( double longitude );
|
||||
static void _setLatitude ( double latitude );
|
||||
static void _setLongitude( double longitude, void *p );
|
||||
static void _setLatitude ( double latitude, void *p );
|
||||
|
||||
static double _getLongitude();
|
||||
static double _getLatitude ();
|
||||
static double _getLongitude(void *p);
|
||||
static double _getLatitude (void *p);
|
||||
|
||||
static double _getBearing();
|
||||
static double _getElevation();
|
||||
static double _getRange();
|
||||
static double _getRdot();
|
||||
static double _getH_offset();
|
||||
static double _getV_offset();
|
||||
static double _getX_shift();
|
||||
static double _getY_shift();
|
||||
static double _getRotation();
|
||||
static double _getBearing(void *p);
|
||||
static double _getElevation(void *p);
|
||||
inline double _getRange() { return range; };
|
||||
static double _getRdot(void *p);
|
||||
static double _getH_offset(void *p);
|
||||
static double _getV_offset(void *p);
|
||||
static double _getX_shift(void *p);
|
||||
static double _getY_shift(void *p);
|
||||
static double _getRotation(void *p);
|
||||
|
||||
static bool _isNight();
|
||||
|
||||
private:
|
||||
FGAIBase *self;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -217,6 +217,7 @@ int FGAIManager::createAircraft( string model_class, string path,
|
|||
double heading, double speed, double pitch, double roll ) {
|
||||
|
||||
FGAIAircraft* ai_plane = new FGAIAircraft(this);
|
||||
cout << "ai_plane: " << ai_plane << endl;
|
||||
ai_list.push_back(ai_plane);
|
||||
ai_plane->setID( assignID() );
|
||||
++numObjects;
|
||||
|
@ -248,6 +249,7 @@ int FGAIManager::createAircraft( string model_class, string path,
|
|||
FGAIFlightPlan* flightplan ) {
|
||||
|
||||
FGAIAircraft* ai_plane = new FGAIAircraft(this);
|
||||
cout << "ai_plane1: " << ai_plane << endl;
|
||||
ai_list.push_back(ai_plane);
|
||||
ai_plane->setID( assignID() );
|
||||
++numObjects;
|
||||
|
|
|
@ -34,18 +34,14 @@ SG_USING_STD(string);
|
|||
#include "AIStorm.hxx"
|
||||
|
||||
|
||||
FGAIStorm *FGAIStorm::_self = NULL;
|
||||
|
||||
FGAIStorm::FGAIStorm(FGAIManager* mgr) {
|
||||
manager = mgr;
|
||||
_self = this;
|
||||
_type_str = "thunderstorm";
|
||||
_otype = otStorm;
|
||||
}
|
||||
|
||||
|
||||
FGAIStorm::~FGAIStorm() {
|
||||
_self = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,9 +40,6 @@ public:
|
|||
virtual void unbind();
|
||||
void update(double dt);
|
||||
|
||||
protected:
|
||||
static FGAIStorm *_self;
|
||||
|
||||
private:
|
||||
|
||||
double dt;
|
||||
|
|
|
@ -34,11 +34,8 @@ SG_USING_STD(string);
|
|||
#include "AIThermal.hxx"
|
||||
|
||||
|
||||
FGAIThermal *FGAIThermal::_self = NULL;
|
||||
|
||||
FGAIThermal::FGAIThermal(FGAIManager* mgr) {
|
||||
manager = mgr;
|
||||
_self = this;
|
||||
_type_str = "thermal";
|
||||
_otype = otThermal;
|
||||
max_strength = 6.0;
|
||||
|
@ -48,7 +45,6 @@ FGAIThermal::FGAIThermal(FGAIManager* mgr) {
|
|||
|
||||
|
||||
FGAIThermal::~FGAIThermal() {
|
||||
_self = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -45,9 +45,6 @@ public:
|
|||
inline double getStrength() const { return strength; };
|
||||
inline double getDiameter() const { return diameter; };
|
||||
|
||||
protected:
|
||||
static FGAIThermal *_self;
|
||||
|
||||
private:
|
||||
|
||||
double dt;
|
||||
|
|
Loading…
Reference in a new issue