]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/fgclouds.cxx
Fix line endings
[flightgear.git] / src / Environment / fgclouds.cxx
index b61a5510147dcb78993ce8cbb42861d4738dbd4b..970a4fa9d54e6399d98dcf36f65d0e0e5f710d21 100644 (file)
 //
 //
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include <Main/fg_props.hxx>
 
 #include <simgear/constants.h>
@@ -44,10 +48,13 @@ extern SGSky *thesky;
 FGClouds::FGClouds(FGEnvironmentCtrl * controller) :
        station_elevation_ft(0.0),
        _controller( controller ),
-       snd_lightning(NULL)
+       snd_lightning(NULL),
+    last_scenario( "none" ),
+    last_env_config( new SGPropertyNode() ),
+    last_env_clouds( new SGPropertyNode() )
 {
        update_event = 0;
-       fgSetString("/environment/weather-scenario", "METAR");
+       fgSetString("/environment/weather-scenario", last_scenario.c_str());
 }
 FGClouds::~FGClouds() {
 }
@@ -62,7 +69,7 @@ void FGClouds::set_update_event(int count) {
 
 void FGClouds::init(void) {
        if( snd_lightning == NULL ) {
-               snd_lightning = new SGSoundSample(globals->get_fg_root().c_str(), "Sounds/thunder.wav", true);
+               snd_lightning = new SGSoundSample(globals->get_fg_root().c_str(), "Sounds/thunder.wav");
                snd_lightning->set_max_dist(7000.0f);
                snd_lightning->set_reference_dist(3000.0f);
                SGSoundMgr *soundMgr = globals->get_soundmgr();
@@ -71,7 +78,7 @@ void FGClouds::init(void) {
        }
 }
 
-SGNewCloud *FGClouds::buildCloud(SGPropertyNode *cloud_def_root, string name) {
+SGNewCloud *FGClouds::buildCloud(SGPropertyNode *cloud_def_root, const string& name) {
        SGPropertyNode *cld_def=NULL;
 
        cld_def = cloud_def_root->getChild(name.c_str());
@@ -100,7 +107,7 @@ SGNewCloud *FGClouds::buildCloud(SGPropertyNode *cloud_def_root, string name) {
        return cld;
 }
 
-void FGClouds::buildLayer(SGCloudField *layer, string name, double alt, double coverage) {
+void FGClouds::buildLayer(SGCloudField *layer, const string& name, double alt, double coverage) {
        struct {
                string name;
                double count;
@@ -108,8 +115,8 @@ void FGClouds::buildLayer(SGCloudField *layer, string name, double alt, double c
        int CloudVarietyCount = 0;
        double totalCount = 0.0;
 
-       SGPropertyNode *cloud_def_root = fgGetNode("/environment/config/cloudlayers/clouds", false);
-       SGPropertyNode *layer_def_root = fgGetNode("/environment/config/cloudlayers/layers", false);
+       SGPropertyNode *cloud_def_root = fgGetNode("/environment/cloudlayers/clouds", false);
+       SGPropertyNode *layer_def_root = fgGetNode("/environment/cloudlayers/layers", false);
 
        layer->clear();
        // when we don't generate clouds the layer is rendered in 2D
@@ -260,7 +267,7 @@ void FGClouds::buildMETAR(void) {
 
 // copy from FGMetarEnvironmentCtrl until better
 void
-FGClouds::update_metar_properties( FGMetar *m )
+FGClouds::update_metar_properties( const FGMetar *m )
 {
     int i;
     double d;
@@ -272,7 +279,7 @@ FGClouds::update_metar_properties( FGMetar *m )
     fgSetDouble("/environment/metar/max-visibility-m",
                 m->getMaxVisibility().getVisibility_m() );
 
-    SGMetarVisibility *dirvis = m->getDirVisibility();
+    const SGMetarVisibility *dirvis = m->getDirVisibility();
     for (i = 0; i < 8; i++, dirvis++) {
         const char *min = "/environment/metar/visibility[%d]/min-m";
         const char *max = "/environment/metar/visibility[%d]/max-m";
@@ -303,7 +310,7 @@ FGClouds::update_metar_properties( FGMetar *m )
                 m->getPressure_inHg() );
 
     vector<SGMetarCloud> cv = m->getClouds();
-    vector<SGMetarCloud>::iterator cloud;
+    vector<SGMetarCloud>::const_iterator cloud;
 
     const char *cl = "/environment/clouds/layer[%i]";
     for (i = 0, cloud = cv.begin(); cloud != cv.end(); cloud++, i++) {
@@ -375,7 +382,7 @@ FGClouds::update_env_config ()
 }
 
 
-void FGClouds::setLayer( int iLayer, float alt_ft, string coverage, string layer_type ) {
+void FGClouds::setLayer( int iLayer, float alt_ft, const string& coverage, const string& layer_type ) {
        double coverage_norm = 0.0;
        if( coverage == "few" )
                coverage_norm = 2.0/8.0;        // <1-2
@@ -390,13 +397,17 @@ void FGClouds::setLayer( int iLayer, float alt_ft, string coverage, string layer
        buildLayer(layer3D, layer_type, station_elevation_ft + alt_ft * SG_FEET_TO_METER, coverage_norm);
 }
 
-void FGClouds::buildScenario( string scenario ) {
+void FGClouds::buildScenario( const string& scenario ) {
        string fakeMetar="";
        string station = fgGetString("/environment/metar/station-id", "XXXX");
 
        // fetch station elevation if exists
-    FGAirport a = globals->get_airports()->search( station );
-    station_elevation_ft = a.getElevation();
+    if( station == "XXXX" )
+        station_elevation_ft = fgGetDouble("/position/ground-elev-m", 0.0);
+    else {
+        const FGAirport* a = globals->get_airports()->search( station );
+        station_elevation_ft = (a ? a->getElevation() : 0.0);
+    }
 
        for(int iLayer = 0 ; iLayer < thesky->get_cloud_layer_count(); iLayer++) {
                thesky->get_cloud_layer(iLayer)->get_layer3D()->clear();
@@ -429,6 +440,15 @@ void FGClouds::buildScenario( string scenario ) {
 void FGClouds::build(void) {
        string scenario = fgGetString("/environment/weather-scenario", "METAR");
 
+    if( scenario == last_scenario)
+        return;
+    if( last_scenario == "none" ) {
+        // save clouds and weather conditions
+        SGPropertyNode *param = fgGetNode("/environment/config", true);
+        copyProperties( param, last_env_config );
+        param = fgGetNode("/environment/clouds", true);
+        copyProperties( param, last_env_clouds );
+    }
        if( scenario == "METAR" ) {
                string realMetar = fgGetString("/environment/metar/real-metar", "");
                if( realMetar != "" ) {
@@ -441,8 +461,22 @@ void FGClouds::build(void) {
                }
                buildMETAR();
        }
+    else if( scenario == "none" ) {
+        // restore clouds and weather conditions
+        SGPropertyNode *param = fgGetNode("/environment/config", true);
+        copyProperties( last_env_config, param );
+        param = fgGetNode("/environment/clouds", true);
+        copyProperties( last_env_clouds, param );
+        fgSetDouble("/environment/metar/rain-norm", 0.0);
+        fgSetDouble("/environment/metar/snow-norm", 0.0);
+//         update_env_config();
+           // propagate aloft tables
+           _controller->reinit();
+               buildMETAR();
+    }
        else
                buildScenario( scenario );
+    last_scenario = scenario;
 
        // ...
        if( snd_lightning == NULL )