]> git.mxchange.org Git - flightgear.git/blobdiff - src/Environment/environment_mgr.cxx
Make environment-manager closest airport updating quieter, and use an event instead...
[flightgear.git] / src / Environment / environment_mgr.cxx
index 0f1b201df3f63c1f49a0781f6afffeab7e6497d0..fd1804f2f59cb43ea4564dee0fb422bed7fe27c4 100644 (file)
@@ -28,6 +28,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/scene/sky/sky.hxx>
 #include <simgear/scene/model/particles.hxx>
+#include <simgear/structure/event_mgr.hxx>
 
 #include <Main/main.hxx>
 #include <Main/fg_props.hxx>
@@ -90,7 +91,6 @@ FGEnvironmentMgr::FGEnvironmentMgr () :
   _altitude_n(fgGetNode("/position/altitude-ft", true)),
   _longitude_n(fgGetNode( "/position/longitude-deg", true )),
   _latitude_n( fgGetNode( "/position/latitude-deg", true )),
-  _positionTimeToLive(0.0),
   _3dCloudsEnableListener(new FG3DCloudsListener(fgClouds) )
 {
   set_subsystem("controller", Environment::LayerInterpolateController::createInstance( fgGetNode("/environment/config", true ) ));
@@ -134,7 +134,7 @@ FGEnvironmentMgr::~FGEnvironmentMgr ()
 void
 FGEnvironmentMgr::init ()
 {
-  SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
+  SG_LOG( SG_ENVIRONMENT, SG_INFO, "Initializing environment subsystem");
   SGSubsystemGroup::init();
   fgClouds->Init();
 
@@ -145,12 +145,21 @@ FGEnvironmentMgr::init ()
   _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 );
+}
+
+void
+FGEnvironmentMgr::shutdown()
+{
+  globals->get_event_mgr()->removeTask("updateClosestAirport");
 }
 
 void
 FGEnvironmentMgr::reinit ()
 {
-  SG_LOG( SG_GENERAL, SG_INFO, "Reinitializing environment subsystem");
+  SG_LOG( SG_ENVIRONMENT, SG_INFO, "Reinitializing environment subsystem");
   SGSubsystemGroup::reinit();
 }
 
@@ -219,6 +228,10 @@ FGEnvironmentMgr::bind ()
           &SGSky::get_3dCloudVisRange,
           &SGSky::set_3dCloudVisRange);
 
+  _tiedProperties.Tie("clouds3d-wrap", thesky,
+          &SGSky::get_3dCloudWrap,
+          &SGSky::set_3dCloudWrap);
+
 //  _tiedProperties.Tie("lightning-enable", &sgEnviro,
 //          &SGEnviro::get_lightning_enable_state,
 //          &SGEnviro::set_lightning_enable_state);
@@ -254,33 +267,30 @@ FGEnvironmentMgr::update (double dt)
       _latitude_n->getDoubleValue(),
       _altitude_n->getDoubleValue()
   )));
+}
 
-  _positionTimeToLive -= dt;
-  if( _positionTimeToLive <= 0.0 )
+void
+FGEnvironmentMgr::updateClosestAirport()
+{
+  SG_LOG(SG_ENVIRONMENT, SG_DEBUG, "FGEnvironmentMgr::update: updating closest airport");
+  
+  SGGeod pos = globals->get_aircraft_position();
+  FGAirport * nearestAirport = FGAirport::findClosest(pos, 100.0);
+  if( nearestAirport == NULL )
   {
-      // update closest airport information
-      _positionTimeToLive = 30.0;
-
-      SG_LOG(SG_ALL, SG_INFO, "FGEnvironmentMgr::update: updating closest airport");
-
-      SGGeod pos = SGGeod::fromDeg(_longitude_n->getDoubleValue(),
-                                   _latitude_n->getDoubleValue());
-
-      FGAirport * nearestAirport = FGAirport::findClosest(pos, 100.0);
-      if( nearestAirport == NULL )
-      {
-          SG_LOG(SG_ALL,SG_WARN,"FGEnvironmentMgr::update: No airport within 100NM range");
-      }
-      else
-      {
-          const string currentId = fgGetString("/sim/airport/closest-airport-id", "");
-          if (currentId != nearestAirport->ident())
-          {
-              fgSetString("/sim/airport/closest-airport-id",
-                      nearestAirport->ident().c_str());
-          }
-      }
+    SG_LOG(SG_ENVIRONMENT,SG_WARN,"FGEnvironmentMgr::update: No airport within 100NM range");
   }
+  else
+  {
+    const string currentId = fgGetString("/sim/airport/closest-airport-id", "");
+    if (currentId != nearestAirport->ident())
+    {
+      SG_LOG(SG_ENVIRONMENT, SG_INFO, "FGEnvironmentMgr::updateClosestAirport: selected:" << nearestAirport->ident());
+      fgSetString("/sim/airport/closest-airport-id",
+                  nearestAirport->ident().c_str());
+    }
+  }
+
 }
 
 FGEnvironment
@@ -424,7 +434,7 @@ void
 FGEnvironmentMgr::set_cloud_layer_coverage_type (int index, int type )
 {
   if( type < 0 || type >= SGCloudLayer::SG_MAX_CLOUD_COVERAGES ) {
-    SG_LOG(SG_ALL,SG_WARN,"Unknown cloud layer type " << type << " ignored" );
+    SG_LOG(SG_ENVIRONMENT,SG_WARN,"Unknown cloud layer type " << type << " ignored" );
     return;
   }