From e97baa503a0f386dc4a2413d7937a6d8bdd0d0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 10 Oct 2020 19:01:40 +0200 Subject: [PATCH] Avoid a division in time_now_d(). Minor optimizations. --- Common/TimeUtil.cpp | 8 ++------ Core/HLE/sceDisplay.cpp | 3 +++ UI/OnScreenDisplay.cpp | 3 ++- Windows/MainWindow.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Common/TimeUtil.cpp b/Common/TimeUtil.cpp index 2cb375c9a0..8f0ce379ed 100644 --- a/Common/TimeUtil.cpp +++ b/Common/TimeUtil.cpp @@ -42,18 +42,14 @@ double time_now_d() { #else -static uint64_t _frequency = 0; -static uint64_t _starttime = 0; - double time_now_d() { static time_t start; struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); if (start == 0) { start = tv.tv_sec; } - tv.tv_sec -= start; - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0; + return (double)(tv.tv_sec - start) + (double)tv.tv_usec * (1.0 / 1000000.0); } #endif diff --git a/Core/HLE/sceDisplay.cpp b/Core/HLE/sceDisplay.cpp index 1b97a35336..a8cb651a8b 100644 --- a/Core/HLE/sceDisplay.cpp +++ b/Core/HLE/sceDisplay.cpp @@ -619,6 +619,9 @@ static void DoFrameTiming(bool &throttle, bool &skipFrame, float timestep) { skipFrame = true; } + // TODO: This is NOT where we should wait, really! We should mark each outgoing frame with the desired + // timestamp to push it to display, and sleep in the render thread to achieve that. + if (curFrameTime < nextFrameTime && throttle) { // If time gap is huge just jump (somebody unthrottled) if (nextFrameTime - curFrameTime > 2*scaledTimestep) { diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index 5b89f78b57..e63eb37d08 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -22,8 +22,9 @@ void OnScreenMessagesView::Draw(UIContext &dc) { float y = 10.0f; // Then draw them all. const std::list &messages = osm.Messages(); + double now = time_now_d(); for (auto iter = messages.begin(); iter != messages.end(); ++iter) { - float alpha = (iter->endTime - time_now_d()) * 4.0f; + float alpha = (iter->endTime - now) * 4.0f; if (alpha > 1.0) alpha = 1.0f; if (alpha < 0.0) alpha = 0.0f; // Messages that are wider than the screen are left-aligned instead of centered. diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 439791544e..f925f05fe8 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -622,7 +622,7 @@ namespace MainWindow } lastMouseDown = 0.0; } else { - lastMouseDown = time_now_d(); + lastMouseDown = now; } } break;