For Qt GUI, implemented a new method of timing frame advance hold delay so that the delay time is more constant with changing emulation speed.

This commit is contained in:
mjbudd77 2021-10-05 06:49:16 -04:00
parent 4352fd8da0
commit e0f9754e80
4 changed files with 21 additions and 6 deletions

View File

@ -4162,6 +4162,11 @@ void consoleWin_t::loadMostRecentROM(void)
fceuWrapperUnLock(); fceuWrapperUnLock();
} }
int consoleWin_t::getPeriodicInterval(void)
{
return gameTimer->interval();
}
void consoleWin_t::transferVideoBuffer(void) void consoleWin_t::transferVideoBuffer(void)
{ {
if ( nes_shm->blitUpdated ) if ( nes_shm->blitUpdated )

View File

@ -175,6 +175,8 @@ class consoleWin_t : public QMainWindow
void OpenHelpWindow(std::string subpage = ""); void OpenHelpWindow(std::string subpage = "");
int getPeriodicInterval(void);
protected: protected:
consoleMenuBar *menubar; consoleMenuBar *menubar;

View File

@ -52,6 +52,7 @@
int NoWaiting = 0; int NoWaiting = 0;
extern Config *g_config; extern Config *g_config;
extern bool bindSavestate, frameAdvanceLagSkip, lagCounterDisplay; extern bool bindSavestate, frameAdvanceLagSkip, lagCounterDisplay;
unsigned int frameAdvHoldTimer = 0;
/* UsrInputType[] is user-specified. CurInputType[] is current /* UsrInputType[] is user-specified. CurInputType[] is current
(game loading can override user settings) (game loading can override user settings)
@ -989,10 +990,15 @@ static void KeyboardCommands(void)
{ {
if (frameAdvancing == false) if (frameAdvancing == false)
{ {
frameAdvHoldTimer = 0;
FCEUI_FrameAdvance(); FCEUI_FrameAdvance();
frameAdvancing = true; frameAdvancing = true;
//printf("Frame Advance Start\n"); //printf("Frame Advance Start\n");
} }
if ( consoleWindow )
{
frameAdvHoldTimer += consoleWindow->getPeriodicInterval();
}
} }
else else
{ {
@ -1000,6 +1006,7 @@ static void KeyboardCommands(void)
{ {
FCEUI_FrameAdvanceEnd(); FCEUI_FrameAdvanceEnd();
frameAdvancing = false; frameAdvancing = false;
frameAdvHoldTimer = 0;
//printf("Frame Advance End\n"); //printf("Frame Advance End\n");
} }
} }

View File

@ -717,8 +717,7 @@ void UpdateAutosave(void);
#ifdef __QT_DRIVER__ #ifdef __QT_DRIVER__
double getFrameRate(void); extern unsigned int frameAdvHoldTimer;
double getBaseFrameRate(void);
#endif #endif
///Emulates a single frame. ///Emulates a single frame.
@ -733,18 +732,20 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski
if (frameAdvanceRequested) if (frameAdvanceRequested)
{ {
#ifdef __QT_DRIVER__ #ifdef __QT_DRIVER__
double baseFrameRatio = getFrameRate() / getBaseFrameRate(); uint32_t frameAdvanceDelayScaled = frameAdvance_Delay * (PAL ? 20 : 16);
int32_t frameAdvanceDelayScaled = (int32_t)( (double)frameAdvance_Delay * baseFrameRatio);
if ( frameAdvanceDelayScaled < 1 ) if ( frameAdvanceDelayScaled < 1 )
{ {
frameAdvanceDelayScaled = 1; frameAdvanceDelayScaled = 1;
} }
if (frameAdvance_Delay_count == 0 || frameAdvance_Delay_count >= frameAdvanceDelayScaled) if ( (frameAdvance_Delay_count == 0) || (frameAdvHoldTimer >= frameAdvanceDelayScaled) )
{
EmulationPaused = EMULATIONPAUSED_FA; EmulationPaused = EMULATIONPAUSED_FA;
}
if (frameAdvance_Delay_count < frameAdvanceDelayScaled) if (frameAdvance_Delay_count < frameAdvanceDelayScaled)
{
frameAdvance_Delay_count++; frameAdvance_Delay_count++;
}
#else #else
if (frameAdvance_Delay_count == 0 || frameAdvance_Delay_count >= frameAdvance_Delay) if (frameAdvance_Delay_count == 0 || frameAdvance_Delay_count >= frameAdvance_Delay)
EmulationPaused = EMULATIONPAUSED_FA; EmulationPaused = EMULATIONPAUSED_FA;