Reset: use simple properties for TimeManager
This commit is contained in:
parent
881df711ba
commit
069a098909
2 changed files with 20 additions and 16 deletions
|
@ -54,11 +54,7 @@ static bool do_timeofday (const SGPropertyNode * arg)
|
||||||
|
|
||||||
TimeManager::TimeManager() :
|
TimeManager::TimeManager() :
|
||||||
_inited(false),
|
_inited(false),
|
||||||
_impl(NULL),
|
_impl(NULL)
|
||||||
_sceneryLoaded("sim/sceneryloaded"),
|
|
||||||
_modelHz("sim/model-hz"),
|
|
||||||
_timeDelta("sim/time/delta-realtime-sec"),
|
|
||||||
_simTimeDelta("sim/time/delta-sec")
|
|
||||||
{
|
{
|
||||||
SGCommandMgr::instance()->addCommand("timeofday", do_timeofday);
|
SGCommandMgr::instance()->addCommand("timeofday", do_timeofday);
|
||||||
}
|
}
|
||||||
|
@ -106,6 +102,11 @@ void TimeManager::init()
|
||||||
_lastFrameTime = 0;
|
_lastFrameTime = 0;
|
||||||
_frameLatencyMax = 0.0;
|
_frameLatencyMax = 0.0;
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
|
|
||||||
|
_sceneryLoaded = fgGetNode("sim/sceneryloaded", true);
|
||||||
|
_modelHz = fgGetNode("sim/model-hz", true);
|
||||||
|
_timeDelta = fgGetNode("sim/time/delta-realtime-sec", true);
|
||||||
|
_simTimeDelta = fgGetNode("sim/time/delta-sec", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::unbind()
|
void TimeManager::unbind()
|
||||||
|
@ -119,7 +120,10 @@ void TimeManager::unbind()
|
||||||
_frameLatency.clear();
|
_frameLatency.clear();
|
||||||
_frameRateWorst.clear();
|
_frameRateWorst.clear();
|
||||||
|
|
||||||
// and the property objects too
|
_sceneryLoaded.clear();
|
||||||
|
_modelHz.clear();
|
||||||
|
_timeDelta.clear();
|
||||||
|
_simTimeDelta.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::postinit()
|
void TimeManager::postinit()
|
||||||
|
@ -203,15 +207,16 @@ void TimeManager::computeTimeDeltas(double& simDt, double& realDt)
|
||||||
|
|
||||||
SGSubsystemGroup* fdmGroup =
|
SGSubsystemGroup* fdmGroup =
|
||||||
globals->get_subsystem_mgr()->get_group(SGSubsystemMgr::FDM);
|
globals->get_subsystem_mgr()->get_group(SGSubsystemMgr::FDM);
|
||||||
fdmGroup->set_fixed_update_time(1.0 / _modelHz);
|
double modelHz = _modelHz->getDoubleValue();
|
||||||
|
fdmGroup->set_fixed_update_time(1.0 / modelHz);
|
||||||
|
|
||||||
// round the real time down to a multiple of 1/model-hz.
|
// round the real time down to a multiple of 1/model-hz.
|
||||||
// this way all systems are updated the _same_ amount of dt.
|
// this way all systems are updated the _same_ amount of dt.
|
||||||
dt += _dtRemainder;
|
dt += _dtRemainder;
|
||||||
int multiLoop = long(floor(dt * _modelHz));
|
int multiLoop = long(floor(dt * modelHz));
|
||||||
multiLoop = SGMisc<long>::max(0, multiLoop);
|
multiLoop = SGMisc<long>::max(0, multiLoop);
|
||||||
_dtRemainder = dt - double(multiLoop)/double(_modelHz);
|
_dtRemainder = dt - double(multiLoop)/modelHz;
|
||||||
dt = double(multiLoop)/double(_modelHz);
|
dt = double(multiLoop)/modelHz;
|
||||||
|
|
||||||
realDt = dt;
|
realDt = dt;
|
||||||
if (_clockFreeze->getBoolValue() || wait_for_scenery) {
|
if (_clockFreeze->getBoolValue() || wait_for_scenery) {
|
||||||
|
@ -224,8 +229,8 @@ void TimeManager::computeTimeDeltas(double& simDt, double& realDt)
|
||||||
globals->inc_sim_time_sec(simDt);
|
globals->inc_sim_time_sec(simDt);
|
||||||
|
|
||||||
// These are useful, especially for Nasal scripts.
|
// These are useful, especially for Nasal scripts.
|
||||||
_timeDelta = realDt;
|
_timeDelta->setDoubleValue(realDt);
|
||||||
_simTimeDelta = simDt;
|
_simTimeDelta->setDoubleValue(simDt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeManager::update(double dt)
|
void TimeManager::update(double dt)
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/props/propertyObject.hxx>
|
|
||||||
|
|
||||||
// forward decls
|
// forward decls
|
||||||
class SGTime;
|
class SGTime;
|
||||||
|
@ -88,9 +87,9 @@ private:
|
||||||
double _frameLatencyMax;
|
double _frameLatencyMax;
|
||||||
int _frameCount;
|
int _frameCount;
|
||||||
|
|
||||||
SGPropObjBool _sceneryLoaded;
|
SGPropertyNode_ptr _sceneryLoaded;
|
||||||
SGPropObjInt _modelHz;
|
SGPropertyNode_ptr _modelHz;
|
||||||
SGPropObjDouble _timeDelta, _simTimeDelta;
|
SGPropertyNode_ptr _timeDelta, _simTimeDelta;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // of FG_TIME_TIMEMANAGER_HXX
|
#endif // of FG_TIME_TIMEMANAGER_HXX
|
||||||
|
|
Loading…
Reference in a new issue