]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/environment_mgr.cxx
Merge branch 'next' into durk-atc
[flightgear.git] / src / Environment / environment_mgr.cxx
index c6451eef1690f14b0727d6568273d9c7d6cb1fc9..0f1b201df3f63c1f49a0781f6afffeab7e6497d0 100644 (file)
@@ -27,7 +27,6 @@
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/scene/sky/sky.hxx>
-#include <simgear/environment/visual_enviro.hxx>
 #include <simgear/scene/model/particles.hxx>
 
 #include <Main/main.hxx>
 #include "ridge_lift.hxx"
 #include "terrainsampler.hxx"
 #include "Airports/simple.hxx"
+#include "gravity.hxx"
 
 class SGSky;
 extern SGSky *thesky;
 
+class FG3DCloudsListener : public SGPropertyChangeListener {
+public:
+  FG3DCloudsListener( FGClouds * fgClouds );
+  virtual ~FG3DCloudsListener();
+
+  virtual void valueChanged (SGPropertyNode * node);
+
+private:
+  FGClouds * _fgClouds;
+  SGPropertyNode_ptr _shaderNode;
+  SGPropertyNode_ptr _enableNode;
+};
+
+FG3DCloudsListener::FG3DCloudsListener( FGClouds * fgClouds ) :
+    _fgClouds( fgClouds ) 
+{
+  _shaderNode = fgGetNode( "/sim/rendering/shader-effects", true );
+  _shaderNode->addChangeListener( this );
+
+  _enableNode = fgGetNode( "/sim/rendering/clouds3d-enable", true );
+  _enableNode->addChangeListener( this );
+
+  valueChanged( _enableNode );
+}
+
+FG3DCloudsListener::~FG3DCloudsListener()
+{
+  _enableNode->removeChangeListener( this );
+  _shaderNode->removeChangeListener( this );
+}
+
+void FG3DCloudsListener::valueChanged( SGPropertyNode * node )
+{
+  _fgClouds->set_3dClouds( _enableNode->getBoolValue() && _shaderNode->getBoolValue() );
+}
+
 FGEnvironmentMgr::FGEnvironmentMgr () :
   _environment(new FGEnvironment()),
   fgClouds(new FGClouds()),
   _cloudLayersDirty(true),
-  _altitudeNode(fgGetNode("/position/altitude-ft", true)),
+  _altitude_n(fgGetNode("/position/altitude-ft", true)),
   _longitude_n(fgGetNode( "/position/longitude-deg", true )),
   _latitude_n( fgGetNode( "/position/latitude-deg", true )),
-  _positionTimeToLive(0.0)
+  _positionTimeToLive(0.0),
+  _3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) )
 {
   set_subsystem("controller", Environment::LayerInterpolateController::createInstance( fgGetNode("/environment/config", true ) ));
   set_subsystem("realwx", Environment::RealWxController::createInstance( fgGetNode("/environment/realwx", true ) ), 1.0 );
@@ -90,6 +127,8 @@ FGEnvironmentMgr::~FGEnvironmentMgr ()
 
   delete fgClouds;
   delete _environment;
+
+  delete _3dCloudsEnableListener;
 }
 
 void
@@ -98,6 +137,14 @@ FGEnvironmentMgr::init ()
   SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
   SGSubsystemGroup::init();
   fgClouds->Init();
+
+  // FIXME: is this really part of the environment_mgr?
+  // Initialize the longitude, latitude and altitude to the initial position
+  // of the aircraft so that the atmospheric properties (pressure, temperature
+  // and density) can be initialized accordingly.
+  _altitude_n->setDoubleValue(fgGetDouble("/sim/presets/altitude-ft"));
+  _longitude_n->setDoubleValue(fgGetDouble("/sim/presets/longitude-deg"));
+  _latitude_n->setDoubleValue(fgGetDouble("/sim/presets/latitude-deg"));
 }
 
 void
@@ -122,9 +169,9 @@ FGEnvironmentMgr::bind ()
           &FGClouds::get_update_event,
           &FGClouds::set_update_event);
 
-  _tiedProperties.Tie("turbulence/use-cloud-turbulence", &sgEnviro,
-          &SGEnviro::get_turbulence_enable_state,
-          &SGEnviro::set_turbulence_enable_state);
+//  _tiedProperties.Tie("turbulence/use-cloud-turbulence", &sgEnviro,
+//          &SGEnviro::get_turbulence_enable_state,
+//          &SGEnviro::set_turbulence_enable_state);
 
   for (int i = 0; i < MAX_CLOUD_LAYERS; i++) {
       SGPropertyNode_ptr layerNode = fgGetNode("/environment/clouds",true)->getChild("layer", i, true );
@@ -164,10 +211,6 @@ FGEnvironmentMgr::bind ()
 
   _tiedProperties.setRoot( fgGetNode("/sim/rendering", true ) );
 
-  _tiedProperties.Tie( "clouds3d-enable", fgClouds,
-          &FGClouds::get_3dClouds,
-          &FGClouds::set_3dClouds);
-
   _tiedProperties.Tie( "clouds3d-density", thesky,
           &SGSky::get_3dCloudDensity,
           &SGSky::set_3dCloudDensity);
@@ -176,15 +219,10 @@ FGEnvironmentMgr::bind ()
           &SGSky::get_3dCloudVisRange,
           &SGSky::set_3dCloudVisRange);
 
-  _tiedProperties.Tie("precipitation-enable", &sgEnviro,
-          &SGEnviro::get_precipitation_enable_state,
-          &SGEnviro::set_precipitation_enable_state);
-
-  _tiedProperties.Tie("lightning-enable", &sgEnviro,
-          &SGEnviro::get_lightning_enable_state,
-          &SGEnviro::set_lightning_enable_state);
+//  _tiedProperties.Tie("lightning-enable", &sgEnviro,
+//          &SGEnviro::get_lightning_enable_state,
+//          &SGEnviro::set_lightning_enable_state);
 
-  sgEnviro.config(fgGetNode("/sim/rendering/precipitation"));
 }
 
 void
@@ -200,7 +238,7 @@ FGEnvironmentMgr::update (double dt)
 {
   SGSubsystemGroup::update(dt);
 
-  _environment->set_elevation_ft( _altitudeNode->getDoubleValue() );
+  _environment->set_elevation_ft( _altitude_n->getDoubleValue() );
 
   simgear::Particles::setWindFrom( _environment->get_wind_from_heading_deg(),
                                    _environment->get_wind_speed_kt() );
@@ -209,6 +247,14 @@ FGEnvironmentMgr::update (double dt)
     fgClouds->set_update_event( fgClouds->get_update_event()+1 );
   }
 
+
+  fgSetDouble( "/environment/gravitational-acceleration-mps2", 
+    Environment::Gravity::instance()->getGravity(SGGeod::fromDegFt(
+      _longitude_n->getDoubleValue(),
+      _latitude_n->getDoubleValue(),
+      _altitude_n->getDoubleValue()
+  )));
+
   _positionTimeToLive -= dt;
   if( _positionTimeToLive <= 0.0 )
   {