diff --git a/src/Environment/realwx_ctrl.cxx b/src/Environment/realwx_ctrl.cxx index 86c89822e..f7d09fba7 100644 --- a/src/Environment/realwx_ctrl.cxx +++ b/src/Environment/realwx_ctrl.cxx @@ -68,7 +68,8 @@ public: virtual void update( double dt ); virtual double getTimeToLive() const { return _timeToLive; } - virtual void setTimeToLive( double value ) { _timeToLive = value; } + virtual void resetTimeToLive() + { _timeToLive = 0.00; _pollingTimer = 0.0; } // implementation of MetarDataHandler virtual void handleMetarData( const std::string & data ); @@ -245,6 +246,8 @@ void BasicRealWxController::init() void BasicRealWxController::reinit() { _wasEnabled = false; + checkNearbyMetar(); + update(0); // fetch data ASAP } void BasicRealWxController::shutdown() @@ -264,14 +267,13 @@ void BasicRealWxController::unbind() } void BasicRealWxController::update( double dt ) -{ +{ if( _enabled ) { bool firstIteration = !_wasEnabled; - // clock tick for every METAR in stock BOOST_FOREACH(LiveMetarProperties* p, _metarProperties) { // first round? All received METARs are outdated - if( firstIteration ) p->setTimeToLive( 0.0 ); + if( firstIteration ) p->resetTimeToLive(); p->update(dt); } @@ -289,7 +291,7 @@ void BasicRealWxController::addMetarAtPath(const string& propPath, const string& // already exists if (p->getStationId() != icao) { p->setStationId(icao); - p->setTimeToLive(0.0); + p->resetTimeToLive(); } return; @@ -342,7 +344,7 @@ void BasicRealWxController::checkNearbyMetar() _metarProperties[0]->getStationId() << "', new: '" << nearestAirport->ident() << "'" ); _metarProperties[0]->setStationId( nearestAirport->ident() ); - _metarProperties[0]->setTimeToLive( 0.0 ); + _metarProperties[0]->resetTimeToLive(); } } catch( sg_exception & ) { diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 96e138092..755484f34 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -815,6 +815,17 @@ void fgReInitSubsystems() // reload offsets from config defaults globals->get_viewmgr()->reinit(); + // ugly: finalizePosition waits for METAR to arrive for the new airport. + // we don't re-init the environment manager here, since historically we did + // not, and doing so seems to have other issues. All that's needed is to + // schedule METAR fetch immediately, so it's available for finalizePosition. + // So we manually extract the METAR-fetching component inside the environment + // manager, and re-init that. + SGSubsystemGroup* envMgr = static_cast(globals->get_subsystem("environment")); + if (envMgr) { + envMgr->get_subsystem("realwx")->reinit(); + } + globals->get_subsystem("time")->reinit(); // need to bind FDMshell again, since we manually unbound it above... diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx index c7c63b533..777709ccf 100644 --- a/src/Main/positioninit.cxx +++ b/src/Main/positioninit.cxx @@ -560,8 +560,8 @@ bool initPosition() bool finalizeMetar() { double hdg = fgGetDouble( "/environment/metar/base-wind-dir-deg", 9999.0 ); - string apt = fgGetString( "/sim/startup/options/airport" ); - string rwy = fgGetString( "/sim/startup/options/runway" ); + string apt = fgGetString("/sim/presets/airport-id"); + string rwy = fgGetString("/sim/presets/runway"); double strthdg = fgGetDouble( "/sim/startup/options/heading-deg", 9999.0 ); string parkpos = fgGetString( "/sim/presets/parkpos" ); bool onground = fgGetBool( "/sim/presets/onground", false ); @@ -577,11 +577,6 @@ bool finalizeMetar() } if (!fgGetBool( "/environment/metar/valid" )) { - // bit hacky - run these two subsystems. We can't run the whole - // lot since some view things aren't initialised and hence FGLight - // crashes. - globals->get_subsystem("http")->update(0.0); - globals->get_subsystem("environment")->update(0.0); return false; }