mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-24 15:24:30 +01:00
Add utility function and some minor cleanup/documentation
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
/// <summary>
|
||||
/// Restartable timer utility that starts at construction.
|
||||
/// </summary>
|
||||
class Timer
|
||||
{
|
||||
using Clock = std::chrono::high_resolution_clock;
|
||||
@@ -20,15 +23,32 @@ namespace OpenRCT2
|
||||
Timepoint _tp = Clock::now();
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Restarts the timer.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
void Restart() noexcept
|
||||
{
|
||||
_tp = Clock::now();
|
||||
}
|
||||
|
||||
std::chrono::duration<float> GetElapsedSeconds() const noexcept
|
||||
/// <summary>
|
||||
/// Returns the amount of time in seconds since the last start.
|
||||
/// </summary>
|
||||
[[nodiscard]] std::chrono::duration<float> GetElapsedTime() const noexcept
|
||||
{
|
||||
return Clock::now() - _tp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the amount of time in seconds since the last start and restarts.
|
||||
/// </summary>
|
||||
[[nodiscard]] std::chrono::duration<float> GetElapsedTimeAndRestart() noexcept
|
||||
{
|
||||
const auto res = Clock::now() - _tp;
|
||||
Restart();
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace OpenRCT2
|
||||
|
||||
@@ -75,7 +75,7 @@ void DiscordService::Tick()
|
||||
{
|
||||
Discord_RunCallbacks();
|
||||
|
||||
if (_updateTimer.GetElapsedSeconds() < REFRESH_INTERVAL)
|
||||
if (_updateTimer.GetElapsedTime() < REFRESH_INTERVAL)
|
||||
return;
|
||||
|
||||
RefreshPresence();
|
||||
|
||||
Reference in New Issue
Block a user