From 4ba8f330c4d5cd6c25f6acddf2866b40e698d35f Mon Sep 17 00:00:00 2001 From: Jakly <102590697+Jaklyy@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:40:33 -0400 Subject: [PATCH] fix framerate target not adjusting with vcount writes (#2181) --- src/frontend/qt_sdl/EmuInstance.cpp | 12 ++++++------ src/frontend/qt_sdl/EmuThread.cpp | 21 ++++++++++++--------- src/frontend/qt_sdl/Window.cpp | 6 +++--- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/frontend/qt_sdl/EmuInstance.cpp b/src/frontend/qt_sdl/EmuInstance.cpp index 90116692..e9550f8c 100644 --- a/src/frontend/qt_sdl/EmuInstance.cpp +++ b/src/frontend/qt_sdl/EmuInstance.cpp @@ -93,25 +93,25 @@ EmuInstance::EmuInstance(int inst) : deleting(false), if (val == 0.0) { Platform::Log(Platform::LogLevel::Error, "Target FPS in config invalid\n"); - targetFPS = 1.0 / 60.0; + targetFPS = 60.0; } - else targetFPS = 1.0 / val; + else targetFPS = val; val = globalCfg.GetDouble("FastForwardFPS"); if (val == 0.0) { Platform::Log(Platform::LogLevel::Error, "Fast-Forward FPS in config invalid\n"); - fastForwardFPS = 1.0 / 60.0; + fastForwardFPS = 60.0; } - else fastForwardFPS = 1.0 / val; + else fastForwardFPS = val; val = globalCfg.GetDouble("SlowmoFPS"); if (val == 0.0) { Platform::Log(Platform::LogLevel::Error, "Slow-Mo FPS in config invalid\n"); - slowmoFPS = 1.0 / 60.0; + slowmoFPS = 60.0; } - else slowmoFPS = 1.0 / val; + else slowmoFPS = val; doAudioSync = globalCfg.GetBool("AudioSync"); diff --git a/src/frontend/qt_sdl/EmuThread.cpp b/src/frontend/qt_sdl/EmuThread.cpp index 3371a03b..f4112cd3 100644 --- a/src/frontend/qt_sdl/EmuThread.cpp +++ b/src/frontend/qt_sdl/EmuThread.cpp @@ -359,7 +359,7 @@ void EmuThread::run() if (slowmo) emuInstance->curFPS = emuInstance->slowmoFPS; else if (fastforward) emuInstance->curFPS = emuInstance->fastForwardFPS; - else if (!emuInstance->doLimitFPS) emuInstance->curFPS = 1.0 / 1000.0; + else if (!emuInstance->doLimitFPS) emuInstance->curFPS = 1000.0; else emuInstance->curFPS = emuInstance->targetFPS; if (emuInstance->audioDSiVolumeSync && emuInstance->nds->ConsoleType == 1) @@ -378,16 +378,18 @@ void EmuThread::run() if (emuInstance->doAudioSync && !(fastforward || slowmo)) emuInstance->audioSync(); - double frametimeStep = nlines / (60.0 * 263.0); + double frametimeStep = nlines / (emuInstance->curFPS * 263.0); + + if (frametimeStep < 0.001) frametimeStep = 0.001; { double curtime = SDL_GetPerformanceCounter() * perfCountsSec; - frameLimitError += emuInstance->curFPS - (curtime - lastTime); - if (frameLimitError < -emuInstance->curFPS) - frameLimitError = -emuInstance->curFPS; - if (frameLimitError > emuInstance->curFPS) - frameLimitError = emuInstance->curFPS; + frameLimitError += frametimeStep - (curtime - lastTime); + if (frameLimitError < -frametimeStep) + frameLimitError = -frametimeStep; + if (frameLimitError > frametimeStep) + frameLimitError = frametimeStep; if (round(frameLimitError * 1000.0) > 0.0) { @@ -415,10 +417,11 @@ void EmuThread::run() winUpdateFreq = fps / (u32)round(fpstarget); if (winUpdateFreq < 1) winUpdateFreq = 1; - + + double actualfps = (59.8261 * 263.0) / nlines; int inst = emuInstance->instanceID; if (inst == 0) - sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget); + sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, actualfps); else sprintf(melontitle, "[%d/%.0f] melonDS (%d)", fps, fpstarget, inst+1); changeWindowTitle(melontitle); diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 0af72ef6..1d207949 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -1942,9 +1942,9 @@ void MainWindow::onOpenInterfaceSettings() void MainWindow::onUpdateInterfaceSettings() { pauseOnLostFocus = globalCfg.GetBool("PauseLostFocus"); - emuInstance->targetFPS = 1.0 / globalCfg.GetDouble("TargetFPS"); - emuInstance->fastForwardFPS = 1.0 / globalCfg.GetDouble("FastForwardFPS"); - emuInstance->slowmoFPS = 1.0 / globalCfg.GetDouble("SlowmoFPS"); + emuInstance->targetFPS = globalCfg.GetDouble("TargetFPS"); + emuInstance->fastForwardFPS = globalCfg.GetDouble("FastForwardFPS"); + emuInstance->slowmoFPS = globalCfg.GetDouble("SlowmoFPS"); panel->setMouseHide(globalCfg.GetBool("MouseHide"), globalCfg.GetInt("MouseHideSeconds")*1000); }