]> git.mxchange.org Git - flightgear.git/commitdiff
Stuart Buchanan :
authorfredb <fredb>
Sat, 6 Dec 2008 23:03:12 +0000 (23:03 +0000)
committerfredb <fredb>
Sat, 6 Dec 2008 23:03:12 +0000 (23:03 +0000)
- Replaces simple shader attributes with vectors (this was missed out of the last patch by mistake)
- Includes Yon's Fog update code (Thanks!)
- Fixes a bug since 1.0 where --enable-real-weather-fetch stopped the other weather scenarios from working.

src/Environment/environment_ctrl.cxx
src/Environment/environment_ctrl.hxx
src/Environment/fgclouds.cxx
src/Environment/fgclouds.hxx

index 1d70724afdc9fb3c804b798f8011ffd979341ae8..4a5bd263339cac721458b46a1c72b94de163169b 100644 (file)
@@ -348,6 +348,7 @@ FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
       MaxCloudAltitudeChangeFtSec( 20.0 ),
       MaxCloudThicknessChangeFtSec( 50.0 ),
       MaxCloudInterpolationHeightFt( 5000.0 ),
+      MaxCloudInterpolationDeltaFt( 4000.0 ),
 
       _error_count( 0 ),
       _stale_count( 0 ),
@@ -404,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 (fgGetString("/environment/weather-scenario", "METAR") != "METAR") return;
 
     if (metar_loaded) {
         // Generate interpolated values between the METAR and the current
@@ -521,12 +525,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)
@@ -684,10 +691,7 @@ FGMetarEnvironmentCtrl::reinit ()
 {
     _error_count = 0;
     _error_dt = 0.0;
-
-#if 0
-    update_env_config();
-#endif
+    metar_loaded = false;
 
     env->reinit();
 }
index d06a7d108265eef8a1bb1ec503727f20f754687f..cc2449cae2c56b61af4aed1f1a1c9f9892d4a567 100644 (file)
@@ -198,6 +198,10 @@ private:
                                                 // interpolate at. Any cloud
                                                 // changes above this height
                                                 // difference are not interpolated
+    const double MaxCloudInterpolationDeltaFt;  // Max difference in altitude to 
+                                                // interpolate. Any cloud changing height
+                                                // by more than this value is not 
+                                                // interpolated
 
 private:
 
index ae35c5074c9e0cab69d68bac8fbfb6f19c7c3362..0f414321a9ac4ab76207a5ba3b0d29f86721cf5b 100644 (file)
@@ -212,7 +212,7 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
                }
        }
        totalCount = 1.0 / totalCount;
-
+        
        for(double px = 0.0; px < SGCloudField::fieldSize; px += grid_x_size) {
                for(double py = 0.0; py < SGCloudField::fieldSize; py += grid_y_size) {
                        double x = px + grid_x_rand * (sg_random() - 0.5) - (SGCloudField::fieldSize / 2.0);
@@ -238,7 +238,7 @@ void FGClouds::buildLayer(int iLayer, const string& name, double alt, double cov
 }
 
 // TODO:call this after real metar updates
-void FGClouds::buildMETAR(void) {
+void FGClouds::buildCloudLayers(void) {
        SGPropertyNode *metar_root = fgGetNode("/environment", true);
         
        double wind_speed_kt     = metar_root->getDoubleValue("wind-speed-kt");
@@ -261,8 +261,9 @@ void FGClouds::buildMETAR(void) {
 
                double alt_ft = cloud_root->getDoubleValue("elevation-ft");
                double alt_m = alt_ft * SG_FEET_TO_METER;
-                printf("Alt m: %.0f\n", alt_m);
                 string coverage = cloud_root->getStringValue("coverage");
+                
+                
                double coverage_norm = 0.0;
                if( coverage == "few" )
                        coverage_norm = 2.0/8.0;        // <1-2
@@ -312,6 +313,7 @@ void
 FGClouds::update_metar_properties( const FGMetar *m )
 {
     int i;
+    int j;
     double d;
     char s[128];
 
@@ -354,47 +356,55 @@ FGClouds::update_metar_properties( const FGMetar *m )
     vector<SGMetarCloud> cv = m->getClouds();
     vector<SGMetarCloud>::const_iterator cloud;
 
-    const char *cl = "/environment/clouds/layer[%i]";
-    for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {
-        const char *coverage_string[5] = 
-            { "clear", "few", "scattered", "broken", "overcast" };
-        const double thickness[5] = { 0, 65, 600,750, 1000};
-        int q;
-
-        snprintf(s, 128, cl, i);
-        strncat(s, "/coverage", 128);
-        q = cloud->getCoverage();
-        fgSetString(s, coverage_string[q] );
-
-        snprintf(s, 128, cl, i);
-        strncat(s, "/elevation-ft", 128);
-        fgSetDouble(s, cloud->getAltitude_ft() + station_elevation_ft);
-
-        snprintf(s, 128, cl, i);
-        strncat(s, "/thickness-ft", 128);
-        fgSetDouble(s, thickness[q]);
-
-        snprintf(s, 128, cl, i);
-        strncat(s, "/span-m", 128);
-        fgSetDouble(s, 40000.0);
-    }
-
-    for (; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
-        snprintf(s, 128, cl, i);
-        strncat(s, "/coverage", 128);
-        fgSetString(s, "clear");
-
-        snprintf(s, 128, cl, i);
-        strncat(s, "/elevation-ft", 128);
-        fgSetDouble(s, -9999);
-
-        snprintf(s, 128, cl, i);
-        strncat(s, "/thickness-ft", 128);
-        fgSetDouble(s, 0);
-
-        snprintf(s, 128, cl, i);
-        strncat(s, "/span-m", 128);
-        fgSetDouble(s, 40000.0);
+    // Load into both the METAR and environment properties to stop interpolation
+    const char *cl[] = {"/environment/metar/clouds/layer[%i]",
+                        "/environment/clouds/layer[%i]"};
+
+    for (j = 0; j < 2; j++)
+    {
+        for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {
+            const char *coverage_string[5] = 
+                { "clear", "few", "scattered", "broken", "overcast" };
+            const double thickness[5] = { 0, 65, 600,750, 1000};
+            int q;
+    
+            snprintf(s, 128, cl[j], i);
+            strncat(s, "/coverage", 128);
+            q = cloud->getCoverage();
+            fgSetString(s, coverage_string[q] );
+            
+            snprintf(s, 128, cl[j], i);
+            strncat(s, "/elevation-ft", 128);
+            fgSetDouble(s, cloud->getAltitude_ft() + station_elevation_ft);
+            
+            snprintf(s, 128, cl[j], i);
+            strncat(s, "/thickness-ft", 128);
+            fgSetDouble(s, thickness[q]);
+            
+            snprintf(s, 128, cl[j], i);
+            strncat(s, "/span-m", 128);
+            fgSetDouble(s, 40000.0);
+        }
+    
+        for (; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
+            
+            
+            snprintf(s, 128, cl[j], i);
+            strncat(s, "/coverage", 128);
+            fgSetString(s, "clear");
+    
+            snprintf(s, 128, cl[j], i);
+            strncat(s, "/elevation-ft", 128);
+            fgSetDouble(s, -9999);
+    
+            snprintf(s, 128, cl[j], i);
+            strncat(s, "/thickness-ft", 128);
+            fgSetDouble(s, 0);
+    
+            snprintf(s, 128, cl[j], i);
+            strncat(s, "/span-m", 128);
+            fgSetDouble(s, 40000.0);
+        }
     }
 
     fgSetDouble("/environment/metar/rain-norm", m->getRain());
@@ -441,7 +451,7 @@ void FGClouds::setLayer( int iLayer, float alt_ft, const string& coverage, const
 void FGClouds::buildScenario( const string& scenario ) {
        string fakeMetar="";
        string station = fgGetString("/environment/metar/station-id", "XXXX");
-
+        
        // fetch station elevation if exists
         if( station == "XXXX" )
             station_elevation_ft = fgGetDouble("/position/ground-elev-m", 0.0);
@@ -459,7 +469,7 @@ void FGClouds::buildScenario( const string& scenario ) {
        station += " 011000Z ";
        if( scenario == "Fair weather" ) {
                fakeMetar = "15003KT 12SM SCT033 FEW200 20/08 Q1015 NOSIG";
-               setLayer(0, 3300.0, "scattered", "cu");
+               //setLayer(0, 3300.0, "scattered", "cu");
         } else if( scenario == "Thunderstorm" ) {
                fakeMetar = "15012KT 08SM TSRA SCT040 BKN070 20/12 Q0995";
                setLayer(0, 4000.0, "scattered", "cb");
@@ -470,10 +480,10 @@ void FGClouds::buildScenario( const string& scenario ) {
        update_metar_properties( m );
        update_env_config();
        // propagate aloft tables
-       _controller->reinit();
+       //_controller->reinit();
 
        fgSetString("/environment/metar/last-metar", m->getData());
-       // TODO:desactivate real metar updates
+       // TODO:de-activate real metar updates
        if( scenario == "Fair weather" ) {
                fgSetString("/environment/clouds/layer[1]/coverage", "cirrus");
        }
@@ -493,6 +503,7 @@ void FGClouds::build() {
             param = fgGetNode("/environment/clouds", true);
             copyProperties( param, last_env_clouds );
         }
+                
         if( scenario == "METAR" ) {
             string realMetar = fgGetString("/environment/metar/real-metar", "");
             if( realMetar != "" ) {
@@ -502,8 +513,8 @@ void FGClouds::build() {
                 update_env_config();
                        // propagate aloft tables
                 _controller->reinit();
+                buildCloudLayers();
             }
-            buildMETAR();
         }
         else if( scenario == "none" ) {
         // restore clouds and weather conditions
@@ -516,15 +527,17 @@ void FGClouds::build() {
 //         update_env_config();
            // propagate aloft tables
             _controller->reinit();
-            buildMETAR();
+            buildCloudLayers();
         }
-        else
+        else {
             buildScenario( scenario );
+            _controller->reinit();
+            buildCloudLayers();
+        }
         
         last_scenario = scenario;
         rebuild_required = false;
 
-       // ...
         if( snd_lightning == NULL )
             init();
 }
index 9e8f7c92c77003aaddb61777e7d24cb36673e7a9..dff1f8fd0cc6a0ffd4959644d1c8755e1661efa4 100644 (file)
@@ -45,7 +45,7 @@ private:
 void buildCloud(SGPropertyNode *cloud_def_root, SGPropertyNode *box_def_root, const string& name, sgVec3 pos, SGCloudField *layer);
        void buildLayer(int iLayer, const string& name, double alt, double coverage);
 
-       void buildMETAR(void);
+       void buildCloudLayers(void);
 
        void buildScenario( const string& scenario );