From f8b80778011fc22d60657334628497737ce0db91 Mon Sep 17 00:00:00 2001 From: mfranz Date: Fri, 5 Oct 2007 12:59:43 +0000 Subject: [PATCH] - rename dynamics to _dynamics for consistency reasons - 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 | 52 ++++++++++++++++++------------------- src/Airports/simple.cxx | 46 ++++++++++++++++++-------------- src/Airports/simple.hxx | 14 +++++++--- 3 files changed, 63 insertions(+), 49 deletions(-) diff --git a/src/Airports/apt_loader.cxx b/src/Airports/apt_loader.cxx index a7475c708..43f350d33 100644 --- a/src/Airports/apt_loader.cxx +++ b/src/Airports/apt_loader.cxx @@ -46,31 +46,31 @@ 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); // diff --git a/src/Airports/simple.cxx b/src/Airports/simple.cxx index 0b9c39097..6efac4c0e 100644 --- a/src/Airports/simple.cxx +++ b/src/Airports/simple.cxx @@ -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() ); diff --git a/src/Airports/simple.hxx b/src/Airports/simple.hxx index cb003e3d9..9251ee423 100644 --- a/src/Airports/simple.hxx +++ b/src/Airports/simple.hxx @@ -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. -- 2.39.5