]> git.mxchange.org Git - flightgear.git/commitdiff
Patch by Torsten Dryer: Remove the Ugly global dialog variable and remove rwy as...
authorDurk Talsma <durktals@gmail.com>
Thu, 22 Sep 2011 18:52:05 +0000 (20:52 +0200)
committerDurk Talsma <durktals@gmail.com>
Thu, 22 Sep 2011 18:52:05 +0000 (20:52 +0200)
src/AIModel/AIFlightPlan.cxx
src/AIModel/AIFlightPlan.hxx
src/AIModel/AIFlightPlanCreate.cxx
src/AIModel/AIFlightPlanCreateCruise.cxx
src/ATC/atc_mgr.cxx
src/ATC/atc_mgr.hxx
src/ATC/atcdialog.cxx
src/ATC/atcdialog.hxx
src/ATC/trafficcontrol.cxx
src/Airports/groundnetwork.cxx

index e87d11530ab3a4eb485359604b73827796e88c2a..5458b2ce45855125fcb7f0221648a11a2da6d7d7 100644 (file)
@@ -71,7 +71,6 @@ bool FGAIWaypoint::contains(string target) {
 
 FGAIFlightPlan::FGAIFlightPlan() 
 {
-    rwy = 0;
     sid = 0;
     repeat = false;
     distance_to_go = 0;
index 624ea16a82ef4fde9cb73a16adfc1dd0e8ff58eb..1b95cad47af6c08a6c9ce225bcfcd1540e3d1ad1 100644 (file)
@@ -166,7 +166,6 @@ public:
   FGAIWaypoint *getLastWaypoint() { return waypoints.back(); };
 
 private:
-  FGRunway* rwy;
   FGAIFlightPlan *sid;
   typedef std::vector <FGAIWaypoint*> wpt_vector_type;
   typedef wpt_vector_type::const_iterator wpt_vector_iterator;
index 3ed42fb89d1ec91bff298a2c88095dab12182e62..d53dc4bd08075540a8568b7ffde8c72153d8ebd0 100644 (file)
@@ -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());
index 0e8a97495c437f775117f43fe7e3bbdb1b4396e4..898e7ef5d3b090f15ac67283623a0053989eeb2b 100644 (file)
@@ -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);
index ef17774c2117ca68d73f513943d9b92cd2090319..0345c2509d32cbb5ed58741af8447705de80cc20 100644 (file)
@@ -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;
 
index 38a2def729475bac0c4251db41d506094da4560a..0d9efa730b81bcffe139dae4a540441c783e34b9 100644 (file)
@@ -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
index eb9533fbb692726b6d5b6aba720e5b75cff56635..d2aad836e25e78c93be1381d191f77fb938d160a 100644 (file)
 
 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);
 
index f52b5b4f1852e0f7c20a8b2abdf6add13ea4c9f0..2e1c4ada686af1a194e8e4f2677b9149e0a0e234 100644 (file)
 typedef vector<string> StringVec;
 typedef vector<string>:: 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
index dc0552fe7a9d2b958b46fcc9d6406d01b82e4aa1..f2802d3b7b3865caf8d94ea2f31b3ceb0ebfd606 100644 (file)
@@ -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);
index 0da6af35cae8ac9e227dad55fb6ada62ef617cbe..3a3c6d7144f37790aa162d7a8cd265685786112d 100644 (file)
@@ -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);