X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FEnvironment%2Fenvironment_ctrl.cxx;h=5b9cfcfb99744b5e0a72843dbb252f57ab1518d8;hb=11d15b451347674fba77648700d23c5aaec3c6c2;hp=c14b8b9bf7df226554324d9204038172689d293b;hpb=219be77f1e329b03a7dcf1d697ea2fdbf7f1a81a;p=flightgear.git diff --git a/src/Environment/environment_ctrl.cxx b/src/Environment/environment_ctrl.cxx index c14b8b9bf..5b9cfcfb9 100644 --- a/src/Environment/environment_ctrl.cxx +++ b/src/Environment/environment_ctrl.cxx @@ -264,8 +264,7 @@ FGInterpolateEnvironmentCtrl::bucket::lessThan(bucket *a, bucket *b) //////////////////////////////////////////////////////////////////////// FGMetarCtrl::FGMetarCtrl( SGSubsystem * environmentCtrl ) - : _environmentCtrl(environmentCtrl), - station_elevation_ft(0.0), + : metar_valid(false), setup_winds_aloft(true), wind_interpolation_required(true), @@ -277,7 +276,8 @@ FGMetarCtrl::FGMetarCtrl( SGSubsystem * environmentCtrl ) MaxCloudAltitudeChangeFtSec( 20.0 ), MaxCloudThicknessChangeFtSec( 50.0 ), MaxCloudInterpolationHeightFt( 5000.0 ), - MaxCloudInterpolationDeltaFt( 4000.0 ) + MaxCloudInterpolationDeltaFt( 4000.0 ), + _environmentCtrl(environmentCtrl) { windModulator = new FGBasicWindModulator(); @@ -666,9 +666,11 @@ FGMetarCtrl::update(double dt) } } } - - set_temp_at_altitude(temperature_n->getDoubleValue(), station_elevation_ft); - set_dewpoint_at_altitude(dewpoint_n->getDoubleValue(), station_elevation_ft); + { + double station_elevation_ft = station_elevation_n->getDoubleValue(); + set_temp_at_altitude(temperature_n->getDoubleValue(), station_elevation_ft); + set_dewpoint_at_altitude(dewpoint_n->getDoubleValue(), station_elevation_ft); + } //TODO: check if temperature/dewpoint have changed. This requires reinit. // Force an update of the 3D clouds @@ -823,7 +825,7 @@ void MetarThread::run() break; } - metar_fetcher->fetch( airport_id ); + metar_fetcher->fetch( airport_id ); } } #endif @@ -883,8 +885,13 @@ void FGMetarFetcher::init () */ const char * startup_airport = fgGetString("/sim/startup/options/airport"); if( *startup_airport ) { - current_airport_id = startup_airport; - fetch( current_airport_id ); + FGAirport * a = FGAirport::getByIdent( startup_airport ); + if( a ) { + SGGeod pos = SGGeod::fromDeg(a->getLongitude(), a->getLatitude()); + a = FGAirport::findClosest(pos, 10000.0, &airportWithMetarFilter); + current_airport_id = a->getId(); + fetch( current_airport_id ); + } } } @@ -985,6 +992,11 @@ void FGMetarFetcher::fetch( const string & id ) } catch (const sg_io_exception& e) { SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: " << e.getFormattedMessage().c_str() ); result = NULL; + // remove METAR flag from the airport + FGAirport * a = FGAirport::findByIdent( id ); + if( a ) a->setMetar( false ); + // immediately schedule a new search + search_timer = 0.0; } // write the metar to the property node, the rest is done by the methods tied to this property