]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/environment_mgr.cxx
Added support for shared JSBSim engine and system configurations in fgdata.
[flightgear.git] / src / Environment / environment_mgr.cxx
index f13d9e88f87e61444d85eb4cd6fe5581c2264870..27066408ea5e21009f7e560362ee3d53cef71637 100644 (file)
@@ -43,8 +43,9 @@
 #include "precipitation_mgr.hxx"
 #include "ridge_lift.hxx"
 #include "terrainsampler.hxx"
-#include "Airports/simple.hxx"
+#include "Airports/airport.hxx"
 #include "gravity.hxx"
+#include "magvarmanager.hxx"
 
 class FG3DCloudsListener : public SGPropertyChangeListener {
 public:
@@ -81,9 +82,6 @@ FGEnvironmentMgr::FGEnvironmentMgr () :
   _environment(new FGEnvironment()),
   fgClouds(new FGClouds()),
   _cloudLayersDirty(true),
-  _altitude_n(fgGetNode("/position/altitude-ft", true)),
-  _longitude_n(fgGetNode( "/position/longitude-deg", true )),
-  _latitude_n( fgGetNode( "/position/latitude-deg", true )),
   _3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) ),
   _sky(globals->get_renderer()->getSky())
 {
@@ -93,61 +91,43 @@ FGEnvironmentMgr::FGEnvironmentMgr () :
   set_subsystem("precipitation", new FGPrecipitationMgr);
   set_subsystem("terrainsampler", Environment::TerrainSampler::createInstance( fgGetNode("/environment/terrain", true ) ));
   set_subsystem("ridgelift", new FGRidgeLift);
+  
+  set_subsystem("magvar", new FGMagVarManager);
 }
 
 FGEnvironmentMgr::~FGEnvironmentMgr ()
 {
-  SGSubsystem * subsys;
-
-  subsys = get_subsystem( "ridgelift" );
   remove_subsystem( "ridgelift" );
-  delete subsys;
-
-  subsys = get_subsystem( "terrainsampler" );
   remove_subsystem( "terrainsampler" );
-  delete subsys;
-
-  subsys = get_subsystem( "precipitation" );
   remove_subsystem("precipitation");
-  delete subsys;
-
-  subsys = get_subsystem("realwx");
   remove_subsystem("realwx");
-  delete subsys;
-
-  subsys = get_subsystem("controller");
   remove_subsystem("controller");
-  delete subsys;
-
+  remove_subsystem("magvar");
+  
   delete fgClouds;
   delete _environment;
 
   delete _3dCloudsEnableListener;
 }
 
-void
-FGEnvironmentMgr::init ()
+SGSubsystem::InitStatus FGEnvironmentMgr::incrementalInit()
 {
-  SG_LOG( SG_ENVIRONMENT, 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"));
   
-  globals->get_event_mgr()->addTask("updateClosestAirport", this,
-                                    &FGEnvironmentMgr::updateClosestAirport, 30 );
+  InitStatus r = SGSubsystemGroup::incrementalInit();
+  if (r == INIT_DONE) {
+    fgClouds->Init();
+    globals->get_event_mgr()->addTask("updateClosestAirport", this,
+                                      &FGEnvironmentMgr::updateClosestAirport, 30 );
+  }
+  
+  return r;
 }
 
 void
 FGEnvironmentMgr::shutdown()
 {
   globals->get_event_mgr()->removeTask("updateClosestAirport");
+  SGSubsystemGroup::shutdown();
 }
 
 void
@@ -242,14 +222,6 @@ FGEnvironmentMgr::bind ()
           &SGSky::get_3dCloudUseImpostors,
           &SGSky::set_3dCloudUseImpostors);
 
-  _tiedProperties.Tie("minimum-sky-visibility", _sky,
-          &SGSky::get_minimum_sky_visibility,
-          &SGSky::set_minimum_sky_visibility);
-
-//  _tiedProperties.Tie("lightning-enable", &sgEnviro,
-//          &SGEnviro::get_lightning_enable_state,
-//          &SGEnviro::set_lightning_enable_state);
-
 }
 
 void
@@ -265,7 +237,8 @@ FGEnvironmentMgr::update (double dt)
 {
   SGSubsystemGroup::update(dt);
 
-  _environment->set_elevation_ft( _altitude_n->getDoubleValue() );
+    SGGeod aircraftPos(globals->get_aircraft_position());
+  _environment->set_elevation_ft( aircraftPos.getElevationFt() );
 
   simgear::Particles::setWindFrom( _environment->get_wind_from_heading_deg(),
                                    _environment->get_wind_speed_kt() );
@@ -276,11 +249,7 @@ FGEnvironmentMgr::update (double dt)
 
 
   fgSetDouble( "/environment/gravitational-acceleration-mps2", 
-    Environment::Gravity::instance()->getGravity(SGGeod::fromDegFt(
-      _longitude_n->getDoubleValue(),
-      _latitude_n->getDoubleValue(),
-      _altitude_n->getDoubleValue()
-  )));
+    Environment::Gravity::instance()->getGravity(aircraftPos));
 }
 
 void