From 4dca42bfcaf8ed0831a39b1080f87ac037867cc7 Mon Sep 17 00:00:00 2001 From: Matthew Budd Date: Sun, 5 Jul 2020 21:16:31 -0400 Subject: [PATCH] Moved the physical input update to the main thread since the MAC OS X SDL2 requires it to be so. --- src/drivers/Qt/ConsoleWindow.cpp | 21 ++++++++-- src/drivers/Qt/ConsoleWindow.h | 2 +- src/drivers/Qt/fceuWrapper.cpp | 71 +++++++++++++++----------------- src/drivers/Qt/input.cpp | 4 +- src/drivers/Qt/input.h | 6 ++- src/drivers/Qt/nes_shm.h | 1 + src/drivers/Qt/sdl-video.cpp | 1 + 7 files changed, 60 insertions(+), 46 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 2207beb3..41997c0f 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -2,6 +2,9 @@ // #include +#include "Qt/main.h" +#include "Qt/dface.h" +#include "Qt/input.h" #include "Qt/ConsoleWindow.h" #include "Qt/GamePadConf.h" #include "Qt/ConsoleSoundConf.h" @@ -26,10 +29,11 @@ consoleWin_t::consoleWin_t(QWidget *parent) connect(emulatorThread, &QThread::finished, emulatorThread, &QObject::deleteLater); - connect( gameTimer, &QTimer::timeout, this, &consoleWin_t::updateDisplay ); + connect( gameTimer, &QTimer::timeout, this, &consoleWin_t::update ); gameTimer->setTimerType( Qt::PreciseTimer ); - gameTimer->start( 16 ); // 60hz + //gameTimer->start( 16 ); // 60hz + gameTimer->start( 8 ); // 120hz emulatorThread->start(); @@ -273,7 +277,7 @@ void consoleWin_t::aboutQPlot(void) return; } -void consoleWin_t::updateDisplay(void) +void consoleWin_t::update(void) { //struct timespec ts; //double t; @@ -283,7 +287,16 @@ void consoleWin_t::updateDisplay(void) //t = (double)ts.tv_sec + (double)(ts.tv_nsec * 1.0e-9); //printf("Run Frame %f\n", t); - viewport->repaint(); + // Update Input Devices + FCEUD_UpdateInput(); + + // RePaint Game Viewport + if ( nes_shm->blitUpdated ) + { + nes_shm->blitUpdated = 0; + + viewport->repaint(); + } return; } diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 048e88f2..10444c5a 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -78,7 +78,7 @@ class consoleWin_t : public QMainWindow void aboutQPlot(void); void openGamePadConfWin(void); void openGameSndConfWin(void); - void updateDisplay(void); + void update(void); }; diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index 6599d819..f7698afa 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -610,36 +610,40 @@ FCEUD_Update(uint8 *XBuf, extern int FCEUDnetplay; #ifdef CREATE_AVI - if(LoggingEnabled == 2 || (eoptions&EO_NOTHROTTLE)) + if (LoggingEnabled == 2 || (eoptions&EO_NOTHROTTLE)) { - if(LoggingEnabled == 2) - { - int16* MonoBuf = new int16[Count]; - int n; - for(n=0; n GetWriteSound()) Count = GetWriteSound(); - if (!mutecapture) - if(Count > 0 && Buffer) WriteSound(Buffer,Count); - } - if(inited & 2) - FCEUD_UpdateInput(); - if(XBuf && (inited & 4)) BlitScreen(XBuf); + if(LoggingEnabled == 2) + { + int16* MonoBuf = new int16[Count]; + int n; + for(n=0; n GetWriteSound()) Count = GetWriteSound(); + + if (!mutecapture) + { + if(Count > 0 && Buffer) WriteSound(Buffer,Count); + } + } + //if (inited & 2) + // FCEUD_UpdateInput(); + if(XBuf && (inited & 4)) BlitScreen(XBuf); - //SpeedThrottle(); return; - } + } #endif int ocount = Count; @@ -732,15 +736,6 @@ FCEUD_Update(uint8 *XBuf, BlitScreen(XBuf); blitDone = 1; } } - FCEUD_UpdateInput(); - //if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE)) - // SpeedThrottle(); - //if(XBuf && (inited&4)) - //{ - // BlitScreen(XBuf); - //} - //if(Count) - // WriteSound(Buffer,Count,NoWaiting); //FCEUD_UpdateInput(); } @@ -823,7 +818,9 @@ int fceuWrapperUpdate( void ) while ( SpeedThrottle() ) { - FCEUD_UpdateInput(); + // Input device processing is in main thread + // because to MAC OS X SDL2 requires it. + //FCEUD_UpdateInput(); } } else diff --git a/src/drivers/Qt/input.cpp b/src/drivers/Qt/input.cpp index 049a5a97..552f7ad8 100644 --- a/src/drivers/Qt/input.cpp +++ b/src/drivers/Qt/input.cpp @@ -1197,7 +1197,7 @@ static uint8 fkbkeys[0x48]; /** * Update all of the input devices required for the active game. */ -void FCEUD_UpdateInput () +void FCEUD_UpdateInput(void) { int x; int t = 0; @@ -1632,7 +1632,7 @@ const char * ButtonName (const ButtConfig * bc, int which) * Waits for a button input and returns the information as to which * button was pressed. Used in button configuration. */ -int DWaitButton (const uint8 * text, ButtConfig * bc, int wb, int *buttonConfigStatus ) +int DWaitButton (const uint8_t * text, ButtConfig * bc, int wb, int *buttonConfigStatus ) { SDL_Event event; static int32 LastAx[64][64]; diff --git a/src/drivers/Qt/input.h b/src/drivers/Qt/input.h index 35361f56..af5f0c47 100644 --- a/src/drivers/Qt/input.h +++ b/src/drivers/Qt/input.h @@ -1,6 +1,8 @@ #ifndef _aosdfjk02fmasf #define _aosdfjk02fmasf +#include + #include "common/configSys.h" #define MAXBUTTCONFIG 4 @@ -15,7 +17,7 @@ struct ButtConfig int ButtType[MAXBUTTCONFIG]; int DeviceNum[MAXBUTTCONFIG]; int ButtonNum[MAXBUTTCONFIG]; - uint32 NumC; + uint32_t NumC; //uint64 DeviceID[MAXBUTTCONFIG]; /* TODO */ }; @@ -30,7 +32,7 @@ int getKeyState( int k ); int ButtonConfigBegin(); void ButtonConfigEnd(); void ConfigButton(char *text, ButtConfig *bc); -int DWaitButton(const uint8 *text, ButtConfig *bc, int wb, int *buttonConfigStatus = NULL); +int DWaitButton(const uint8_t *text, ButtConfig *bc, int wb, int *buttonConfigStatus = NULL); #define FCFGD_GAMEPAD 1 diff --git a/src/drivers/Qt/nes_shm.h b/src/drivers/Qt/nes_shm.h index d626afe4..0b63998d 100644 --- a/src/drivers/Qt/nes_shm.h +++ b/src/drivers/Qt/nes_shm.h @@ -25,6 +25,7 @@ struct nes_shm_t int pitch; char runEmulator; + char blitUpdated; // Pass Key Events back to QT Gui struct diff --git a/src/drivers/Qt/sdl-video.cpp b/src/drivers/Qt/sdl-video.cpp index cbc8c441..79e6c393 100644 --- a/src/drivers/Qt/sdl-video.cpp +++ b/src/drivers/Qt/sdl-video.cpp @@ -379,6 +379,7 @@ BlitScreen(uint8 *XBuf) { Blit8ToHigh(XBuf + NOFFSET, dest, NWIDTH, s_tlines, pitch, 1, 1); } + nes_shm->blitUpdated = 1; //guiPixelBufferReDraw();