Break upwards dependency on Traffic in the AI code
AIManager had unfortunate code to pass some state to the traffic-manager; this is no longer required since traffic schedules hold onto their AI-Aircraft directly as needed.
This commit is contained in:
parent
77ca03da4d
commit
bca6e9e890
6 changed files with 24 additions and 80 deletions
|
@ -28,9 +28,7 @@
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
|
||||||
#include <Airports/simple.hxx>
|
#include <Airports/simple.hxx>
|
||||||
#include <Traffic/TrafficMgr.hxx>
|
|
||||||
|
|
||||||
#include "AIManager.hxx"
|
#include "AIManager.hxx"
|
||||||
#include "AIAircraft.hxx"
|
#include "AIAircraft.hxx"
|
||||||
|
@ -135,11 +133,6 @@ FGAIManager::unbind() {
|
||||||
|
|
||||||
void FGAIManager::removeDeadItem(FGAIBase* base)
|
void FGAIManager::removeDeadItem(FGAIBase* base)
|
||||||
{
|
{
|
||||||
FGTrafficManager *tmgr = (FGTrafficManager*) globals->get_subsystem("traffic-manager");
|
|
||||||
if (tmgr) {
|
|
||||||
tmgr->release(base->getID());
|
|
||||||
}
|
|
||||||
|
|
||||||
SGPropertyNode *props = base->_getProps();
|
SGPropertyNode *props = base->_getProps();
|
||||||
|
|
||||||
props->setBoolValue("valid", false);
|
props->setBoolValue("valid", false);
|
||||||
|
@ -227,21 +220,6 @@ FGAIManager::attach(FGAIBase *model)
|
||||||
p->setBoolValue("valid", true);
|
p->setBoolValue("valid", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
FGAIManager::destroyObject( int ID ) {
|
|
||||||
ai_list_iterator ai_list_itr = ai_list.begin();
|
|
||||||
|
|
||||||
while(ai_list_itr != ai_list.end()) {
|
|
||||||
|
|
||||||
if ((*ai_list_itr)->getID() == ID) {
|
|
||||||
(*ai_list_itr)->unbind();
|
|
||||||
ai_list_itr = ai_list.erase(ai_list_itr);
|
|
||||||
} else
|
|
||||||
++ai_list_itr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
FGAIManager::getNumAiObjects(void) const
|
FGAIManager::getNumAiObjects(void) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -70,7 +70,6 @@ public:
|
||||||
void updateLOD(SGPropertyNode* node);
|
void updateLOD(SGPropertyNode* node);
|
||||||
void attach(FGAIBase *model);
|
void attach(FGAIBase *model);
|
||||||
|
|
||||||
void destroyObject( int ID );
|
|
||||||
const FGAIBase *calcCollision(double alt, double lat, double lon, double fuse_range);
|
const FGAIBase *calcCollision(double alt, double lat, double lon, double fuse_range);
|
||||||
|
|
||||||
inline double get_user_latitude() const { return user_latitude; }
|
inline double get_user_latitude() const { return user_latitude; }
|
||||||
|
|
|
@ -61,7 +61,6 @@
|
||||||
FGAISchedule::FGAISchedule()
|
FGAISchedule::FGAISchedule()
|
||||||
{
|
{
|
||||||
firstRun = true;
|
firstRun = true;
|
||||||
AIManagerRef = 0;
|
|
||||||
|
|
||||||
heavy = false;
|
heavy = false;
|
||||||
radius = 0;
|
radius = 0;
|
||||||
|
@ -115,7 +114,6 @@ FGAISchedule::FGAISchedule(string model,
|
||||||
i != flt.end();
|
i != flt.end();
|
||||||
i++)
|
i++)
|
||||||
flights.push_back(new FGScheduledFlight((*(*i))));*/
|
flights.push_back(new FGScheduledFlight((*(*i))));*/
|
||||||
AIManagerRef = 0;
|
|
||||||
score = 0;
|
score = 0;
|
||||||
firstRun = true;
|
firstRun = true;
|
||||||
runCount = 0;
|
runCount = 0;
|
||||||
|
@ -134,7 +132,7 @@ FGAISchedule::FGAISchedule(const FGAISchedule &other)
|
||||||
heavy = other.heavy;
|
heavy = other.heavy;
|
||||||
flightIdentifier = other.flightIdentifier;
|
flightIdentifier = other.flightIdentifier;
|
||||||
flights = other.flights;
|
flights = other.flights;
|
||||||
AIManagerRef = other.AIManagerRef;
|
aiAircraft = other.aiAircraft;
|
||||||
acType = other.acType;
|
acType = other.acType;
|
||||||
airline = other.airline;
|
airline = other.airline;
|
||||||
m_class = other.m_class;
|
m_class = other.m_class;
|
||||||
|
@ -158,12 +156,9 @@ FGAISchedule::FGAISchedule(const FGAISchedule &other)
|
||||||
FGAISchedule::~FGAISchedule()
|
FGAISchedule::~FGAISchedule()
|
||||||
{
|
{
|
||||||
// remove related object from AI manager
|
// remove related object from AI manager
|
||||||
if (AIManagerRef)
|
if (aiAircraft)
|
||||||
{
|
{
|
||||||
FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai-model");
|
aiAircraft->setDie(true);
|
||||||
if (aimgr)
|
|
||||||
aimgr->destroyObject(AIManagerRef);
|
|
||||||
AIManagerRef = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
|
/* for (FGScheduledFlightVecIterator flt = flights.begin(); flt != flights.end(); flt++)
|
||||||
|
@ -234,11 +229,9 @@ bool FGAISchedule::update(time_t now, const SGVec3d& userCart)
|
||||||
//cerr << "Settiing departure time " << deptime << endl;
|
//cerr << "Settiing departure time " << deptime << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AIManagerRef) {
|
if (aiAircraft) {
|
||||||
// Check if this aircraft has been released.
|
if (aiAircraft->getDie()) {
|
||||||
FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("traffic-manager");
|
aiAircraft = NULL;
|
||||||
if (tmgr->isReleased(AIManagerRef)) {
|
|
||||||
AIManagerRef = 0;
|
|
||||||
} else {
|
} else {
|
||||||
return true; // in visual range, let the AIManager handle it
|
return true; // in visual range, let the AIManager handle it
|
||||||
}
|
}
|
||||||
|
@ -345,20 +338,20 @@ bool FGAISchedule::createAIAircraft(FGScheduledFlight* flight, double speedKnots
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGAIAircraft *aircraft = new FGAIAircraft(this);
|
aiAircraft = new FGAIAircraft(this);
|
||||||
aircraft->setPerformance(acType, m_class); //"jet_transport";
|
aiAircraft->setPerformance(acType, m_class); //"jet_transport";
|
||||||
aircraft->setCompany(airline); //i->getAirline();
|
aiAircraft->setCompany(airline); //i->getAirline();
|
||||||
aircraft->setAcType(acType); //i->getAcType();
|
aiAircraft->setAcType(acType); //i->getAcType();
|
||||||
aircraft->setPath(modelPath.c_str());
|
aiAircraft->setPath(modelPath.c_str());
|
||||||
//aircraft->setFlightPlan(flightPlanName);
|
//aircraft->setFlightPlan(flightPlanName);
|
||||||
aircraft->setLatitude(position.getLatitudeDeg());
|
aiAircraft->setLatitude(position.getLatitudeDeg());
|
||||||
aircraft->setLongitude(position.getLongitudeDeg());
|
aiAircraft->setLongitude(position.getLongitudeDeg());
|
||||||
aircraft->setAltitude(flight->getCruiseAlt()*100); // convert from FL to feet
|
aiAircraft->setAltitude(flight->getCruiseAlt()*100); // convert from FL to feet
|
||||||
aircraft->setSpeed(0);
|
aiAircraft->setSpeed(0);
|
||||||
aircraft->setBank(0);
|
aiAircraft->setBank(0);
|
||||||
|
|
||||||
courseToDest = SGGeodesy::courseDeg(position, arr->geod());
|
courseToDest = SGGeodesy::courseDeg(position, arr->geod());
|
||||||
FGAIFlightPlan *fp = new FGAIFlightPlan(aircraft, flightPlanName, courseToDest, deptime,
|
FGAIFlightPlan *fp = new FGAIFlightPlan(aiAircraft, flightPlanName, courseToDest, deptime,
|
||||||
dep, arr, true, radius,
|
dep, arr, true, radius,
|
||||||
flight->getCruiseAlt()*100,
|
flight->getCruiseAlt()*100,
|
||||||
position.getLatitudeDeg(),
|
position.getLatitudeDeg(),
|
||||||
|
@ -366,13 +359,12 @@ bool FGAISchedule::createAIAircraft(FGScheduledFlight* flight, double speedKnots
|
||||||
speedKnots, flightType, acType,
|
speedKnots, flightType, acType,
|
||||||
airline);
|
airline);
|
||||||
if (fp->isValidPlan()) {
|
if (fp->isValidPlan()) {
|
||||||
aircraft->SetFlightPlan(fp);
|
aiAircraft->SetFlightPlan(fp);
|
||||||
FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai-model");
|
FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai-model");
|
||||||
aimgr->attach(aircraft);
|
aimgr->attach(aiAircraft);
|
||||||
AIManagerRef = aircraft->getID();
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
delete aircraft;
|
aiAircraft = NULL;
|
||||||
delete fp;
|
delete fp;
|
||||||
//hand back the flights that had already been scheduled
|
//hand back the flights that had already been scheduled
|
||||||
while (!flights.empty()) {
|
while (!flights.empty()) {
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
#define TRAFFICTOAIDISTTOSTART 150.0
|
#define TRAFFICTOAIDISTTOSTART 150.0
|
||||||
#define TRAFFICTOAIDISTTODIE 200.0
|
#define TRAFFICTOAIDISTTODIE 200.0
|
||||||
|
|
||||||
|
// forward decls
|
||||||
|
class FGAIAircraft;
|
||||||
|
|
||||||
class FGAISchedule
|
class FGAISchedule
|
||||||
{
|
{
|
||||||
|
@ -52,7 +54,6 @@ class FGAISchedule
|
||||||
double radius;
|
double radius;
|
||||||
double groundOffset;
|
double groundOffset;
|
||||||
double distanceToUser;
|
double distanceToUser;
|
||||||
int AIManagerRef;
|
|
||||||
double score;
|
double score;
|
||||||
unsigned int runCount;
|
unsigned int runCount;
|
||||||
unsigned int hits;
|
unsigned int hits;
|
||||||
|
@ -71,6 +72,8 @@ class FGAISchedule
|
||||||
*/
|
*/
|
||||||
bool createAIAircraft(FGScheduledFlight* flight, double speedKnots, time_t deptime);
|
bool createAIAircraft(FGScheduledFlight* flight, double speedKnots, time_t deptime);
|
||||||
|
|
||||||
|
// the aiAircraft associated with us
|
||||||
|
SGSharedPtr<FGAIAircraft> aiAircraft;
|
||||||
public:
|
public:
|
||||||
FGAISchedule(); // constructor
|
FGAISchedule(); // constructor
|
||||||
FGAISchedule(string model,
|
FGAISchedule(string model,
|
||||||
|
|
|
@ -216,7 +216,6 @@ void FGTrafficManager::shutdown()
|
||||||
}
|
}
|
||||||
scheduledAircraft.clear();
|
scheduledAircraft.clear();
|
||||||
flights.clear();
|
flights.clear();
|
||||||
releaseList.clear();
|
|
||||||
|
|
||||||
currAircraft = scheduledAircraft.begin();
|
currAircraft = scheduledAircraft.begin();
|
||||||
doingInit = false;
|
doingInit = false;
|
||||||
|
@ -416,25 +415,6 @@ void FGTrafficManager::update(double dt)
|
||||||
currAircraft++;
|
currAircraft++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGTrafficManager::release(int id)
|
|
||||||
{
|
|
||||||
releaseList.push_back(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FGTrafficManager::isReleased(int id)
|
|
||||||
{
|
|
||||||
IdListIterator i = releaseList.begin();
|
|
||||||
while (i != releaseList.end()) {
|
|
||||||
if ((*i) == id) {
|
|
||||||
releaseList.erase(i);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
|
void FGTrafficManager::readTimeTableFromFile(SGPath infileName)
|
||||||
{
|
{
|
||||||
string model;
|
string model;
|
||||||
|
|
|
@ -58,10 +58,6 @@
|
||||||
#include "SchedFlight.hxx"
|
#include "SchedFlight.hxx"
|
||||||
#include "Schedule.hxx"
|
#include "Schedule.hxx"
|
||||||
|
|
||||||
|
|
||||||
typedef std::vector<int> IdList;
|
|
||||||
typedef std::vector<int>::iterator IdListIterator;
|
|
||||||
|
|
||||||
class Heuristic
|
class Heuristic
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -105,8 +101,6 @@ private:
|
||||||
double radius, offset;
|
double radius, offset;
|
||||||
bool heavy;
|
bool heavy;
|
||||||
|
|
||||||
IdList releaseList;
|
|
||||||
|
|
||||||
FGScheduledFlightMap flights;
|
FGScheduledFlightMap flights;
|
||||||
|
|
||||||
void readTimeTableFromFile(SGPath infilename);
|
void readTimeTableFromFile(SGPath infilename);
|
||||||
|
@ -134,8 +128,6 @@ public:
|
||||||
~FGTrafficManager();
|
~FGTrafficManager();
|
||||||
void init();
|
void init();
|
||||||
void update(double time);
|
void update(double time);
|
||||||
void release(int ref);
|
|
||||||
bool isReleased(int id);
|
|
||||||
|
|
||||||
FGScheduledFlightVecIterator getFirstFlight(const string &ref) { return flights[ref].begin(); }
|
FGScheduledFlightVecIterator getFirstFlight(const string &ref) { return flights[ref].begin(); }
|
||||||
FGScheduledFlightVecIterator getLastFlight(const string &ref) { return flights[ref].end(); }
|
FGScheduledFlightVecIterator getLastFlight(const string &ref) { return flights[ref].end(); }
|
||||||
|
|
Loading…
Reference in a new issue