From b9dd24d3cede5aaa0f8df79c46a79d00739eb3b8 Mon Sep 17 00:00:00 2001 From: Joel Schumacher Date: Wed, 20 May 2020 23:05:11 +0200 Subject: [PATCH] Make getTime() relative to first invocation --- src/modules/timer/Timer.cpp | 8 +++++++- src/modules/timer/Timer.h | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/modules/timer/Timer.cpp b/src/modules/timer/Timer.cpp index 66f1fcd6c..4f0745fe1 100644 --- a/src/modules/timer/Timer.cpp +++ b/src/modules/timer/Timer.cpp @@ -123,7 +123,7 @@ double Timer::getTimerPeriod() return 0; } -double Timer::getTime() +double Timer::getTimeAbsolute() { // The timer period (reciprocal of the frequency.) static const double timerPeriod = getTimerPeriod(); @@ -156,5 +156,11 @@ double Timer::getTime() #endif } +double Timer::getTime() +{ + static const double start = getTimeAbsolute(); + return getTimeAbsolute() - start; +} + } // timer } // love diff --git a/src/modules/timer/Timer.h b/src/modules/timer/Timer.h index 86eeae454..b7f24c0fb 100644 --- a/src/modules/timer/Timer.h +++ b/src/modules/timer/Timer.h @@ -72,9 +72,10 @@ public: double getAverageDelta() const; /** - * Gets the amount of time passed since an unspecified time. Useful for - * profiling code or measuring intervals. The time is microsecond-precise, - * and increases monotonically. + * Gets the amount of time in seconds passed since its first invocation + * (which happens as part of Timer::step at the start of love.run). + * Useful for profiling code or measuring intervals. + * The time is microsecond-precise, and increases monotonically. * @return The time (in seconds) **/ static double getTime(); @@ -102,6 +103,9 @@ private: // Returns the timer period on some platforms. static double getTimerPeriod(); + // Like getTime, but relative to an unspecified time. + static double getTimeAbsolute(); + }; // Timer } // timer