From c738327e79004a7b514f7348a05cf0cf44b3436f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Ro=C3=9F?= Date: Mon, 26 Aug 2024 00:45:06 +0200 Subject: [PATCH] [UI] Replaced busy wait loop with a sleep. --- ui/UISystem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/UISystem.cpp b/ui/UISystem.cpp index 2c18e5a3..0520b238 100644 --- a/ui/UISystem.cpp +++ b/ui/UISystem.cpp @@ -175,7 +175,7 @@ #define UI_MOUSE_HOTX 2 #define UI_MOUSE_HOTY 2 -#define UI_FRAMETIME 0.05 +constexpr int ui_FrameTimeMS = 50; ////////////////////////////////////////////////////////////////////////////// // VARIABLES struct tUIWindowNode { @@ -502,9 +502,9 @@ int ui_DoFrame(bool input) { ui_DoWindowFocus(); // determine window with current input focus. res = ui_ProcessFocusedWindow(); // process focused window - // int64_t cur_time = timer_GetMSTime(); - while ((timer_GetTime() - UI_input.cur_time) < UI_FRAMETIME) { - }; + const float elapsedTimeS = timer_GetTime() - UI_input.cur_time; + const int waitTimeMS = ui_FrameTimeMS - static_cast(elapsedTimeS * 1000.0f); + D3::ChronoTimer::SleepMS(waitTimeMS); float temp_time = timer_GetTime(); UIFrameTime = temp_time - UI_input.cur_time;