1
0
Fork 0

PerformanceDB improvements.

Support cascading (inheriting) performance data, so common values don't need to be repeated.
This commit is contained in:
James Turner 2012-10-29 10:01:52 +00:00
parent 79f7907a82
commit 7c8ad455a3
3 changed files with 80 additions and 77 deletions

View file

@ -4,8 +4,9 @@
#endif #endif
#include "performancedata.hxx" #include "performancedata.hxx"
#include "AIAircraft.hxx"
#include <simgear/props/props.hxx>
#include "AIAircraft.hxx"
// For now, make this a define // For now, make this a define
// Later on, additional class variables can simulate settings such as braking power // Later on, additional class variables can simulate settings such as braking power
@ -13,42 +14,63 @@
// to the AIAircraft. // to the AIAircraft.
#define BRAKE_SETTING 1.6 #define BRAKE_SETTING 1.6
PerformanceData::PerformanceData(double acceleration, PerformanceData::PerformanceData() :
double deceleration, _acceleration(4.0),
double climbRate, _deceleration(2.0),
double descentRate, _climbRate(3000.0),
double vRotate, _descentRate(1500.0),
double vTakeOff, _vRotate(150.0),
double vClimb, _vTakeOff(160.0),
double vCruise, _vClimb(300.0),
double vDescent, _vCruise(430.0),
double vApproach, _vDescent(300.0),
double vTouchdown, _vApproach(170.0),
double vTaxi) : _vTouchdown(150.0),
_acceleration(acceleration), _vTaxi(15.0)
_deceleration(deceleration),
_climbRate(climbRate),
_descentRate(descentRate),
_vRotate(vRotate),
_vTakeOff(vTakeOff),
_vClimb(vClimb),
_vCruise(vCruise),
_vDescent(vDescent),
_vApproach(vApproach),
_vTouchdown(vTouchdown),
_vTaxi(vTaxi)
{ {
_rollrate = 9.0; // degrees per second _rollrate = 9.0; // degrees per second
_maxbank = 30.0; // passenger friendly bank angle _maxbank = 30.0; // passenger friendly bank angle
} }
// read perf data from file PerformanceData::PerformanceData(PerformanceData* clone) :
PerformanceData::PerformanceData( const std::string& filename) _acceleration(clone->_acceleration),
{} _deceleration(clone->_deceleration),
_climbRate(clone->_climbRate),
_descentRate(clone->_descentRate),
_vRotate(clone->_vRotate),
_vTakeOff(clone->_vTakeOff),
_vClimb(clone->_vClimb),
_vCruise(clone->_vCruise),
_vDescent(clone->_vDescent),
_vApproach(clone->_vApproach),
_vTouchdown(clone->_vTouchdown),
_vTaxi(clone->_vTaxi)
{
_rollrate = clone->_rollrate;
_maxbank = clone->_maxbank;
}
PerformanceData::~PerformanceData() PerformanceData::~PerformanceData()
{} {}
void PerformanceData::initFromProps(SGPropertyNode *db_node)
{
// read the values, using the existing values as defaults
_acceleration = db_node->getDoubleValue("acceleration-kts-hour", _acceleration);
_deceleration = db_node->getDoubleValue("deceleration-kts-hour", _deceleration);
_climbRate = db_node->getDoubleValue("climbrate-fpm", _climbRate);
_descentRate = db_node->getDoubleValue("decentrate-fpm", _descentRate);
_vRotate = db_node->getDoubleValue("rotate-speed-kts", _vRotate);
_vTakeOff = db_node->getDoubleValue("takeoff-speed-kts", _vTakeOff);
_vClimb = db_node->getDoubleValue("climb-speed-kts", _vClimb);
_vCruise = db_node->getDoubleValue("cruise-speed-kts", _vCruise);
_vDescent = db_node->getDoubleValue("decent-speed-kts", _vDescent);
_vApproach = db_node->getDoubleValue("approach-speed-kts", _vApproach);
_vTouchdown = db_node->getDoubleValue("touchdown-speed-kts", _vTouchdown);
_vTaxi = db_node->getDoubleValue("taxi-speed-kts", _vTaxi);
}
double PerformanceData::actualSpeed(FGAIAircraft* ac, double tgt_speed, double dt, bool maxBrakes) { double PerformanceData::actualSpeed(FGAIAircraft* ac, double tgt_speed, double dt, bool maxBrakes) {
// if (tgt_speed > _vTaxi & ac->onGround()) // maximum taxi speed on ground // if (tgt_speed > _vTaxi & ac->onGround()) // maximum taxi speed on ground
// tgt_speed = _vTaxi; // tgt_speed = _vTaxi;

View file

@ -5,6 +5,7 @@
#include <map> #include <map>
class FGAIAircraft; class FGAIAircraft;
class SGPropertyNode;
/** /**
Data storage for aircraft performance data. This is used to properly simulate the flight of AIAircrafts. Data storage for aircraft performance data. This is used to properly simulate the flight of AIAircrafts.
@ -14,19 +15,12 @@ Data storage for aircraft performance data. This is used to properly simulate th
class PerformanceData class PerformanceData
{ {
public: public:
PerformanceData(double acceleration, PerformanceData();
double deceleration,
double climbRate, PerformanceData(PerformanceData* clone);
double descentRate,
double vRotate, void initFromProps(SGPropertyNode* props);
double vTakeOff,
double vClimb,
double vCruise,
double vDescent,
double vApproach,
double vTouchdown,
double vTaxi);
PerformanceData(const std::string& filename);
~PerformanceData(); ~PerformanceData();
double actualSpeed(FGAIAircraft* ac, double tgt_speed, double dt, bool needMaxBrake); double actualSpeed(FGAIAircraft* ac, double tgt_speed, double dt, bool needMaxBrake);

View file

@ -40,10 +40,6 @@ void PerformanceDB::registerPerformanceData(const std::string& id, PerformanceDa
_db[id] = data; _db[id] = data;
} }
void PerformanceDB::registerPerformanceData(const std::string& id, const std::string& filename) {
registerPerformanceData(id, new PerformanceData(filename));
}
PerformanceData* PerformanceDB::getDataFor(const string& acType, const string& acClass) PerformanceData* PerformanceDB::getDataFor(const string& acType, const string& acClass)
{ {
// first, try with the specific aircraft type, such as 738 or A322 // first, try with the specific aircraft type, such as 738 or A322
@ -65,20 +61,8 @@ PerformanceData* PerformanceDB::getDataFor(const string& acType, const string& a
return _db[acClass]; return _db[acClass];
} }
void PerformanceDB::load(const SGPath& filename) { void PerformanceDB::load(const SGPath& filename)
string name; {
double acceleration;
double deceleration;
double climbRate;
double descentRate;
double vRotate;
double vTakeOff;
double vClimb;
double vCruise;
double vDescent;
double vApproach;
double vTouchdown;
double vTaxi;
SGPropertyNode root; SGPropertyNode root;
try { try {
readProperties(filename.str(), &root); readProperties(filename.str(), &root);
@ -92,22 +76,25 @@ void PerformanceDB::load(const SGPath& filename) {
for (int i = 0; i < node->nChildren(); i++) { for (int i = 0; i < node->nChildren(); i++) {
SGPropertyNode * db_node = node->getChild(i); SGPropertyNode * db_node = node->getChild(i);
if (!strcmp(db_node->getName(), "aircraft")) { if (!strcmp(db_node->getName(), "aircraft")) {
name = db_node->getStringValue("type", "heavy_jet"); PerformanceData* data = NULL;
acceleration = db_node->getDoubleValue("acceleration-kts-hour", 4.0); if (db_node->hasChild("base")) {
deceleration = db_node->getDoubleValue("deceleration-kts-hour", 2.0); string baseName = db_node->getStringValue("base");
climbRate = db_node->getDoubleValue("climbrate-fpm", 3000.0); PerformanceData* baseData = _db[baseName];
descentRate = db_node->getDoubleValue("decentrate-fpm", 1500.0); if (!baseData) {
vRotate = db_node->getDoubleValue("rotate-speed-kts", 150.0); SG_LOG(SG_AI, SG_ALERT,
vTakeOff = db_node->getDoubleValue("takeoff-speed-kts", 160.0); "Error reading AI aircraft performance database: unknown base type " << baseName);
vClimb = db_node->getDoubleValue("climb-speed-kts", 300.0); return;
vCruise = db_node->getDoubleValue("cruise-speed-kts", 430.0); }
vDescent = db_node->getDoubleValue("decent-speed-kts", 300.0);
vApproach = db_node->getDoubleValue("approach-speed-kts", 170.0);
vTouchdown = db_node->getDoubleValue("touchdown-speed-kts", 150.0);
vTaxi = db_node->getDoubleValue("taxi-speed-kts", 15.0);
registerPerformanceData(name, new PerformanceData( // clone base data to 'inherit' from it
acceleration, deceleration, climbRate, descentRate, vRotate, vTakeOff, vClimb, vCruise, vDescent, vApproach, vTouchdown, vTaxi)); data = new PerformanceData(baseData);
} else {
data = new PerformanceData;
}
data->initFromProps(db_node);
string name = db_node->getStringValue("type", "heavy_jet");
registerPerformanceData(name, data);
} else if (!strcmp(db_node->getName(), "alias")) { } else if (!strcmp(db_node->getName(), "alias")) {
string alias(db_node->getStringValue("alias")); string alias(db_node->getStringValue("alias"));
if (alias.empty()) { if (alias.empty()) {