From cb89dff10ff10cc38d893cb1f12d7cb947871cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 27 Jan 2024 11:30:29 +0100 Subject: [PATCH] SDL: Remove unnecessary sleeps in the SDLMain loop (we now handle it in NativeFrame) --- SDL/SDLMain.cpp | 10 ---------- UI/NativeApp.cpp | 10 +++++----- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index e3fb221bd6..50489bb7cf 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -675,17 +675,7 @@ static void EmuThreadFunc(GraphicsContext *graphicsContext) { NativeInitGraphics(graphicsContext); while (emuThreadState != (int)EmuThreadState::QUIT_REQUESTED) { - double startTime = time_now_d(); - UpdateRunLoop(graphicsContext); - - // Simple throttling to not burn the GPU in the menu. - if (GetUIState() != UISTATE_INGAME || !PSP_IsInited()) { - double diffTime = time_now_d() - startTime; - int sleepTime = (int)(1000.0 / 60.0) - (int)(diffTime * 1000.0); - if (sleepTime > 0) - sleep_ms(sleepTime); - } } emuThreadState = (int)EmuThreadState::STOPPED; graphicsContext->StopThread(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index e81d0bdf38..49ed7cd003 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1176,7 +1176,12 @@ void NativeFrame(GraphicsContext *graphicsContext) { graphicsContext->Poll(); } + SendMouseDeltaAxis(); + if (!(renderFlags & ScreenRenderFlags::HANDLED_THROTTLING)) { + // TODO: We should ideally mix this with game audio. + g_BackgroundAudio.Play(); + float refreshRate = System_GetPropertyFloat(SYSPROP_DISPLAY_REFRESH_RATE); // Simple throttling to not burn the GPU in the menu. // TODO: This should move into NativeFrame. Also, it's only necessary in MAILBOX or IMMEDIATE presentation modes. @@ -1184,12 +1189,7 @@ void NativeFrame(GraphicsContext *graphicsContext) { int sleepTime = (int)(1000.0 / refreshRate) - (int)(diffTime * 1000.0); if (sleepTime > 0) sleep_ms(sleepTime); - - // TODO: We should ideally mix this with game audio. - g_BackgroundAudio.Play(); } - - SendMouseDeltaAxis(); } bool HandleGlobalMessage(UIMessage message, const std::string &value) {