For Qt GUI, changed onFrameFinished callback to only update video buffer. Don't do any input processing as this will mess up when running turbo mode. Added a draw timer to SDL video renderer to better align is scheduling with the next vsync.

This commit is contained in:
harry 2024-01-31 06:49:54 -05:00
parent d363d04dbb
commit 01358407fd
4 changed files with 45 additions and 18 deletions

View File

@ -82,6 +82,11 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
vsyncEnabled = false; vsyncEnabled = false;
mouseButtonMask = 0; mouseButtonMask = 0;
drawTimer = new QTimer(this);
drawTimer->setInterval(14);
drawTimer->setSingleShot(true);
drawTimer->setTimerType(Qt::PreciseTimer);
connect(drawTimer, &QTimer::timeout, this, &ConsoleViewSDL_t::onDrawSignal);
localBufSize = (4 * GL_NES_WIDTH) * (4 * GL_NES_HEIGHT) * sizeof(uint32_t); localBufSize = (4 * GL_NES_WIDTH) * (4 * GL_NES_HEIGHT) * sizeof(uint32_t);
@ -123,6 +128,8 @@ ConsoleViewSDL_t::ConsoleViewSDL_t(QWidget *parent)
ConsoleViewSDL_t::~ConsoleViewSDL_t(void) ConsoleViewSDL_t::~ConsoleViewSDL_t(void)
{ {
//printf("Destroying SDL Viewport\n"); //printf("Destroying SDL Viewport\n");
drawTimer->stop();
delete drawTimer;
if ( localBuf ) if ( localBuf )
{ {
@ -585,6 +592,19 @@ void ConsoleViewSDL_t::getNormalizedCursorPos( double &x, double &y )
//printf("Normalized Cursor (%f,%f) \n", x, y ); //printf("Normalized Cursor (%f,%f) \n", x, y );
} }
void ConsoleViewSDL_t::queueRedraw(void)
{
if (!drawTimer->isActive())
{
render();
}
}
void ConsoleViewSDL_t::onDrawSignal(void)
{
render();
}
void ConsoleViewSDL_t::render(void) void ConsoleViewSDL_t::render(void)
{ {
int nesWidth = GL_NES_WIDTH; int nesWidth = GL_NES_WIDTH;
@ -707,5 +727,8 @@ void ConsoleViewSDL_t::render(void)
videoBufferSwapMark(); videoBufferSwapMark();
// Schedule draw timing inline with vsync
drawTimer->start();
nes_shm->render_count++; nes_shm->render_count++;
} }

View File

@ -24,7 +24,7 @@ class ConsoleViewSDL_t : public QWidget, public ConsoleViewerBase
void reset(void); void reset(void);
void cleanup(void); void cleanup(void);
void render(void); void render(void);
void queueRedraw(void){ render(); }; void queueRedraw(void);
int driver(void){ return VIDEO_DRIVER_SDL; }; int driver(void){ return VIDEO_DRIVER_SDL; };
void transfer2LocalBuffer(void); void transfer2LocalBuffer(void);
@ -83,6 +83,7 @@ class ConsoleViewSDL_t : public QWidget, public ConsoleViewerBase
bool forceAspect; bool forceAspect;
bool autoScaleEna; bool autoScaleEna;
QColor *bgColor; QColor *bgColor;
QTimer *drawTimer;
uint32_t *localBuf; uint32_t *localBuf;
uint32_t localBufSize; uint32_t localBufSize;
@ -95,5 +96,6 @@ class ConsoleViewSDL_t : public QWidget, public ConsoleViewerBase
//SDL_Rect sdlViewport; //SDL_Rect sdlViewport;
private slots: private slots:
void onDrawSignal();
}; };

View File

@ -154,6 +154,7 @@ consoleWin_t::consoleWin_t(QWidget *parent)
mainMenuEmuWasPaused = false; mainMenuEmuWasPaused = false;
mainMenuPauseWhenActv = false; mainMenuPauseWhenActv = false;
autoHideMenuFullscreen = false; autoHideMenuFullscreen = false;
redrawVideoRequest = false;
createMainMenu(); createMainMenu();
@ -412,7 +413,7 @@ void consoleWin_t::winScreenChanged(QScreen *scr)
return; return;
} }
refreshRate = scr->refreshRate(); refreshRate = scr->refreshRate();
//printf("Screen Refresh Rate: %f\n", scr->refreshRate() ); printf("Screen Refresh Rate: %f\n", scr->refreshRate() );
//printf("Screen Changed: %p\n", scr ); //printf("Screen Changed: %p\n", scr );
if ( viewport_GL != NULL ) if ( viewport_GL != NULL )
@ -4555,9 +4556,8 @@ int consoleWin_t::getPeriodicInterval(void)
return gameTimer->interval(); return gameTimer->interval();
} }
void consoleWin_t::transferVideoBuffer(void) void consoleWin_t::transferVideoBuffer(bool allowRedraw)
{ {
bool redraw = false;
FCEU_PROFILE_FUNC(prof, "VideoXfer"); FCEU_PROFILE_FUNC(prof, "VideoXfer");
{ {
@ -4569,21 +4569,22 @@ void consoleWin_t::transferVideoBuffer(void)
if (viewport_Interface != nullptr) if (viewport_Interface != nullptr)
{ {
viewport_Interface->transfer2LocalBuffer(); viewport_Interface->transfer2LocalBuffer();
redraw = true; redrawVideoRequest = true;
} }
} }
} }
// Don't queue redraw in mutex lock scope // Don't queue redraw in mutex lock scope
if (redraw && (viewport_Interface != nullptr)) if (allowRedraw && redrawVideoRequest && (viewport_Interface != nullptr))
{ {
viewport_Interface->queueRedraw(); viewport_Interface->queueRedraw();
redrawVideoRequest = false;
} }
} }
void consoleWin_t::emuFrameFinish(void) void consoleWin_t::emuFrameFinish(void)
{ {
static bool eventProcessingInProg = false; //static bool eventProcessingInProg = false;
guiSignalRecvMark(); guiSignalRecvMark();
@ -4592,16 +4593,16 @@ void consoleWin_t::emuFrameFinish(void)
// return; // return;
//} //}
// Prevent recursion as processEvents function can double back on us // Prevent recursion as processEvents function can double back on us
if ( !eventProcessingInProg ) //if ( !eventProcessingInProg )
{ //{
eventProcessingInProg = true; // eventProcessingInProg = true;
// Process all events before attempting to render viewport // // Process all events before attempting to render viewport
QCoreApplication::processEvents(); // QCoreApplication::processEvents();
eventProcessingInProg = false; // eventProcessingInProg = false;
} //}
// Update Input Devices // Update Input Devices
FCEUD_UpdateInput(); //FCEUD_UpdateInput();
//printf("EMU Frame Finish\n"); //printf("EMU Frame Finish\n");
@ -4609,7 +4610,7 @@ void consoleWin_t::emuFrameFinish(void)
// QtScriptManager::getInstance()->frameFinishedUpdate(); // QtScriptManager::getInstance()->frameFinishedUpdate();
//#endif //#endif
transferVideoBuffer(); transferVideoBuffer(false);
} }
void consoleWin_t::updatePeriodic(void) void consoleWin_t::updatePeriodic(void)
@ -4634,7 +4635,7 @@ void consoleWin_t::updatePeriodic(void)
FCEUD_UpdateInput(); FCEUD_UpdateInput();
// RePaint Game Viewport // RePaint Game Viewport
transferVideoBuffer(); transferVideoBuffer(true);
// Low Rate Updates // Low Rate Updates
if ( (updateCounter % 30) == 0 ) if ( (updateCounter % 30) == 0 )

View File

@ -278,6 +278,7 @@ class consoleWin_t : public QMainWindow
bool contextMenuEnable; bool contextMenuEnable;
bool soundUseGlobalFocus; bool soundUseGlobalFocus;
bool autoHideMenuFullscreen; bool autoHideMenuFullscreen;
bool redrawVideoRequest;
std::list <std::string*> romList; std::list <std::string*> romList;
std::vector <autoFireMenuAction*> afActList; std::vector <autoFireMenuAction*> afActList;
@ -313,7 +314,7 @@ class consoleWin_t : public QMainWindow
void changeState(int slot); void changeState(int slot);
void saveState(int slot); void saveState(int slot);
void loadState(int slot); void loadState(int slot);
void transferVideoBuffer(void); void transferVideoBuffer(bool allowRedraw);
void syncAutoFirePatternMenu(void); void syncAutoFirePatternMenu(void);
std::string findHelpFile(void); std::string findHelpFile(void);