]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/environment_ctrl.cxx
Merge branch 'releng/1.9.1' into maint
[flightgear.git] / src / Environment / environment_ctrl.cxx
index 5733ed67a3f3d3f21e103b17e80994cc27498956..5d4494b051da8a7030c5f5b6e94f9d7599382ee9 100644 (file)
 #include "environment_mgr.hxx"
 #include "environment_ctrl.hxx"
 
-SG_USING_STD(sort);
+using std::sort;
 
 class metar_filter : public FGAirportSearchFilter {
-    virtual bool acceptable(FGAirport *a) { return a->getMetar(); }
+    virtual bool pass(FGAirport *a) { return a->getMetar(); }
 } metar_only;
 
 \f
@@ -348,6 +348,7 @@ FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
       MaxCloudAltitudeChangeFtSec( 20.0 ),
       MaxCloudThicknessChangeFtSec( 50.0 ),
       MaxCloudInterpolationHeightFt( 5000.0 ),
+      MaxCloudInterpolationDeltaFt( 4000.0 ),
 
       _error_count( 0 ),
       _stale_count( 0 ),
@@ -356,7 +357,8 @@ FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
 {
 #if defined(ENABLE_THREADS)
     thread = new MetarThread(this);
-    thread->start( 1 );
+    thread->setProcessorAffinity(1);
+    thread->start();
 #endif // ENABLE_THREADS
 }
 
@@ -403,6 +405,9 @@ FGMetarEnvironmentCtrl::update_env_config ()
     double pressure;
     double temp;
     double dewpoint;
+    
+    // If we aren't in the METAR scenario, don't attempt to interpolate.
+    if (strcmp(fgGetString("/environment/weather-scenario", "METAR"), "METAR")) return;
 
     if (metar_loaded) {
         // Generate interpolated values between the METAR and the current
@@ -431,15 +436,19 @@ FGMetarEnvironmentCtrl::update_env_config ()
         // factor by the maximum wind change.
         double x = fabs(current[0] - metar[0]);
         double y = fabs(current[1] - metar[1]);
-        double dx = x / (x + y);
-        double dy = 1 - dx;
 
-        double maxdx = dx * MaxWindChangeKtsSec;
-        double maxdy = dy * MaxWindChangeKtsSec;
+        // only interpolate if we have a difference
+        if (x + y > 0) {
+            double dx = x / (x + y);
+            double dy = 1 - dx;
 
-        // Interpolate each component separately.
-        current[0] = interpolate_val(current[0], metar[0], maxdx);
-        current[1] = interpolate_val(current[1], metar[1], maxdy);
+            double maxdx = dx * MaxWindChangeKtsSec;
+            double maxdy = dy * MaxWindChangeKtsSec;
+
+            // Interpolate each component separately.
+            current[0] = interpolate_val(current[0], metar[0], maxdx);
+            current[1] = interpolate_val(current[1], metar[1], maxdy);
+        }
 
         // Now convert back to polar coordinates.
         if ((current[0] == 0.0) && (current[1] == 0.0)) {
@@ -520,12 +529,15 @@ FGMetarEnvironmentCtrl::update_env_config ()
             double current_alt = fgGetDouble(s);
             double required_alt = (*layer)->getDoubleValue("elevation-ft");
 
-            if (current_alt < -9000 || required_alt < -9000
-                    || fabs(aircraft_alt - required_alt) > MaxCloudInterpolationHeightFt) {
-                // We don't interpolate any values that are too high above us,
-                // or too far below us to be visible. Nor do we interpolate
-                // values to or from -9999, which is used as a placeholder
-                // when there isn't actually a cloud layer present.
+            if (current_alt < -9000 || required_alt < -9000 ||
+                fabs(aircraft_alt - required_alt) > MaxCloudInterpolationHeightFt ||
+                fabs(current_alt - required_alt) > MaxCloudInterpolationDeltaFt) {
+                // We don't interpolate any layers that are
+                //  - too far above us to be visible
+                //  - too far below us to be visible
+                //  - with too large a difference to make interpolation sensible
+                //  - to or from -9999 (used as a placeholder)
+                //  - any values that are too high above us,
                 snprintf(s, 128, cl, i);
                 strncat(s, "/elevation-ft", 128);
                 if (current_alt != required_alt)
@@ -571,7 +583,7 @@ FGMetarEnvironmentCtrl::update_env_config ()
         dewpoint = fgGetDouble("/environment/metar/dewpoint-degc");
 
         // Set the cloud layers by copying over the METAR versions.
-        SGPropertyNode * clouds = fgGetNode("/environment/metar/clouds");
+        SGPropertyNode * clouds = fgGetNode("/environment/metar/clouds", true);
 
         vector<SGPropertyNode_ptr> layers = clouds->getChildren("layer");
         vector<SGPropertyNode_ptr>::const_iterator layer;
@@ -598,6 +610,9 @@ FGMetarEnvironmentCtrl::update_env_config ()
             strncat(s, "/span-m", 128);
             fgSetDouble(s, 40000.0);
         }
+
+        // Force an update of the 3D clouds
+        fgSetDouble("/environment/rebuild-layers", 1.0);
     }
 
     fgSetupWind(dir_from, dir_to, speed, gust);
@@ -651,6 +666,7 @@ FGMetarEnvironmentCtrl::init ()
         const FGAirport* a = globals->get_airports()
                    ->search( longitude->getDoubleValue(),
                              latitude->getDoubleValue(),
+                             360.0,
                              metar_only );
         if ( a ) {  
             FGMetarResult result = fetch_data( a->getId() );
@@ -682,10 +698,7 @@ FGMetarEnvironmentCtrl::reinit ()
 {
     _error_count = 0;
     _error_dt = 0.0;
-
-#if 0
-    update_env_config();
-#endif
+    metar_loaded = false;
 
     env->reinit();
 }
@@ -714,6 +727,7 @@ FGMetarEnvironmentCtrl::update(double delta_time_sec)
         const FGAirport* a = globals->get_airports()
                    ->search( longitude->getDoubleValue(),
                              latitude->getDoubleValue(),
+                             360.0,
                              metar_only );
         if ( a ) {
             if ( !last_apt || last_apt->getId() != a->getId()