]> git.mxchange.org Git - flightgear.git/commitdiff
- rename dynamics to _dynamics for consistency reasons
authormfranz <mfranz>
Fri, 5 Oct 2007 12:59:43 +0000 (12:59 +0000)
committermfranz <mfranz>
Fri, 5 Oct 2007 12:59:43 +0000 (12:59 +0000)
- preserve information from apt.dat about whether an airport is a "normal"
  airport, a seaport, or a heliport. Do it without wasting another byte
  in the FGAirport structure (saves 50kB of memory). Yes, I know bitfields. :-)

src/Airports/apt_loader.cxx
src/Airports/simple.cxx
src/Airports/simple.hxx

index a7475c70823b75f93a2104257e9db91b61e6939d..43f350d3392319063cca917257136377ea58f536 100644 (file)
 
 static void addAirport(FGAirportList *airports, const string& apt_id, const string& apt_name,
     int rwy_count, double rwy_lat_accum, double rwy_lon_accum, double last_rwy_heading,
-    double apt_elev, SGGeod& tower, bool got_tower)
+    double apt_elev, SGGeod& tower, bool got_tower, int type)
 {
-    if (!apt_id.empty()) {
-        if (rwy_count > 0) {
-            double lat = rwy_lat_accum / (double)rwy_count;
-            double lon = rwy_lon_accum / (double)rwy_count;
-
-            if (!got_tower) {
-                // tower height hard coded for now...
-                const float tower_height = 50.0f;
-                // make a little off the heading for 1 runway airports...
-                float fudge_lon = fabs(sin(last_rwy_heading * SGD_DEGREES_TO_RADIANS)) * .003f;
-                float fudge_lat = .003f - fudge_lon;
-        
-                tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, apt_elev + tower_height);
-            }
-                    
-            airports->add(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false);
-        } else {
-            if ( apt_id.length() ) {
-                SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: No runways for " << apt_id
-                        << ", skipping." );
-            }
-        }
+    if (apt_id.empty())
+        return;
+
+    if (!rwy_count) {
+        SG_LOG(SG_GENERAL, SG_ALERT, "ERROR: No runways for " << apt_id
+                << ", skipping." );
+        return;
     }
+
+    double lat = rwy_lat_accum / (double)rwy_count;
+    double lon = rwy_lon_accum / (double)rwy_count;
+
+    if (!got_tower) {
+        // tower height hard coded for now...
+        const float tower_height = 50.0f;
+        // make a little off the heading for 1 runway airports...
+        float fudge_lon = fabs(sin(last_rwy_heading * SGD_DEGREES_TO_RADIANS)) * .003f;
+        float fudge_lat = .003f - fudge_lon;
+        tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, apt_elev + tower_height);
+    }
+
+    airports->add(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false,
+            type == 1/*airport*/, type == 16/*seaport*/, type == 17/*heliport*/);
 }
 
 // Load the airport data base from the specified aptdb file.  The
@@ -151,7 +151,7 @@ bool fgAirportDBLoad( FGAirportList *airports, FGRunwayList *runways,
                     << elev );
 
             addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum,
-                last_rwy_heading, last_apt_elev, last_tower, got_tower);
+                last_rwy_heading, last_apt_elev, last_tower, got_tower, line_id);
 
             last_apt_id = id;
             last_apt_elev = elev;
@@ -242,9 +242,9 @@ bool fgAirportDBLoad( FGAirportList *airports, FGRunwayList *runways,
         }
     }
 
-    // add the last airport being processed if any    
+    // add the last airport being processed if any
     addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum,
-        last_rwy_heading, last_apt_elev, last_tower, got_tower);
+        last_rwy_heading, last_apt_elev, last_tower, got_tower, 0);
 
 
     //
index 0b9c39097e57e8203f6b592180abc4ff413ede9e..6efac4c0e25a853ee85d117a983184d65c0a34cd 100644 (file)
@@ -61,42 +61,46 @@ SG_USING_STD(random_shuffle);
 /***************************************************************************
  * FGAirport
  ***************************************************************************/
-FGAirport::FGAirport()
+FGAirport::FGAirport() : _dynamics(0)
 {
-    dynamics = 0;
 }
 
-FGAirport::FGAirport(const string &id, const SGGeod& location, const SGGeod& tower_location, const string &name, bool has_metar)
+FGAirport::FGAirport(const string &id, const SGGeod& location, const SGGeod& tower_location,
+        const string &name, bool has_metar, bool is_airport, bool is_seaport,
+        bool is_heliport) :
+    _id(id),
+    _location(location),
+    _tower_location(tower_location),
+    _name(name),
+    _has_metar(has_metar),
+    _is_airport(is_airport),
+    _is_seaport(is_seaport),
+    _is_heliport(is_heliport),
+    _dynamics(0)
 {
-    _id = id;
-    _location = location;
-    _tower_location = tower_location;
-    _name      = name;
-    _has_metar = has_metar;
-    dynamics   = 0;
 }
 
 
 FGAirport::~FGAirport()
 {
-    delete dynamics;
+    delete _dynamics;
 }
 
 
 FGAirportDynamics * FGAirport::getDynamics()
 {
-    if (dynamics != 0) {
-        return dynamics;
+    if (_dynamics != 0) {
+        return _dynamics;
     } else {
         //cerr << "Trying to load dynamics for " << _id << endl;
-        dynamics = new FGAirportDynamics(this);
-        XMLLoader::load(dynamics);
+        _dynamics = new FGAirportDynamics(this);
+        XMLLoader::load(_dynamics);
 
         FGRunwayPreference rwyPrefs(this);
         XMLLoader::load(&rwyPrefs);
-        dynamics->setRwyUse(rwyPrefs);
+        _dynamics->setRwyUse(rwyPrefs);
    }
-    return dynamics;
+    return _dynamics;
 }
 
 
@@ -142,13 +146,15 @@ FGAirportList::~FGAirportList( void )
 
 // add an entry to the list
 void FGAirportList::add( const string &id, const SGGeod& location, const SGGeod& tower_location,
-                         const string &name, const bool has_metar )
+                         const string &name, bool has_metar, bool is_airport, bool is_seaport,
+                         bool is_heliport)
 {
-    FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar);
+    FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar,
+            is_airport, is_seaport, is_heliport);
+
     airports_by_id[a->getId()] = a;
     // try and read in an auxilary file
+
     airports_array.push_back( a );
     SG_LOG( SG_GENERAL, SG_BULK, "Adding " << id << " pos = " << location.getLongitudeDeg()
             << ", " << location.getLatitudeDeg() << " elev = " << location.getElevationFt() );
index cb003e3d991b243cf1c3b79038701aa10e2fdb19..9251ee423a7fa08d3a2f1585741a3e8a08ee9fcd 100644 (file)
@@ -69,12 +69,16 @@ private:
     SGGeod _tower_location;
     string _name;
     bool _has_metar;
-    FGAirportDynamics *dynamics;
+    bool _is_airport;
+    bool _is_seaport;
+    bool _is_heliport;
+    FGAirportDynamics *_dynamics;
 
 public:
     FGAirport();
     // FGAirport(const FGAirport &other);
-    FGAirport(const string& id, const SGGeod& location, const SGGeod& tower, const string& name, bool has_metar);
+    FGAirport(const string& id, const SGGeod& location, const SGGeod& tower, const string& name,
+            bool has_metar, bool is_airport, bool is_seaport, bool is_heliport);
     ~FGAirport();
 
     const string& getId() const { return _id; }
@@ -85,6 +89,9 @@ public:
     // Returns ft
     double getElevation() const { return _location.getElevationFt(); }
     bool   getMetar()     const { return _has_metar; }
+    bool   isAirport()    const { return _is_airport; }
+    bool   isSeaport()    const { return _is_seaport; }
+    bool   isHeliport()   const { return _is_heliport; }
 
     const SGGeod& getTowerLocation() const { return _tower_location; }
 
@@ -126,7 +133,8 @@ public:
 
     // add an entry to the list
     void add( const string& id, const SGGeod& location, const SGGeod& tower,
-              const string& name, const bool has_metar );
+              const string& name, bool has_metar, bool is_airport,
+              bool is_seaport, bool is_heliport );
 
     // search for the specified id.
     // Returns NULL if unsucessfull.