]> git.mxchange.org Git - flightgear.git/commitdiff
Use property objects to avoid property look-ups during TimeManager updates.
authorJames Turner <zakalawe@mac.com>
Sun, 20 Nov 2011 18:30:31 +0000 (18:30 +0000)
committerJames Turner <zakalawe@mac.com>
Sun, 20 Nov 2011 18:30:31 +0000 (18:30 +0000)
src/Time/TimeManager.cxx
src/Time/TimeManager.hxx

index 00f6f31b9a50560a45e57cac9157b12f680ce91b..96282bfe38b6c7f0ef8b4739802a8124a9c383a2 100644 (file)
@@ -53,7 +53,12 @@ static bool do_timeofday (const SGPropertyNode * arg)
 
 TimeManager::TimeManager() :
   _inited(false),
-  _impl(NULL)
+  _impl(NULL),
+  _sceneryLoaded("sim/sceneryloaded"),
+  _sceneryLoadOverride("sim/sceneryloaded-override"),
+  _modelHz("sim/model-hz"),
+  _timeDelta("sim/time/delta-realtime-sec"),
+  _simTimeDelta("sim/time/delta-sec")
 {
   SGCommandMgr::instance()->addCommand("timeofday", do_timeofday);
 }
@@ -158,9 +163,7 @@ void TimeManager::computeTimeDeltas(double& simDt, double& realDt)
     _lastClockFreeze = _clockFreeze->getBoolValue();
   }
 
-  bool scenery_loaded = fgGetBool("sim/sceneryloaded");
-  bool wait_for_scenery = !(scenery_loaded || fgGetBool("sim/sceneryloaded-override"));
-  
+  bool wait_for_scenery = !(_sceneryLoaded || _sceneryLoadOverride);
   if (!wait_for_scenery) {
     throttleUpdateRate();
   }
@@ -190,20 +193,18 @@ void TimeManager::computeTimeDeltas(double& simDt, double& realDt)
   if (0 < dtMax && dtMax < dt) {
     dt = dtMax;
   }
-  
-  int model_hz = fgGetInt("/sim/model-hz");
-  
+    
   SGSubsystemGroup* fdmGroup = 
     globals->get_subsystem_mgr()->get_group(SGSubsystemMgr::FDM);
-  fdmGroup->set_fixed_update_time(1.0 / model_hz);
+  fdmGroup->set_fixed_update_time(1.0 / _modelHz);
   
 // round the real time down to a multiple of 1/model-hz.
 // this way all systems are updated the _same_ amount of dt.
   dt += _dtRemainder;
-  int multiLoop = long(floor(dt * model_hz));
+  int multiLoop = long(floor(dt * _modelHz));
   multiLoop = SGMisc<long>::max(0, multiLoop);
-  _dtRemainder = dt - double(multiLoop)/double(model_hz);
-  dt = double(multiLoop)/double(model_hz);
+  _dtRemainder = dt - double(multiLoop)/double(_modelHz);
+  dt = double(multiLoop)/double(_modelHz);
 
   realDt = dt;
   if (_clockFreeze->getBoolValue() || wait_for_scenery) {
@@ -216,8 +217,8 @@ void TimeManager::computeTimeDeltas(double& simDt, double& realDt)
   globals->inc_sim_time_sec(simDt);
 
 // These are useful, especially for Nasal scripts.
-  fgSetDouble("/sim/time/delta-realtime-sec", realDt);
-  fgSetDouble("/sim/time/delta-sec", simDt);
+  _timeDelta = realDt;
+  _simTimeDelta = simDt;
 }
 
 void TimeManager::update(double dt)
index 10226eaf63446f4882f93db65ada92a9284eaaf2..ef86c907f94fc9761fdb8bb240ea85c692845016 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/props/props.hxx>
+#include <simgear/props/propertyObject.hxx>
 
 // forward decls
 class SGTime;
@@ -87,6 +88,11 @@ private:
   time_t _lastFrameTime;
   double _frameLatencyMax;
   int _frameCount;
+  
+  SGPropObjBool _sceneryLoaded, 
+    _sceneryLoadOverride;
+  SGPropObjInt _modelHz;
+  SGPropObjDouble _timeDelta, _simTimeDelta;
 };
 
 #endif // of FG_TIME_TIMEMANAGER_HXX