1
0
Fork 0

Make the steady clock and MP clock init at modelHz boundary.

This removing any fractional (of a modelHz step) part when initialising.
This allow us to sync time in different FG instances, if FPS allow.
This commit is contained in:
jano 2020-12-11 23:11:58 +01:00 committed by James Turner
parent bf26817d53
commit 7dfbcf0918

View file

@ -197,24 +197,31 @@ void TimeManager::valueChanged(SGPropertyNode* aProp)
void TimeManager::computeTimeDeltas(double& simDt, double& realDt) void TimeManager::computeTimeDeltas(double& simDt, double& realDt)
{ {
// Update the elapsed time. const double modelHz = _modelHz->getDoubleValue();
if (_firstUpdate) {
_lastStamp.stamp();
// we initialise the mp protocol clock with the system clock. // Update the elapsed time.
_systemStamp.systemClockHoursAndMinutes(); if (_firstUpdate) {
_steadyClock = _systemStamp.toSecs(); _lastStamp.stamp();
_firstUpdate = false; // Initialise the mp protocol / steady clock with the system clock.
_lastClockFreeze = _clockFreeze->getBoolValue(); // later, the clock follows steps of 1/modelHz (120 by default),
// so the MP clock remains aligned to these boundaries
_systemStamp.systemClockHoursAndMinutes();
const double systemStamp = _systemStamp.toSecs();
_steadyClock = floor(systemStamp * modelHz) / modelHz;
// initialize the remainder with offset from the system clock
_dtRemainder = systemStamp - _steadyClock;
_firstUpdate = false;
_lastClockFreeze = _clockFreeze->getBoolValue();
} }
bool wait_for_scenery = !_sceneryLoaded->getBoolValue(); bool wait_for_scenery = !_sceneryLoaded->getBoolValue();
if (!wait_for_scenery) { if (!wait_for_scenery) {
throttleUpdateRate(); throttleUpdateRate();
} } else {
else
{
// suppress framerate while initial scenery isn't loaded yet (splash screen still active) // suppress framerate while initial scenery isn't loaded yet (splash screen still active)
_lastFrameTime=0; _lastFrameTime=0;
_frameCount = 0; _frameCount = 0;
@ -258,7 +265,6 @@ 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);
double modelHz = _modelHz->getDoubleValue();
fdmGroup->set_fixed_update_time(1.0 / modelHz); 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.