]> git.mxchange.org Git - flightgear.git/commitdiff
METAR selection of runway works for reset.
authorJames Turner <zakalawe@mac.com>
Sun, 16 Dec 2012 15:05:21 +0000 (15:05 +0000)
committerJames Turner <zakalawe@mac.com>
Sun, 16 Dec 2012 15:05:21 +0000 (15:05 +0000)
Explicitly reinit the realwx subsystem on sim-reset, so METAR is updated within the 10-second finalizePosition window.

src/Environment/realwx_ctrl.cxx
src/Main/fg_init.cxx
src/Main/positioninit.cxx

index 86c89822e9ac538774afd5d3ae4313c4c3579624..f7d09fba72bd2bd60f5aea1af702cdeb9070a2da 100644 (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 & ) {
index 96e13809254aa3ae35fb1c88b2be1c09f968bc90..755484f34ead3f5172394ca281f9b087e9fb3575 100644 (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...
index c7c63b5336f586c7079d4448672a076ff7f12675..777709ccf9845b988700dba9b67332bd47be1cc5 100644 (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;
     }