]> git.mxchange.org Git - flightgear.git/commitdiff
Remove isReciprocal from FGRunway.
authorJames Turner <zakalawe@mac.com>
Thu, 28 Feb 2013 18:21:23 +0000 (18:21 +0000)
committerJames Turner <zakalawe@mac.com>
Thu, 28 Feb 2013 18:21:29 +0000 (18:21 +0000)
This was a bogus concept, either runways have a reciprocal or not (if singled-ended), really this was simply exposing an artefact of the apt.dat encoding. Change to an API which gives what is actually wanted - the ability to extract an airport's runways without any reciprocals included.

src/Airports/airport.cxx
src/Airports/airport.hxx
src/Airports/runways.cxx
src/Airports/runways.hxx
src/Cockpit/groundradar.cxx
src/GUI/MapWidget.cxx
src/Navaids/NavDataCache.cxx

index 2f8dc11976d14c533128a3a51c62e2cd0350ec4e..5bfdb18e28499e61511cb44903fcd9be9b3a3c83 100644 (file)
@@ -247,11 +247,6 @@ bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
   
   BOOST_FOREACH(PositionedID id, mRunways) {
     FGRunway* rwy = (FGRunway*) flightgear::NavDataCache::instance()->loadById(id);
-
-    if (rwy->isReciprocal()) {
-      continue; // we only care about lengths, so don't do work twice
-    }
-
     if (rwy->isHardSurface() && (rwy->lengthFt() >= aLengthFt)) {
       return true; // we're done!
     }
@@ -260,6 +255,28 @@ bool FGAirport::hasHardRunwayOfLengthFt(double aLengthFt) const
   return false;
 }
 
+FGRunwayList FGAirport::getRunwaysWithoutReciprocals() const
+{
+  loadRunways();
+  
+  FGRunwayList r;
+  
+  BOOST_FOREACH(PositionedID id, mRunways) {
+    FGRunway* rwy = (FGRunway*) flightgear::NavDataCache::instance()->loadById(id);
+    FGRunway* recip = rwy->reciprocalRunway();
+    if (recip) {
+      FGRunwayList::iterator it = std::find(r.begin(), r.end(), recip);
+      if (it != r.end()) {
+        continue; // reciprocal already in result set, don't include us
+      }
+    }
+    
+    r.push_back(rwy);
+  }
+  
+  return r;
+}
+
 unsigned int FGAirport::numTaxiways() const
 {
   loadTaxiways();
index 8c0c492977bba348d817ec55b916c789e6399c0e..2d2ca713828e68775c8731f46c58846eba915cb7 100644 (file)
@@ -58,6 +58,7 @@ namespace flightgear {
   typedef std::map<std::string, FGAirport*> AirportCache;
 }
 
+typedef std::vector<FGRunway*> FGRunwayList;
 
 
 /***************************************************************************************
@@ -122,6 +123,19 @@ public:
      */
     FGRunway* findBestRunwayForPos(const SGGeod& aPos) const;
     
+    /**
+     * Retrieve all runways at the airport, but excluding the reciprocal
+     * runways. For example at KSFO this might return 1L, 1R, 28L and 28R,
+     * but would not then include 19L/R or 10L/R.
+     *
+     * Exactly which runways you get, is undefined (i.e, dont assumes it's
+     * runways with heading < 180 degrees) - it depends on order in apt.dat.
+     *
+     * This is useful for code that wants to process each piece of tarmac at
+     * an airport *once*, not *twice* - eg mapping and nav-display code.
+     */
+    FGRunwayList getRunwaysWithoutReciprocals() const;
+    
      /**
      * Useful predicate for FMS/GPS/NAV displays and similar - check if this
      * aiport has a hard-surfaced runway of at least the specified length.
index 8abed46cadd9c1a06565c9c02dfbb5974c1fc10f..66f2407a2989d438321b4feea5022239e34108fe 100644 (file)
@@ -51,12 +51,10 @@ FGRunway::FGRunway(PositionedID aGuid,
                         const double width,
                         const double displ_thresh,
                         const double stopway,
-                        const int surface_code,
-                        bool reciprocal) :
+                        const int surface_code) :
   FGRunwayBase(aGuid, RUNWAY, aIdent, aGeod,
                heading, length, width, surface_code),
   _airport(aAirport),
-  _isReciprocal(reciprocal),
   _reciprocal(0),
   _displ_thresh(displ_thresh),
   _stopway(stopway),
@@ -209,7 +207,6 @@ FGHelipad::FGHelipad(PositionedID aGuid,
                         const double width,
                         const int surface_code) :
   FGRunwayBase(aGuid, RUNWAY, aIdent, aGeod,
-               heading, length, width, surface_code),
-  _airport(aAirport)
+               heading, length, width, surface_code)
 {
 }
index b5109de4fe991b2cebbd5bb1bcb0a168e2e83737..216875c410c8caa2793798d815df06b77f2d7ebf 100644 (file)
@@ -42,7 +42,6 @@ namespace flightgear {
 class FGRunway : public FGRunwayBase
 {
   PositionedID _airport;
-  bool _isReciprocal;
   PositionedID _reciprocal;
   double _displ_thresh;
   double _stopway;
@@ -56,8 +55,7 @@ public:
             const double width,
             const double displ_thresh,
             const double stopway,
-            const int surface_code,
-            const bool reciprocal);
+            const int surface_code);
   
   /**
    * given a runway identifier (06, 18L, 31R) compute the identifier for the
@@ -71,13 +69,6 @@ public:
    */
   double score(double aLengthWt, double aWidthWt, double aSurfaceWt) const;
 
-  /**
-   * Test if this runway is the reciprocal. This allows users who iterate
-   * over runways to avoid counting runways twice, if desired.
-   */
-  bool isReciprocal() const
-  { return _isReciprocal; }
-
   /**
    * Get the runway beginning point - this is syntatic sugar, equivalent to
    * calling pointOnCenterline(0.0);
@@ -136,7 +127,6 @@ public:
 
 class FGHelipad : public FGRunwayBase
 {
-  PositionedID _airport;
 public:
     FGHelipad(PositionedID aGuid,
            PositionedID aAirport, const std::string& rwy_no,
index 7a2af9b62125ef2e19c5ae3dadd287afc72fae4a..702ba6d5a941be98139df383432029f2baad44a5 100644 (file)
@@ -336,12 +336,10 @@ void GroundRadar::updateTexture()
     }
     pvt_geom->setVertexArray(pvt_vertices.get());
 
-    for (unsigned int i=0; i<apt->numRunways(); ++i)
+    FGRunwayList rwys(apt->getRunwaysWithoutReciprocals());
+    for (unsigned int i=0; i<rwys.size(); ++i)
     {
-      FGRunway* runway(apt->getRunwayByIndex(i));
-      if (runway->isReciprocal()) continue;
-      
-      addRunwayVertices(runway, tower_lat, tower_lon, scale, rwy_vertices.get());
+      addRunwayVertices(rwys[i], tower_lat, tower_lon, scale, rwy_vertices.get());
     }
     osg::Geometry *rwy_geom = dynamic_cast<osg::Geometry *>(_geode->getDrawable(2));
     rwy_geom->setVertexArray(rwy_vertices.get());
index b8bac7236bf9441cdd3343c3fd31137eb67177ff..249605c6bfe7f9ac9859cf76c71e0e49a51ac5ed 100644 (file)
@@ -1194,22 +1194,26 @@ void MapWidget::drawAirport(FGAirport* apt)
     return;
   }
 
-  for (unsigned int r=0; r<apt->numRunways(); ++r) {
-      FGRunway* rwy = apt->getRunwayByIndex(r);
-      if (!rwy->isReciprocal()) {
-          drawRunwayPre(rwy);
-      }
+  FGRunwayList runways(apt->getRunwaysWithoutReciprocals());
+    
+  for (unsigned int r=0; r<runways.size(); ++r) {
+    drawRunwayPre(runways[r]);
   }
 
-  for (unsigned int r=0; r<apt->numRunways(); ++r) {
-      FGRunway* rwy = apt->getRunwayByIndex(r);
-      if (!rwy->isReciprocal()) {
-          drawRunway(rwy);
-      }
+  for (unsigned int r=0; r<runways.size(); ++r) {
+    FGRunway* rwy = runways[r];
+    drawRunway(rwy);
 
-      if (rwy->ILS()) {
-          drawILS(false, rwy);
+    if (rwy->ILS()) {
+        drawILS(false, rwy);
+    }
+    
+    if (rwy->reciprocalRunway()) {
+      FGRunway* recip = rwy->reciprocalRunway();
+      if (recip->ILS()) {
+        drawILS(false, recip);
       }
+    }
   }
 
   for (unsigned int r=0; r<apt->numHelipads(); ++r) {
@@ -1224,14 +1228,11 @@ int MapWidget::scoreAirportRunways(FGAirport* apt)
   bool needHardSurface = _root->getBoolValue("hard-surfaced-airports", true);
   double minLength = _root->getDoubleValue("min-runway-length-ft", 2000.0);
 
-  int score = 0;
-  unsigned int numRunways(apt->numRunways());
-  for (unsigned int r=0; r<numRunways; ++r) {
-    FGRunway* rwy = apt->getRunwayByIndex(r);
-    if (rwy->isReciprocal()) {
-      continue;
-    }
+  FGRunwayList runways(apt->getRunwaysWithoutReciprocals());
 
+  int score = 0;
+  for (unsigned int r=0; r<runways.size(); ++r) {
+    FGRunway* rwy = runways[r];
     if (needHardSurface && !rwy->isHardSurface()) {
       continue;
     }
index b27736d1b6a57fa87c13a670e4d3e5f588535496..ee7b90d95469d3a4ca49f860c0f3b831af6afdbc 100644 (file)
@@ -733,7 +733,7 @@ public:
       PositionedID reciprocal = sqlite3_column_int64(loadRunwayStmt, 6);
       PositionedID ils = sqlite3_column_int64(loadRunwayStmt, 7);
       FGRunway* r = new FGRunway(rowId, apt, id, pos, heading, lengthM, widthM,
-                          displacedThreshold, stopway, surface, false);
+                          displacedThreshold, stopway, surface);
       
       if (reciprocal > 0) {
         r->setReciprocalRunway(reciprocal);