From 3fb4b5e26c0125dda68b3858e8c3d9589244c211 Mon Sep 17 00:00:00 2001 From: Tillsunset <35825944+Tillsunset@users.noreply.github.com> Date: Thu, 29 Sep 2022 04:36:27 -0500 Subject: [PATCH] MacOS+Linux: Use CLOCK_MONOTONIC_RAW over CLOCK_MONOTONIC (#313) On MacOS this fixes the framerate being too high due to discontinuities in the timer that drives the emulated vsync. It also fixes behavior of the GetTickCount() wrapper. --- src/Common/unix/platform.cpp | 2 +- src/util/highresolutiontimer/HighResolutionTimer.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Common/unix/platform.cpp b/src/Common/unix/platform.cpp index d97f4e65..a111a625 100644 --- a/src/Common/unix/platform.cpp +++ b/src/Common/unix/platform.cpp @@ -4,6 +4,6 @@ uint32_t GetTickCount() { struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); return (1000 * ts.tv_sec + ts.tv_nsec / 1000000); } \ No newline at end of file diff --git a/src/util/highresolutiontimer/HighResolutionTimer.cpp b/src/util/highresolutiontimer/HighResolutionTimer.cpp index 21cabff5..510fdfa5 100644 --- a/src/util/highresolutiontimer/HighResolutionTimer.cpp +++ b/src/util/highresolutiontimer/HighResolutionTimer.cpp @@ -9,7 +9,7 @@ HighResolutionTimer HighResolutionTimer::now() return HighResolutionTimer(pc.QuadPart); #else timespec pc; - clock_gettime(CLOCK_MONOTONIC, &pc); + clock_gettime(CLOCK_MONOTONIC_RAW, &pc); uint64 nsec = (uint64)pc.tv_sec * (uint64)1000000000 + (uint64)pc.tv_nsec; return HighResolutionTimer(nsec); #endif @@ -28,7 +28,7 @@ uint64 HighResolutionTimer::m_freq = []() -> uint64 { return (uint64)(freq.QuadPart); #else timespec pc; - clock_getres(CLOCK_MONOTONIC, &pc); + clock_getres(CLOCK_MONOTONIC_RAW, &pc); return (uint64)1000000000 / (uint64)pc.tv_nsec; #endif }();