From d7d3e9f21b57da72eee00b05e6c3bde0ec68f8c9 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Sun, 8 Nov 2009 02:30:42 +0000 Subject: [PATCH] preventing frameskip from affecting frame advance except when also fast-forwarding, and fixing a bug where the very first frame advance would not pause the game --- desmume/src/NDSSystem.h | 1 + desmume/src/windows/main.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 863d7a80e..9bd2e9654 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -366,6 +366,7 @@ void NDS_Sleep(); void NDS_SkipNextFrame(); #define NDS_SkipFrame(s) if(s) NDS_SkipNext2DFrame(); +void NDS_OmitFrameSkip(int force=0); void execHardware_doAllDma(EDMAMode modeNum); diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 2a49ae68e..a4255f200 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -292,6 +292,7 @@ int frameskiprate=0; int lastskiprate=0; int emu_paused = 0; bool frameAdvance = false; +bool continuousframeAdvancing = false; bool staterewindingenabled = false; unsigned short windowSize = 0; @@ -1576,7 +1577,7 @@ static void StepRunLoop_Throttle(bool allowSleep = true, int forceFrameSkip = -1 mainLoopData.framestoskip = 0; // otherwise switches to lower frameskip rates will lag behind } - if(!mainLoopData.skipnextframe || forceFrameSkip == 0) + if(!mainLoopData.skipnextframe || forceFrameSkip == 0 || frameAdvance || (continuousframeAdvancing && !FastForward)) { mainLoopData.framesskipped = 0; @@ -1647,13 +1648,13 @@ static void StepRunLoop_Throttle(bool allowSleep = true, int forceFrameSkip = -1 emu_halt(); SPU_Pause(1); } - ServiceDisplayThreadInvocations(); - if(execute && emu_paused && !frameAdvance) { // safety net against running out of control in case this ever happens. Unpause(); Pause(); } + + ServiceDisplayThreadInvocations(); } DWORD WINAPI run() @@ -3292,10 +3293,11 @@ void TogglePause() } -bool first; +bool first = true; void FrameAdvance(bool state) { + continuousframeAdvancing = false; if(!romloaded) return; if(state) { @@ -3310,11 +3312,17 @@ void FrameAdvance(bool state) execute = TRUE; frameAdvance = true; } + // this seems to reduce the average recovery time (by about 1 frame) + // when switching from frameskipping to frameadvance. + // we could pass 1 in to force it to happen even earlier + // but that can result in 2d and 3d looking out of sync for 1 frame. + NDS_OmitFrameSkip(); } else { // frame advance button still held down, // start or continue executing at normal speed Unpause(); frameAdvance = false; + continuousframeAdvancing = true; } } else { // frame advance button released