From a77eabb9dc0e1a2a81ccaa13c1d7c0408fd1161e Mon Sep 17 00:00:00 2001 From: Julian Smith Date: Fri, 26 Nov 2021 14:18:50 +0000 Subject: [PATCH] src/Time/TimeManager.*: in simple-time, added support for fixed fdm increment. If in simple-time mode and /sim/time/fixed-dt is non-zero, we always increment FDM time by fixed amount each frame, regardless of frame rate. Allows creation of high quality videos even on slow hardware. --- src/Time/TimeManager.cxx | 25 +++++++++++++++++++++++-- src/Time/TimeManager.hxx | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Time/TimeManager.cxx b/src/Time/TimeManager.cxx index ca74dd1e8..5cfa3b15d 100644 --- a/src/Time/TimeManager.cxx +++ b/src/Time/TimeManager.cxx @@ -90,6 +90,7 @@ void TimeManager::init() _localTimeZoneNode = fgGetNode("/sim/time/local-timezone", true); _warpDelta = fgGetNode("/sim/time/warp-delta", true); _frameNumber = fgGetNode("/sim/frame-number", true); + _simFixedDt = fgGetNode("/sim/time/fixed-dt", true); SGPath zone(globals->get_fg_root()); zone.append("Timezone"); @@ -220,7 +221,27 @@ static double TimeUTC() void TimeManager::computeTimeDeltasSimple(double& simDt, double& realDt) { - double t = TimeUTC(); + double t; + double fixed_dt = _simFixedDt->getDoubleValue(); + static bool fixed_dt_prev = 0; + if (fixed_dt) + { + // Always increase time by fixed amount, regardless of elapsed + // time. E.g. this can be used to generate high-quality videos. + t = _simple_time_fdm + fixed_dt; + fixed_dt_prev = fixed_dt; + } + else + { + t = TimeUTC(); + + if (fixed_dt_prev) + { + // Avoid bogus sleep to match _maxFrameRate. + _simple_time_fdm = _simple_time_utc = t - fixed_dt_prev; + fixed_dt_prev = 0.0; + } + } double modelHz = _modelHz->getDoubleValue(); bool scenery_loaded = _sceneryLoaded->getBoolValue(); @@ -236,7 +257,7 @@ void TimeManager::computeTimeDeltasSimple(double& simDt, double& realDt) // inline instead of calling throttleUpdateRate(). // double sleep_time = 0; - if (scenery_loaded) { + if (scenery_loaded && !fixed_dt) { double max_frame_rate = _maxFrameRate->getDoubleValue(); if (max_frame_rate != 0) { double delay_end = _simple_time_utc + 1.0/max_frame_rate; diff --git a/src/Time/TimeManager.hxx b/src/Time/TimeManager.hxx index cdf75c571..a1b0eea45 100644 --- a/src/Time/TimeManager.hxx +++ b/src/Time/TimeManager.hxx @@ -108,6 +108,7 @@ private: SGPropertyNode_ptr _localTimeStringNode; SGPropertyNode_ptr _localTimeZoneNode; SGPropertyNode_ptr _frameNumber; + SGPropertyNode_ptr _simFixedDt; bool _lastClockFreeze = false; bool _adjustWarpOnUnfreeze = false;