diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 60c0b62c0f..c60c87d79a 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -996,8 +996,7 @@ namespace OpenRCT2 void RunFrame() { - const auto deltaTime = _timer.GetElapsedSeconds().count(); - _timer.Restart(); + const auto deltaTime = _timer.GetElapsedTimeAndRestart().count(); // Make sure we catch the state change and reset it. bool useVariableFrame = ShouldRunVariableFrame(); diff --git a/src/openrct2/core/Timer.hpp b/src/openrct2/core/Timer.hpp index 192392f8f1..cde73d0640 100644 --- a/src/openrct2/core/Timer.hpp +++ b/src/openrct2/core/Timer.hpp @@ -12,6 +12,9 @@ namespace OpenRCT2 { + /// + /// Restartable timer utility that starts at construction. + /// class Timer { using Clock = std::chrono::high_resolution_clock; @@ -20,15 +23,32 @@ namespace OpenRCT2 Timepoint _tp = Clock::now(); public: + /// + /// Restarts the timer. + /// + /// void Restart() noexcept { _tp = Clock::now(); } - std::chrono::duration GetElapsedSeconds() const noexcept + /// + /// Returns the amount of time in seconds since the last start. + /// + [[nodiscard]] std::chrono::duration GetElapsedTime() const noexcept { return Clock::now() - _tp; } + + /// + /// Returns the amount of time in seconds since the last start and restarts. + /// + [[nodiscard]] std::chrono::duration GetElapsedTimeAndRestart() noexcept + { + const auto res = Clock::now() - _tp; + Restart(); + return res; + } }; } // namespace OpenRCT2 diff --git a/src/openrct2/network/DiscordService.cpp b/src/openrct2/network/DiscordService.cpp index c4375b147a..9c9c9b4639 100644 --- a/src/openrct2/network/DiscordService.cpp +++ b/src/openrct2/network/DiscordService.cpp @@ -75,7 +75,7 @@ void DiscordService::Tick() { Discord_RunCallbacks(); - if (_updateTimer.GetElapsedSeconds() < REFRESH_INTERVAL) + if (_updateTimer.GetElapsedTime() < REFRESH_INTERVAL) return; RefreshPresence();