From 152fec1cb638a18c8b3852e9992ca8987bb54052 Mon Sep 17 00:00:00 2001 From: Durk Talsma Date: Thu, 22 Sep 2011 20:52:05 +0200 Subject: [PATCH] Patch by Torsten Dryer: Remove the Ugly global dialog variable and remove rwy as a member variable from the AIFlightPlan class. --- src/AIModel/AIFlightPlan.cxx | 1 - src/AIModel/AIFlightPlan.hxx | 1 - src/AIModel/AIFlightPlanCreate.cxx | 20 ++++++++++++-------- src/AIModel/AIFlightPlanCreateCruise.cxx | 3 ++- src/ATC/atc_mgr.cxx | 4 +--- src/ATC/atc_mgr.hxx | 2 -- src/ATC/atcdialog.cxx | 7 ++++--- src/ATC/atcdialog.hxx | 16 ++++++++++++++-- src/ATC/trafficcontrol.cxx | 7 ++----- src/Airports/groundnetwork.cxx | 2 +- 10 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/AIModel/AIFlightPlan.cxx b/src/AIModel/AIFlightPlan.cxx index e87d11530..5458b2ce4 100644 --- a/src/AIModel/AIFlightPlan.cxx +++ b/src/AIModel/AIFlightPlan.cxx @@ -71,7 +71,6 @@ bool FGAIWaypoint::contains(string target) { FGAIFlightPlan::FGAIFlightPlan() { - rwy = 0; sid = 0; repeat = false; distance_to_go = 0; diff --git a/src/AIModel/AIFlightPlan.hxx b/src/AIModel/AIFlightPlan.hxx index 624ea16a8..1b95cad47 100644 --- a/src/AIModel/AIFlightPlan.hxx +++ b/src/AIModel/AIFlightPlan.hxx @@ -166,7 +166,6 @@ public: FGAIWaypoint *getLastWaypoint() { return waypoints.back(); }; private: - FGRunway* rwy; FGAIFlightPlan *sid; typedef std::vector wpt_vector_type; typedef wpt_vector_type::const_iterator wpt_vector_iterator; diff --git a/src/AIModel/AIFlightPlanCreate.cxx b/src/AIModel/AIFlightPlanCreate.cxx index 3ed42fb89..d53dc4bd0 100644 --- a/src/AIModel/AIFlightPlanCreate.cxx +++ b/src/AIModel/AIFlightPlanCreate.cxx @@ -226,7 +226,8 @@ bool FGAIFlightPlan::createTakeoffTaxi(FGAIAircraft * ac, bool firstFlight, apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, depHeading); } - rwy = apt->getRunwayByIdent(activeRunway); + FGRunway * rwy = apt->getRunwayByIdent(activeRunway); + assert( rwy != NULL ); SGGeod runwayTakeoff = rwy->pointOnCenterline(5.0); FGGroundNetwork *gn = apt->getDynamics()->getGroundNetwork(); @@ -456,9 +457,8 @@ bool FGAIFlightPlan::createTakeOff(FGAIAircraft * ac, bool firstFlight, apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, heading); } - rwy = apt->getRunwayByIdent(activeRunway); - - + FGRunway * rwy = apt->getRunwayByIdent(activeRunway); + assert( rwy != NULL ); double airportElev = apt->getElevation(); @@ -513,7 +513,6 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight, double heading = ac->getTrafficRef()->getCourse(); apt->getDynamics()->getActiveRunway(rwyClass, 1, activeRunway, heading); - rwy = apt->getRunwayByIdent(activeRunway); } if (sid) { for (wpt_vector_iterator i = sid->getFirstWayPoint(); @@ -522,6 +521,9 @@ bool FGAIFlightPlan::createClimb(FGAIAircraft * ac, bool firstFlight, //cerr << " Cloning waypoint " << endl; } } else { + FGRunway * rwy = apt->getRunwayByIdent(activeRunway); + assert( rwy != NULL ); + SGGeod climb1 = rwy->pointOnCenterline(10 * SG_NM_TO_METER); wpt = createInAir(ac, "10000ft climb", climb1, vClimb, 10000); wpt->setGear_down(true); @@ -560,9 +562,8 @@ bool FGAIFlightPlan::createDescent(FGAIAircraft * ac, FGAirport * apt, double heading = ac->getTrafficRef()->getCourse(); apt->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway, heading); - rwy = apt->getRunwayByIdent(activeRunway); - - + FGRunway * rwy = apt->getRunwayByIdent(activeRunway); + assert( rwy != NULL ); // Create a slow descent path that ends 250 lateral to the runway. double initialTurnRadius = getTurnRadius(vDescent, true); @@ -859,6 +860,9 @@ bool FGAIFlightPlan::createLanding(FGAIAircraft * ac, FGAirport * apt, char buffer[12]; for (int i = 1; i < 10; i++) { snprintf(buffer, 12, "wpt%d", i); + FGRunway * rwy = apt->getRunwayByIdent(activeRunway); + assert( rwy != NULL ); + coord = rwy->pointOnCenterline(rwy->lengthM() * (i / 10.0)); wpt = createOnGround(ac, buffer, coord, aptElev, (vTouchdown / i)); wpt->setCrossat(apt->getElevation()); diff --git a/src/AIModel/AIFlightPlanCreateCruise.cxx b/src/AIModel/AIFlightPlanCreateCruise.cxx index 0e8a97495..898e7ef5d 100644 --- a/src/AIModel/AIFlightPlanCreateCruise.cxx +++ b/src/AIModel/AIFlightPlanCreateCruise.cxx @@ -299,7 +299,8 @@ bool FGAIFlightPlan::createCruise(FGAIAircraft *ac, bool firstFlight, FGAirport string rwyClass = getRunwayClassFromTrafficType(fltType); double heading = ac->getTrafficRef()->getCourse(); arr->getDynamics()->getActiveRunway(rwyClass, 2, activeRunway, heading); - rwy = arr->getRunwayByIdent(activeRunway); + FGRunway* rwy = arr->getRunwayByIdent(activeRunway); + assert( rwy != NULL ); // begin descent 110km out SGGeod beginDescentPoint = rwy->pointOnCenterline(0); SGGeod secondaryDescentPoint = rwy->pointOnCenterline(-10000); diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index ef17774c2..0345c2509 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -46,8 +46,6 @@ FGATCManager::~FGATCManager() { void FGATCManager::init() { SGSubsystem::init(); - currentATCDialog = new FGATCDialogNew; - currentATCDialog->init(); int leg = 0; @@ -219,7 +217,7 @@ void FGATCManager::update ( double time ) { ai_ac.setSpeed(speed); ai_ac.update(time); controller = ai_ac.getATCController(); - currentATCDialog->update(time); + FGATCDialogNew::instance()->update(time); if (controller) { //cerr << "name of previous waypoint : " << fp->getPreviousWaypoint()->getName() << endl; diff --git a/src/ATC/atc_mgr.hxx b/src/ATC/atc_mgr.hxx index 38a2def72..0d9efa730 100644 --- a/src/ATC/atc_mgr.hxx +++ b/src/ATC/atc_mgr.hxx @@ -50,7 +50,6 @@ private: AtcVec activeStations; FGAIAircraft ai_ac; FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft. - //FGATCDialogNew dialog; // note that this variable should really replace the ugly global "currentATCDialog(); bool networkVisible; bool initSucceeded; @@ -60,7 +59,6 @@ public: void init(); void addController(FGATCController *controller); void update(double time); - FGATCDialogNew * getATCDialog() { return currentATCDialog; }; }; #endif // _ATC_MRG_HXX_ \ No newline at end of file diff --git a/src/ATC/atcdialog.cxx b/src/ATC/atcdialog.cxx index eb9533fbb..d2aad836e 100644 --- a/src/ATC/atcdialog.cxx +++ b/src/ATC/atcdialog.cxx @@ -35,11 +35,12 @@ FGATCDialogNew *currentATCDialog; -static bool doATCDialog(const SGPropertyNode* arg) { +/*static bool doATCDialog(const SGPropertyNode* arg) { //cerr << "Running doATCDialog" << endl; currentATCDialog->PopupDialog(); return(true); -} +}*/ +FGATCDialogNew * FGATCDialogNew::_instance = NULL; FGATCDialogNew::FGATCDialogNew() { @@ -54,7 +55,7 @@ FGATCDialogNew::~FGATCDialogNew() void FGATCDialogNew::init() { // Add ATC-dialog to the command list - globals->get_commands()->addCommand("ATC-dialog", doATCDialog); + globals->get_commands()->addCommand("ATC-dialog", FGATCDialogNew::popup ); // Add ATC-freq-search to the command list //globals->get_commands()->addCommand("ATC-freq-search", do_ATC_freq_search); diff --git a/src/ATC/atcdialog.hxx b/src/ATC/atcdialog.hxx index f52b5b4f1..2e1c4ada6 100644 --- a/src/ATC/atcdialog.hxx +++ b/src/ATC/atcdialog.hxx @@ -43,13 +43,14 @@ typedef vector StringVec; typedef vector:: iterator StringVecIterator; -static bool doATCDialog(const SGPropertyNode* arg); class FGATCDialogNew { private: NewGUI *_gui; bool dialogVisible; StringVec commands; + + static FGATCDialogNew *_instance; public: FGATCDialogNew(); @@ -61,8 +62,19 @@ public: void PopupDialog(); void addEntry(int, string); void removeEntry(int); + + static bool popup( const SGPropertyNode * ) { + instance()->PopupDialog(); + return true; + } + + inline static FGATCDialogNew * instance() { + if( _instance != NULL ) return _instance; + _instance = new FGATCDialogNew(); + _instance->init(); + return _instance; + } }; -extern FGATCDialogNew *currentATCDialog; #endif // _ATC_DIALOG_HXX_ \ No newline at end of file diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index dc0552fe7..f2802d3b7 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -731,9 +731,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, AtcMsgId msgId, } } } else { - FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc"); - atc->getATCDialog()->addEntry(1, text); - + FGATCDialogNew::instance()->addEntry(1, text); } } @@ -1151,8 +1149,7 @@ bool FGStartupController::checkTransmissionState(int st, time_t now, time_t star trans_num->setIntValue(-1); // PopupCallback(n); //cerr << "Selected transmission message " << n << endl; - FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc"); - atc->getATCDialog()->removeEntry(1); + FGATCDialogNew::instance()->removeEntry(1); } else { //cerr << "creading message for " << i->getAircraft()->getCallSign() << endl; transmit(&(*i), msgId, msgDir, false); diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index 0da6af35c..3a3c6d714 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -679,7 +679,7 @@ bool FGGroundNetwork::checkTransmissionState(int minState, int maxState, Traffic // PopupCallback(n); //cerr << "Selected transmission message " << n << endl; FGATCManager *atc = (FGATCManager*) globals->get_subsystem("atc"); - atc->getATCDialog()->removeEntry(1); + FGATCDialogNew::instance()->removeEntry(1); } else { //cerr << "creating message for " << i->getAircraft()->getCallSign() << endl; transmit(&(*i), msgId, msgDir, false);