Explicitly reinit the realwx subsystem on sim-reset, so METAR is updated within the 10-second finalizePosition window.
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 );
void BasicRealWxController::reinit()
{
_wasEnabled = false;
+ checkNearbyMetar();
+ update(0); // fetch data ASAP
}
void BasicRealWxController::shutdown()
}
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);
}
// already exists
if (p->getStationId() != icao) {
p->setStationId(icao);
- p->setTimeToLive(0.0);
+ p->resetTimeToLive();
}
return;
_metarProperties[0]->getStationId() <<
"', new: '" << nearestAirport->ident() << "'" );
_metarProperties[0]->setStationId( nearestAirport->ident() );
- _metarProperties[0]->setTimeToLive( 0.0 );
+ _metarProperties[0]->resetTimeToLive();
}
}
catch( sg_exception & ) {
// 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<SGSubsystemGroup*>(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...
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 );
}
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;
}