From 5a89b4f3854f2ec0811cd2adbdeb84b3445ae08f Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Fri, 2 Jun 2017 08:18:17 -0700 Subject: [PATCH] allow b3Clock to reset to time reference 0, by default reset will set the reference to 'now'. --- examples/Utils/b3Clock.cpp | 18 +++++++++++++++++- examples/Utils/b3Clock.h | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/Utils/b3Clock.cpp b/examples/Utils/b3Clock.cpp index bcf7d13ba..de2134b56 100644 --- a/examples/Utils/b3Clock.cpp +++ b/examples/Utils/b3Clock.cpp @@ -88,8 +88,23 @@ b3Clock& b3Clock::operator=(const b3Clock& other) /// Resets the initial reference time. -void b3Clock::reset() +void b3Clock::reset(bool zeroReference) { + if (zeroReference) + { + m_data->mStartTick = 0; +#ifdef B3_USE_WINDOWS_TIMERS + m_data->mStartTime.QuadPart = 0; +#else + #ifdef __CELLOS_LV2__ + m_data->mStartTime = 0; + #else + m_data->mStartTime = (struct timeval){0}; + #endif +#endif + + } else + { #ifdef B3_USE_WINDOWS_TIMERS QueryPerformanceCounter(&m_data->mStartTime); m_data->mStartTick = GetTickCount(); @@ -105,6 +120,7 @@ void b3Clock::reset() gettimeofday(&m_data->mStartTime, 0); #endif #endif + } } /// Returns the time in ms since the last call to reset or since diff --git a/examples/Utils/b3Clock.h b/examples/Utils/b3Clock.h index 10a36686a..1cdd28847 100644 --- a/examples/Utils/b3Clock.h +++ b/examples/Utils/b3Clock.h @@ -13,8 +13,8 @@ public: ~b3Clock(); - /// Resets the initial reference time. - void reset(); + /// Resets the initial reference time. If zeroReference is true, will set reference to absolute 0. + void reset(bool zeroReference=false); /// Returns the time in ms since the last call to reset or since /// the b3Clock was created.