1
0
Fork 0

METAR selection of runway works for reset.

Explicitly reinit the realwx subsystem on sim-reset, so METAR is updated within the 10-second finalizePosition window.
This commit is contained in:
James Turner 2012-12-16 15:05:21 +00:00
parent 32a1c018e4
commit 2905c96f47
3 changed files with 21 additions and 13 deletions

View file

@ -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 & ) {

View file

@ -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<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...

View file

@ -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;
}