Skip to content

Commit

Permalink
SDL: Remove unnecessary sleeps in the SDLMain loop (we now handle it …
Browse files Browse the repository at this point in the history
…in NativeFrame)
  • Loading branch information
hrydgard committed Jan 27, 2024
1 parent 437dbe4 commit cb89dff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
10 changes: 0 additions & 10 deletions SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,20 +1176,20 @@ 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.
double diffTime = time_now_d() - startTime;
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) {
Expand Down

0 comments on commit cb89dff

Please sign in to comment.