needsTaxiClearance = false;
_needsGroundElevation = true;
- _performance = 0; //TODO initialize to JET_TRANSPORT from PerformanceDB
+ PerformanceDB* perfDB = globals->get_subsystem<PerformanceDB>();
+ if (perfDB) {
+ _performance = perfDB->getDefaultPerformance();
+ }
+
dt = 0;
takeOffStatus = 0;
void FGAIAircraft::setPerformance(const std::string& acType, const std::string& acclass)
{
- static PerformanceDB perfdb; //TODO make it a global service
- _performance = perfdb.getDataFor(acType, acclass);
+ PerformanceDB* perfDB = globals->get_subsystem<PerformanceDB>();
+ if (perfDB) {
+ _performance = perfDB->getDataFor(acType, acclass);
+ }
}
#if 0
#include <boost/foreach.hpp>
+#include <simgear/sg_inlines.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
-#include <simgear/xml/easyxml.hxx>
+#include <simgear/structure/exception.hxx>
#include <Main/globals.hxx>
#include <iostream>
PerformanceDB::PerformanceDB()
{
- SGPath dbpath( globals->get_fg_root() );
-
+}
+
+
+PerformanceDB::~PerformanceDB()
+{
+}
+void PerformanceDB::init()
+{
+ SGPath dbpath( globals->get_fg_root() );
dbpath.append( "/AI/Aircraft/" );
- dbpath.append( "performancedb.xml");
+ dbpath.append( "performancedb.xml");
load(dbpath);
+
+ if (getDefaultPerformance() == 0) {
+ SG_LOG(SG_AI, SG_WARN, "PerformanceDB: no default performance data found/loaded");
+ }
}
+void PerformanceDB::shutdown()
+{
+ PerformanceDataDict::iterator it;
+ for (it = _db.begin(); it != _db.end(); ++it) {
+ delete it->second;
+ }
-PerformanceDB::~PerformanceDB()
-{}
+ _db.clear();
+ _aliases.clear();
+}
+
+void PerformanceDB::update(double dt)
+{
+ SG_UNUSED(dt);
+ suspend();
+}
void PerformanceDB::registerPerformanceData(const std::string& id, PerformanceData* data) {
//TODO if key exists already replace data "inplace", i.e. copy to existing PerfData instance
_db[id] = data;
}
-PerformanceData* PerformanceDB::getDataFor(const string& acType, const string& acClass)
+PerformanceData* PerformanceDB::getDataFor(const string& acType, const string& acClass) const
{
// first, try with the specific aircraft type, such as 738 or A322
- if (_db.find(acType) != _db.end()) {
- return _db[acType];
+ PerformanceDataDict::const_iterator it;
+ it = _db.find(acType);
+ if (it != _db.end()) {
+ return it->second;
}
const string& alias = findAlias(acType);
- if (_db.find(alias) != _db.end()) {
- return _db[alias];
+ it = _db.find(alias);
+ if (it != _db.end()) {
+ return it->second;
}
SG_LOG(SG_AI, SG_INFO, "no performance data for " << acType);
-
- if (_db.find(acClass) == _db.end()) {
- return _db["jet_transport"];
+
+ it = _db.find(acClass);
+ if (it == _db.end()) {
+ return getDefaultPerformance();
}
-
- return _db[acClass];
+
+ return it->second;
+}
+
+PerformanceData* PerformanceDB::getDefaultPerformance() const
+{
+ PerformanceDataDict::const_iterator it = _db.find("jet_transport");
+ if (it == _db.end())
+ return NULL;
+
+ return it->second;
+}
+
+bool PerformanceDB::havePerformanceDataForAircraftType(const std::string& acType) const
+{
+ PerformanceDataDict::const_iterator it = _db.find(acType);
+ if (it != _db.end())
+ return true;
+
+ const std::string alias(findAlias(acType));
+ return (_db.find(alias) != _db.end());
}
void PerformanceDB::load(const SGPath& filename)
class PerformanceData;
class SGPath;
+#include <simgear/structure/subsystem_mgr.hxx>
+
/**
* Registry for performance data.
*
* @author Thomas F�rster <t.foerster@biologie.hu-berlin.de>
*/
//TODO provide std::map interface?
-class PerformanceDB
+class PerformanceDB : public SGSubsystem
{
public:
PerformanceDB();
- ~PerformanceDB();
+ virtual ~PerformanceDB();
- void registerPerformanceData(const std::string& id, PerformanceData* data);
- void registerPerformanceData(const std::string& id, const std::string& filename);
+ virtual void init();
+ virtual void shutdown();
+
+ virtual void update(double dt);
+
+ bool havePerformanceDataForAircraftType(const std::string& acType) const;
/**
* get performance data for an aircraft type / class. Type is specific, eg
* '738' or 'A319'. Class is more generic, such as 'jet_transport'.
*/
- PerformanceData* getDataFor(const std::string& acType, const std::string& acClass);
- void load(const SGPath& path);
+ PerformanceData* getDataFor(const std::string& acType, const std::string& acClass) const;
+
+ PerformanceData* getDefaultPerformance() const;
+ static const char* subsystemName() { return "aircraft-performance-db"; }
private:
- std::map<std::string, PerformanceData*> _db;
+ void load(const SGPath& path);
+
+ void registerPerformanceData(const std::string& id, PerformanceData* data);
+
+
+ typedef std::map<std::string, PerformanceData*> PerformanceDataDict;
+ PerformanceDataDict _db;
const std::string& findAlias(const std::string& acType) const;
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/performancedata.hxx>
-#include <AIModel/performancedb.hxx>
#include <ATC/atc_mgr.hxx>
#include <Traffic/TrafficMgr.hxx>
#include <Airports/groundnetwork.hxx>
#include <Model/modelmgr.hxx>
#include <AIModel/submodel.hxx>
#include <AIModel/AIManager.hxx>
+#include <AIModel/performancedb.hxx>
#include <Navaids/navdb.hxx>
#include <Navaids/navlist.hxx>
#include <Scenery/scenery.hxx>
////////////////////////////////////////////////////////////////////
// Initialize the ATC subsystem
////////////////////////////////////////////////////////////////////
+
+ globals->add_new_subsystem<PerformanceDB>(SGSubsystemMgr::POST_FDM);
globals->add_subsystem("ATC", new FGATCManager, SGSubsystemMgr::POST_FDM);
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Initialise the AI Model Manager
////////////////////////////////////////////////////////////////////
- SG_LOG(SG_GENERAL, SG_INFO, " AI Model Manager");
+
globals->add_subsystem("ai-model", new FGAIManager, SGSubsystemMgr::POST_FDM);
globals->add_subsystem("submodel-mgr", new FGSubmodelMgr, SGSubsystemMgr::POST_FDM);