fix framerate target not adjusting with vcount writes (#2181)
Some checks are pending
macOS / ${{ matrix.arch }} (arm64) (push) Waiting to run
macOS / ${{ matrix.arch }} (x86_64) (push) Waiting to run
macOS / Universal binary (push) Blocked by required conditions
Ubuntu / x86_64 (push) Waiting to run
Ubuntu / aarch64 (push) Waiting to run
Windows / build (push) Waiting to run

This commit is contained in:
Jakly 2024-10-30 14:40:33 -04:00 committed by GitHub
parent 3877a8e46b
commit 4ba8f330c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 18 deletions

View File

@ -93,25 +93,25 @@ EmuInstance::EmuInstance(int inst) : deleting(false),
if (val == 0.0) if (val == 0.0)
{ {
Platform::Log(Platform::LogLevel::Error, "Target FPS in config invalid\n"); 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"); val = globalCfg.GetDouble("FastForwardFPS");
if (val == 0.0) if (val == 0.0)
{ {
Platform::Log(Platform::LogLevel::Error, "Fast-Forward FPS in config invalid\n"); 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"); val = globalCfg.GetDouble("SlowmoFPS");
if (val == 0.0) if (val == 0.0)
{ {
Platform::Log(Platform::LogLevel::Error, "Slow-Mo FPS in config invalid\n"); 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"); doAudioSync = globalCfg.GetBool("AudioSync");

View File

@ -359,7 +359,7 @@ void EmuThread::run()
if (slowmo) emuInstance->curFPS = emuInstance->slowmoFPS; if (slowmo) emuInstance->curFPS = emuInstance->slowmoFPS;
else if (fastforward) emuInstance->curFPS = emuInstance->fastForwardFPS; 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; else emuInstance->curFPS = emuInstance->targetFPS;
if (emuInstance->audioDSiVolumeSync && emuInstance->nds->ConsoleType == 1) if (emuInstance->audioDSiVolumeSync && emuInstance->nds->ConsoleType == 1)
@ -378,16 +378,18 @@ void EmuThread::run()
if (emuInstance->doAudioSync && !(fastforward || slowmo)) if (emuInstance->doAudioSync && !(fastforward || slowmo))
emuInstance->audioSync(); 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; double curtime = SDL_GetPerformanceCounter() * perfCountsSec;
frameLimitError += emuInstance->curFPS - (curtime - lastTime); frameLimitError += frametimeStep - (curtime - lastTime);
if (frameLimitError < -emuInstance->curFPS) if (frameLimitError < -frametimeStep)
frameLimitError = -emuInstance->curFPS; frameLimitError = -frametimeStep;
if (frameLimitError > emuInstance->curFPS) if (frameLimitError > frametimeStep)
frameLimitError = emuInstance->curFPS; frameLimitError = frametimeStep;
if (round(frameLimitError * 1000.0) > 0.0) if (round(frameLimitError * 1000.0) > 0.0)
{ {
@ -415,10 +417,11 @@ void EmuThread::run()
winUpdateFreq = fps / (u32)round(fpstarget); winUpdateFreq = fps / (u32)round(fpstarget);
if (winUpdateFreq < 1) if (winUpdateFreq < 1)
winUpdateFreq = 1; winUpdateFreq = 1;
double actualfps = (59.8261 * 263.0) / nlines;
int inst = emuInstance->instanceID; int inst = emuInstance->instanceID;
if (inst == 0) if (inst == 0)
sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, fpstarget); sprintf(melontitle, "[%d/%.0f] melonDS " MELONDS_VERSION, fps, actualfps);
else else
sprintf(melontitle, "[%d/%.0f] melonDS (%d)", fps, fpstarget, inst+1); sprintf(melontitle, "[%d/%.0f] melonDS (%d)", fps, fpstarget, inst+1);
changeWindowTitle(melontitle); changeWindowTitle(melontitle);

View File

@ -1942,9 +1942,9 @@ void MainWindow::onOpenInterfaceSettings()
void MainWindow::onUpdateInterfaceSettings() void MainWindow::onUpdateInterfaceSettings()
{ {
pauseOnLostFocus = globalCfg.GetBool("PauseLostFocus"); pauseOnLostFocus = globalCfg.GetBool("PauseLostFocus");
emuInstance->targetFPS = 1.0 / globalCfg.GetDouble("TargetFPS"); emuInstance->targetFPS = globalCfg.GetDouble("TargetFPS");
emuInstance->fastForwardFPS = 1.0 / globalCfg.GetDouble("FastForwardFPS"); emuInstance->fastForwardFPS = globalCfg.GetDouble("FastForwardFPS");
emuInstance->slowmoFPS = 1.0 / globalCfg.GetDouble("SlowmoFPS"); emuInstance->slowmoFPS = globalCfg.GetDouble("SlowmoFPS");
panel->setMouseHide(globalCfg.GetBool("MouseHide"), panel->setMouseHide(globalCfg.GetBool("MouseHide"),
globalCfg.GetInt("MouseHideSeconds")*1000); globalCfg.GetInt("MouseHideSeconds")*1000);
} }