diff --git a/include/openspace/util/timemanager.h b/include/openspace/util/timemanager.h index 8d57a89a50..7714bf89a4 100644 --- a/include/openspace/util/timemanager.h +++ b/include/openspace/util/timemanager.h @@ -51,14 +51,14 @@ struct TimeKeyframeData { class TimeManager : public properties::PropertyOwner { public: - TimeManager(); - using CallbackHandle = int; using TimeChangeCallback = std::function; + TimeManager(); + const Time& time() const; const Time& integrateFromTime() const; - const Timeline& timeline(); + const Timeline& timeline() const; std::vector getSyncables(); void preSynchronization(double dt); @@ -105,6 +105,7 @@ public: void removeDeltaTimeChangeCallback(CallbackHandle handle); void removeTimeJumpCallback(CallbackHandle handle); void removeTimelineChangeCallback(CallbackHandle handle); + private: void progressTime(double dt); void applyKeyframeData(const TimeKeyframeData& keyframe); diff --git a/modules/base/dashboard/dashboarditemsimulationincrement.cpp b/modules/base/dashboard/dashboarditemsimulationincrement.cpp index 6f5b9bb2a4..f3c102733c 100644 --- a/modules/base/dashboard/dashboarditemsimulationincrement.cpp +++ b/modules/base/dashboard/dashboarditemsimulationincrement.cpp @@ -177,29 +177,55 @@ DashboardItemSimulationIncrement::DashboardItemSimulationIncrement( } void DashboardItemSimulationIncrement::render(glm::vec2& penPosition) { - const double t = OsEng.timeManager().targetDeltaTime(); - std::pair deltaTime; + const double targetDt = OsEng.timeManager().targetDeltaTime(); + const double currentDt = OsEng.timeManager().deltaTime(); + std::pair targetDeltaTime; + std::pair currentDeltaTime; if (_doSimplification) { - deltaTime = simplifyTime(t); + targetDeltaTime = simplifyTime(targetDt); + if (targetDt != currentDt) { + currentDeltaTime = simplifyTime(currentDt); + } } else { const TimeUnit unit = static_cast(_requestedUnit.value()); - const double convertedT = convertTime(t, TimeUnit::Second, unit); - deltaTime = { convertedT, nameForTimeUnit(unit, convertedT != 1.0) }; + + const double convTarget = convertTime(targetDt, TimeUnit::Second, unit); + targetDeltaTime = { convTarget, nameForTimeUnit(unit, convTarget != 1.0) }; + + if (targetDt != currentDt) { + const double convCurrent = convertTime(currentDt, TimeUnit::Second, unit); + currentDeltaTime = { convCurrent, nameForTimeUnit(unit, convCurrent != 1.0) }; + } } std::string pauseText = OsEng.timeManager().isPaused() ? " (Paused)" : ""; penPosition.y -= _font->height(); - RenderFont( - *_font, - penPosition, - fmt::format( - "Simulation increment: {:.1f} {:s} / second{:s}", - deltaTime.first, deltaTime.second, - pauseText - ) - ); + if (targetDt != currentDt && !OsEng.timeManager().isPaused()) { + // We are in the middle of a transition + RenderFont( + *_font, + penPosition, + fmt::format( + "Simulation increment: {:.1f} {:s} / second{:s} (current: {:.1f} {:s})", + targetDeltaTime.first, targetDeltaTime.second, + pauseText, + currentDeltaTime.first, currentDeltaTime.second + ) + ); + } + else { + RenderFont( + *_font, + penPosition, + fmt::format( + "Simulation increment: {:.1f} {:s} / second{:s}", + targetDeltaTime.first, targetDeltaTime.second, + pauseText + ) + ); + } } glm::vec2 DashboardItemSimulationIncrement::size() const { diff --git a/src/util/timemanager.cpp b/src/util/timemanager.cpp index 53a5aba4c8..d96bfe216e 100644 --- a/src/util/timemanager.cpp +++ b/src/util/timemanager.cpp @@ -28,7 +28,6 @@ #include #include #include - #include namespace { @@ -75,8 +74,7 @@ using datamessagestructures::TimeKeyframe; TimeManager::TimeManager() : properties::PropertyOwner({ "TimeManager" }) - , _defaultTimeInterpolationDuration( - DefaultTimeInterpolationDurationInfo, + , _defaultTimeInterpolationDuration(DefaultTimeInterpolationDurationInfo, 2.f, 0.f, 5.f @@ -354,7 +352,6 @@ void TimeManager::setTimeNextFrame(Time t) { clearKeyframes(); } - void TimeManager::setDeltaTime(double deltaTime) { interpolateDeltaTime(deltaTime, 0.0); } @@ -371,7 +368,7 @@ const Time& TimeManager::integrateFromTime() const { return _integrateFromTime; } -const Timeline& TimeManager::timeline() { +const Timeline& TimeManager::timeline() const { return _timeline; } @@ -392,8 +389,7 @@ TimeManager::CallbackHandle TimeManager::addDeltaTimeChangeCallback(TimeChangeCa return handle; } -TimeManager::CallbackHandle TimeManager::addTimeJumpCallback(TimeChangeCallback cb) -{ +TimeManager::CallbackHandle TimeManager::addTimeJumpCallback(TimeChangeCallback cb) { CallbackHandle handle = _nextCallbackHandle++; _timeJumpCallbacks.emplace_back(handle, std::move(cb)); return handle; @@ -441,12 +437,12 @@ void TimeManager::removeDeltaTimeChangeCallback(CallbackHandle handle) { } void TimeManager::removeTimeJumpCallback(CallbackHandle handle) { - auto it = std::find_if( + const auto it = std::find_if( _timeJumpCallbacks.begin(), _timeJumpCallbacks.end(), [handle](const std::pair>& cb) { - return cb.first == handle; - } + return cb.first == handle; + } ); ghoul_assert( @@ -458,7 +454,7 @@ void TimeManager::removeTimeJumpCallback(CallbackHandle handle) { } void TimeManager::removeTimelineChangeCallback(CallbackHandle handle) { - auto it = std::find_if( + const auto it = std::find_if( _timelineChangeCallbacks.begin(), _timelineChangeCallbacks.end(), [handle](const std::pair>& cb) {