Use property objects to avoid property look-ups during TimeManager updates.
This commit is contained in:
parent
9e344ee645
commit
029226f8d4
2 changed files with 20 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue