]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/environment_mgr.cxx
Ima Sudonim:
[flightgear.git] / src / Environment / environment_mgr.cxx
index b57fec1133db5bcbf7fff412e49bb393de26f93b..2275a47955d87732ead9fb8f8a5e8082332f286c 100644 (file)
 //
 // $Id$
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/debug/logstream.hxx>
 #include <simgear/scene/sky/sky.hxx>
+#include <simgear/environment/visual_enviro.hxx>
 
 #include <Main/main.hxx>
 #include <Main/fg_props.hxx>
 #include "environment.hxx"
 #include "environment_ctrl.hxx"
 #include "environment_mgr.hxx"
+#include "fgclouds.hxx"
+
+class SGSky;
+extern SGSky *thesky;
+
 
 
 FGEnvironmentMgr::FGEnvironmentMgr ()
-  : _environment(new FGEnvironment),
-    _controller(new FGInterpolateEnvironmentCtrl)
+  : _environment(new FGEnvironment)
 {
+
+   if (fgGetBool("/environment/params/real-world-weather-fetch") == true)
+       _controller = new FGMetarEnvironmentCtrl;
+   else
+       _controller = new FGInterpolateEnvironmentCtrl;
+
   _controller->setEnvironment(_environment);
   set_subsystem("controller", _controller, 0.5);
+  fgClouds = new FGClouds( _controller );
 }
 
 FGEnvironmentMgr::~FGEnvironmentMgr ()
 {
   delete _environment;
   delete _controller;
+  delete fgClouds;
 }
 
 void
 FGEnvironmentMgr::init ()
 {
   SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
-  FGSubsystemGroup::init();
+  SGSubsystemGroup::init();
   _update_fdm();
 }
 
@@ -58,7 +75,7 @@ void
 FGEnvironmentMgr::reinit ()
 {
   SG_LOG( SG_GENERAL, SG_INFO, "Reinitializing environment subsystem");
-  FGSubsystemGroup::reinit();
+  SGSubsystemGroup::reinit();
   _update_fdm();
 }
 
@@ -74,6 +91,8 @@ FGEnvironmentMgr::bind ()
   fgSetArchivable("/environment/temperature-sea-level-degc");
   fgTie("/environment/temperature-degc", _environment,
        &FGEnvironment::get_temperature_degc); // FIXME: read-only for now
+  fgTie("/environment/temperature-degf", _environment,
+       &FGEnvironment::get_temperature_degf); // FIXME: read-only for now
   fgTie("/environment/dewpoint-sea-level-degc", _environment,
        &FGEnvironment::get_dewpoint_sea_level_degc,
        &FGEnvironment::set_dewpoint_sea_level_degc);
@@ -142,6 +161,33 @@ FGEnvironmentMgr::bind ()
          &FGEnvironmentMgr::set_cloud_layer_coverage);
     fgSetArchivable(buf);
   }
+  fgTie("/sim/rendering/clouds3d-enable", &sgEnviro,
+         &SGEnviro::get_clouds_enable_state,
+         &SGEnviro::set_clouds_enable_state);
+  fgTie("/sim/rendering/clouds3d-vis-range", &sgEnviro,
+         &SGEnviro::get_clouds_visibility,
+         &SGEnviro::set_clouds_visibility);
+  fgTie("/sim/rendering/clouds3d-density", &sgEnviro,
+         &SGEnviro::get_clouds_density,
+         &SGEnviro::set_clouds_density);
+  fgTie("/sim/rendering/clouds3d-cache-size", &sgEnviro,
+         &SGEnviro::get_clouds_CacheSize,
+         &SGEnviro::set_clouds_CacheSize);
+  fgTie("/sim/rendering/clouds3d-cache-resolution", &sgEnviro,
+         &SGEnviro::get_CacheResolution,
+         &SGEnviro::set_CacheResolution);
+  fgTie("/sim/rendering/precipitation-enable", &sgEnviro,
+         &SGEnviro::get_precipitation_enable_state,
+         &SGEnviro::set_precipitation_enable_state);
+  fgTie("/environment/rebuild_layers", fgClouds,
+      &FGClouds::get_update_event,
+      &FGClouds::set_update_event);
+  fgTie("/sim/rendering/lightning-enable", &sgEnviro,
+      &SGEnviro::get_lightning_enable_state,
+      &SGEnviro::set_lightning_enable_state);
+  fgTie("/environment/turbulence/use-cloud-turbulence", &sgEnviro,
+      &SGEnviro::get_turbulence_enable_state,
+      &SGEnviro::set_turbulence_enable_state);
 }
 
 void
@@ -171,12 +217,21 @@ FGEnvironmentMgr::unbind ()
     sprintf(buf, "/environment/clouds/layer[%d]/type", i);
     fgUntie(buf);
   }
+  fgUntie("/sim/rendering/clouds3d-enable");
+  fgUntie("/sim/rendering/clouds3d-vis-range");
+  fgUntie("/sim/rendering/clouds3d-density");
+  fgUntie("/sim/rendering/clouds3d-cache-size");
+  fgUntie("/sim/rendering/clouds3d-cache-resolution");
+  fgUntie("/sim/rendering/precipitation-enable");
+  fgUntie("/environment/rebuild_layers");
+  fgUntie("/sim/rendering/lightning-enable");
+  fgUntie("/environment/turbulence/use-cloud-turbulence");
 }
 
 void
 FGEnvironmentMgr::update (double dt)
 {
-  FGSubsystemGroup::update(dt);
+  SGSubsystemGroup::update(dt);
 
                                // FIXME: the FDMs should update themselves
   current_aircraft.fdm_state
@@ -247,8 +302,17 @@ FGEnvironmentMgr::get_cloud_layer_elevation_ft (int index) const
 void
 FGEnvironmentMgr::set_cloud_layer_elevation_ft (int index, double elevation_ft)
 {
+  FGEnvironment env = *_environment;
+  env.set_elevation_ft(elevation_ft);
+
   thesky->get_cloud_layer(index)
     ->setElevation_m(elevation_ft * SG_FEET_TO_METER);
+
+  thesky->get_cloud_layer(index)
+    ->setSpeed(env.get_wind_speed_kt() * 0.5151);      // 1 kt = 0.5151 m/s
+
+  thesky->get_cloud_layer(index)
+    ->setDirection(env.get_wind_from_heading_deg());
 }
 
 double