From a85f348e50f9f3f2754e249e7ec1e1ca8a578a03 Mon Sep 17 00:00:00 2001 From: harry Date: Sun, 28 Jan 2024 08:15:00 -0500 Subject: [PATCH] For Qt GUI, edit frame throttling logic when using turbo mode or really fast emulation speed to not be so wasteful when emulation is paused. Don't make sense to waste CPU resources spinning on nothing. Fixes #681. --- src/drivers/Qt/sdl-throttle.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/drivers/Qt/sdl-throttle.cpp b/src/drivers/Qt/sdl-throttle.cpp index 8d5daece..72637de5 100644 --- a/src/drivers/Qt/sdl-throttle.cpp +++ b/src/drivers/Qt/sdl-throttle.cpp @@ -365,7 +365,12 @@ static int highPrecSleep( FCEU::timeStampRecord &ts ) int SpeedThrottle(void) { - if ( (g_fpsScale >= 32) || (NoWaiting & 0x01) || turbo ) + bool isEmuPaused = FCEUI_EmulationPaused() ? true : false; + bool noWaitActive = (NoWaiting & 0x01) ? true : false; + bool turboActive = (turbo || noWaitActive); + + // If Emulator is paused, don't waste CPU cycles spinning on nothing. + if ( !isEmuPaused && ((g_fpsScale >= 32) || turboActive) ) { return 0; /* Done waiting */ } @@ -397,6 +402,16 @@ SpeedThrottle(void) time_left = Nexttime - cur_time; } + // If Emulator is paused, ensure that sleep time cannot be zero + // we don't want to waste a full CPU core on nothing. + if (isEmuPaused) + { + if (time_left.toMilliSeconds() < 1) + { + time_left.fromMilliSeconds(1); + } + } + if (time_left.toMilliSeconds() > 50) { time_left.fromMilliSeconds(50); @@ -407,7 +422,7 @@ SpeedThrottle(void) { InFrame = 0; } - + //fprintf(stderr, "attempting to sleep %Ld ms, frame complete=%s\n", // time_left, InFrame?"no":"yes");