Use a unique_ptr to manage FGAIFlightPlan
This commit is contained in:
parent
c4aa3434ab
commit
66eb3d2690
8 changed files with 32 additions and 53 deletions
|
@ -247,24 +247,15 @@ void FGAIAircraft::setFlightPlan(const std::string& flightplan, bool repeat)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
|
std::unique_ptr<FGAIFlightPlan> plan(new FGAIFlightPlan(flightplan));
|
||||||
if (fp->isValidPlan()) {
|
if (plan->isValidPlan()) {
|
||||||
fp->setRepeat(repeat);
|
plan->setRepeat(repeat);
|
||||||
SetFlightPlan(fp);
|
FGAIBase::setFlightPlan(std::move(plan));
|
||||||
} else {
|
} else {
|
||||||
SG_LOG(SG_AI, SG_WARN, "setFlightPlan: invalid flightplan specified:" << flightplan);
|
SG_LOG(SG_AI, SG_WARN, "setFlightPlan: invalid flightplan specified:" << flightplan);
|
||||||
delete fp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FGAIAircraft::SetFlightPlan(FGAIFlightPlan *f)
|
|
||||||
{
|
|
||||||
delete fp;
|
|
||||||
fp = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
|
void FGAIAircraft::ProcessFlightPlan( double dt, time_t now ) {
|
||||||
|
|
||||||
// the one behind you
|
// the one behind you
|
||||||
|
@ -634,7 +625,7 @@ void FGAIAircraft::announcePositionToController() {
|
||||||
}
|
}
|
||||||
prevController = controller;
|
prevController = controller;
|
||||||
if (controller) {
|
if (controller) {
|
||||||
controller->announcePosition(getID(), fp, fp->getCurrentWaypoint()->getRouteIndex(),
|
controller->announcePosition(getID(), fp.get(), fp->getCurrentWaypoint()->getRouteIndex(),
|
||||||
_getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
|
_getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
|
||||||
trafficRef->getRadius(), leg, this);
|
trafficRef->getRadius(), leg, this);
|
||||||
}
|
}
|
||||||
|
@ -650,7 +641,7 @@ void FGAIAircraft::scheduleForATCTowerDepartureControl(int state) {
|
||||||
cerr << "Error: Could not find Dynamics at airport : " << trafficRef->getDepartureAirport()->getId() << endl;
|
cerr << "Error: Could not find Dynamics at airport : " << trafficRef->getDepartureAirport()->getId() << endl;
|
||||||
}
|
}
|
||||||
if (towerController) {
|
if (towerController) {
|
||||||
towerController->announcePosition(getID(), fp, fp->getCurrentWaypoint()->getRouteIndex(),
|
towerController->announcePosition(getID(), fp.get(), fp->getCurrentWaypoint()->getRouteIndex(),
|
||||||
_getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
|
_getLatitude(), _getLongitude(), hdg, speed, altitude_ft,
|
||||||
trafficRef->getRadius(), leg, this);
|
trafficRef->getRadius(), leg, this);
|
||||||
//cerr << "Scheduling " << trafficRef->getCallSign() << " for takeoff " << endl;
|
//cerr << "Scheduling " << trafficRef->getCallSign() << " for takeoff " << endl;
|
||||||
|
|
|
@ -49,9 +49,9 @@ public:
|
||||||
// void setPerformance(PerformanceData *ps);
|
// void setPerformance(PerformanceData *ps);
|
||||||
|
|
||||||
void setFlightPlan(const std::string& fp, bool repat = false);
|
void setFlightPlan(const std::string& fp, bool repat = false);
|
||||||
void SetFlightPlan(FGAIFlightPlan *f);
|
|
||||||
void initializeFlightPlan();
|
void initializeFlightPlan();
|
||||||
FGAIFlightPlan* GetFlightPlan() const { return fp; };
|
FGAIFlightPlan* GetFlightPlan() const { return fp.get(); };
|
||||||
void ProcessFlightPlan( double dt, time_t now );
|
void ProcessFlightPlan( double dt, time_t now );
|
||||||
time_t checkForArrivalTime(const std::string& wptName);
|
time_t checkForArrivalTime(const std::string& wptName);
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,6 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
|
||||||
model_removed( fgGetNode("/ai/models/model-removed", true) ),
|
model_removed( fgGetNode("/ai/models/model-removed", true) ),
|
||||||
manager( NULL ),
|
manager( NULL ),
|
||||||
_installed(false),
|
_installed(false),
|
||||||
fp( NULL ),
|
|
||||||
_impact_lat(0),
|
_impact_lat(0),
|
||||||
_impact_lon(0),
|
_impact_lon(0),
|
||||||
_impact_elev(0),
|
_impact_elev(0),
|
||||||
|
@ -205,10 +204,6 @@ FGAIBase::~FGAIBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
removeSoundFx();
|
removeSoundFx();
|
||||||
|
|
||||||
if (fp)
|
|
||||||
delete fp;
|
|
||||||
fp = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Cleanly remove the model
|
/** Cleanly remove the model
|
||||||
|
@ -935,7 +930,13 @@ int FGAIBase::_newAIModelID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FGAIBase::isValid() {
|
void FGAIBase::setFlightPlan(std::unique_ptr<FGAIFlightPlan> f)
|
||||||
|
{
|
||||||
|
fp = std::move(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FGAIBase::isValid() const
|
||||||
|
{
|
||||||
//Either no flightplan or it is valid
|
//Either no flightplan or it is valid
|
||||||
return !fp || fp->isValidPlan();
|
return !fp || fp->isValidPlan();
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,9 @@ public:
|
||||||
int _getSubID() const;
|
int _getSubID() const;
|
||||||
|
|
||||||
bool getDie();
|
bool getDie();
|
||||||
bool isValid();
|
bool isValid() const;
|
||||||
|
|
||||||
|
void setFlightPlan(std::unique_ptr<FGAIFlightPlan> f);
|
||||||
|
|
||||||
SGGeod getGeodPos() const;
|
SGGeod getGeodPos() const;
|
||||||
|
|
||||||
|
@ -211,7 +213,7 @@ protected:
|
||||||
|
|
||||||
double life;
|
double life;
|
||||||
|
|
||||||
FGAIFlightPlan *fp;
|
std::unique_ptr<FGAIFlightPlan> fp;
|
||||||
|
|
||||||
bool _impact_reported;
|
bool _impact_reported;
|
||||||
bool _collision_reported;
|
bool _collision_reported;
|
||||||
|
|
|
@ -106,12 +106,9 @@ void FGAIShip::readFromScenario(SGPropertyNode* scFileNode) {
|
||||||
setRollFactor(scFileNode->getDoubleValue("roll-factor", 1));
|
setRollFactor(scFileNode->getDoubleValue("roll-factor", 1));
|
||||||
|
|
||||||
if (!flightplan.empty()) {
|
if (!flightplan.empty()) {
|
||||||
SG_LOG(SG_AI, SG_ALERT, "getting flightplan: " << _name );
|
std::unique_ptr<FGAIFlightPlan> plan(new FGAIFlightPlan(flightplan));
|
||||||
|
setFlightPlan(std::move(plan));
|
||||||
FGAIFlightPlan* fp = new FGAIFlightPlan(flightplan);
|
|
||||||
setFlightPlan(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FGAIShip::init(bool search_in_AI_path) {
|
bool FGAIShip::init(bool search_in_AI_path) {
|
||||||
|
@ -457,10 +454,6 @@ double FGAIShip::sign(double x) {
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FGAIShip::setFlightPlan(FGAIFlightPlan* f) {
|
|
||||||
fp = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FGAIShip::setStartTime(const string& st) {
|
void FGAIShip::setStartTime(const string& st) {
|
||||||
_start_time = st;
|
_start_time = st;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ public:
|
||||||
virtual void update(double dt);
|
virtual void update(double dt);
|
||||||
virtual void reinit();
|
virtual void reinit();
|
||||||
|
|
||||||
void setFlightPlan(FGAIFlightPlan* f);
|
|
||||||
void setRudder(float r);
|
void setRudder(float r);
|
||||||
void setRoll(double rl);
|
void setRoll(double rl);
|
||||||
void ProcessFlightPlan( double dt);
|
void ProcessFlightPlan( double dt);
|
||||||
|
|
|
@ -101,7 +101,7 @@ void FGATCManager::init() {
|
||||||
flight->setCallSign(callsign);
|
flight->setCallSign(callsign);
|
||||||
|
|
||||||
trafficRef->assign(flight);
|
trafficRef->assign(flight);
|
||||||
FGAIFlightPlan *fp = 0;
|
std::unique_ptr<FGAIFlightPlan> fp ;
|
||||||
ai_ac->setTrafficRef(trafficRef);
|
ai_ac->setTrafficRef(trafficRef);
|
||||||
|
|
||||||
string flightPlanName = airport + "-" + airport + ".xml";
|
string flightPlanName = airport + "-" + airport + ".xml";
|
||||||
|
@ -118,7 +118,7 @@ void FGATCManager::init() {
|
||||||
// No valid parking location, so either at the runway or at a random location.
|
// No valid parking location, so either at the runway or at a random location.
|
||||||
if (pk.isValid()) {
|
if (pk.isValid()) {
|
||||||
dcs->setParkingAvailable(pk.parking(), false);
|
dcs->setParkingAvailable(pk.parking(), false);
|
||||||
fp = new FGAIFlightPlan;
|
fp.reset(new FGAIFlightPlan);
|
||||||
controller = dcs->getStartupController();
|
controller = dcs->getStartupController();
|
||||||
int stationFreq = dcs->getGroundFrequency(1);
|
int stationFreq = dcs->getGroundFrequency(1);
|
||||||
if (stationFreq > 0)
|
if (stationFreq > 0)
|
||||||
|
@ -155,7 +155,7 @@ void FGATCManager::init() {
|
||||||
//cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
|
//cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
|
||||||
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
|
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
|
||||||
}
|
}
|
||||||
fp = new FGAIFlightPlan;
|
fp.reset(new FGAIFlightPlan);
|
||||||
leg = 3;
|
leg = 3;
|
||||||
string fltType = "ga";
|
string fltType = "ga";
|
||||||
fp->setRunway(runway);
|
fp->setRunway(runway);
|
||||||
|
@ -177,18 +177,13 @@ void FGATCManager::init() {
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fp->restart();
|
fp->restart();
|
||||||
fp->setLeg(leg);
|
fp->setLeg(leg);
|
||||||
ai_ac->SetFlightPlan(fp);
|
ai_ac->FGAIBase::setFlightPlan(std::move(fp));
|
||||||
}
|
}
|
||||||
if (controller) {
|
if (controller) {
|
||||||
controller->announcePosition(ai_ac->getID(), fp, fp->getCurrentWaypoint()->getRouteIndex(),
|
FGAIFlightPlan* plan = ai_ac->GetFlightPlan();
|
||||||
|
controller->announcePosition(ai_ac->getID(), plan, plan->getCurrentWaypoint()->getRouteIndex(),
|
||||||
ai_ac->_getLatitude(), ai_ac->_getLongitude(), heading, speed, altitude,
|
ai_ac->_getLatitude(), ai_ac->_getLongitude(), heading, speed, altitude,
|
||||||
aircraftRadius, leg, ai_ac);
|
aircraftRadius, leg, ai_ac);
|
||||||
|
|
||||||
//dialog.init();
|
|
||||||
|
|
||||||
//osg::Node* node = apt->getDynamics()->getGroundNetwork()->getRenderNode();
|
|
||||||
//cerr << "Adding groundnetWork to the scenegraph::init" << endl;
|
|
||||||
//globals->get_scenery()->get_scene_graph()->addChild(node);
|
|
||||||
}
|
}
|
||||||
initSucceeded = true;
|
initSucceeded = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,21 +373,19 @@ bool FGAISchedule::createAIAircraft(FGScheduledFlight* flight, double speedKnots
|
||||||
aiAircraft->setBank(0);
|
aiAircraft->setBank(0);
|
||||||
|
|
||||||
courseToDest = SGGeodesy::courseDeg(position, arr->geod());
|
courseToDest = SGGeodesy::courseDeg(position, arr->geod());
|
||||||
FGAIFlightPlan *fp = new FGAIFlightPlan(aiAircraft, flightPlanName, courseToDest, deptime,
|
std::unique_ptr<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(),
|
||||||
position.getLongitudeDeg(),
|
position.getLongitudeDeg(),
|
||||||
speedKnots, flightType, acType,
|
speedKnots, flightType, acType,
|
||||||
airline);
|
airline));
|
||||||
if (fp->isValidPlan()) {
|
if (fp->isValidPlan()) {
|
||||||
aiAircraft->SetFlightPlan(fp);
|
aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
|
||||||
FGAIManager* aimgr = (FGAIManager *) globals-> get_subsystem("ai-model");
|
globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
|
||||||
aimgr->attach(aiAircraft);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
aiAircraft = NULL;
|
aiAircraft = NULL;
|
||||||
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()) {
|
||||||
flights.front()->release();
|
flights.front()->release();
|
||||||
|
|
Loading…
Reference in a new issue