Moved the physical input update to the main thread since the MAC OS X SDL2 requires it to be so.

This commit is contained in:
Matthew Budd 2020-07-05 21:16:31 -04:00
parent 70a00fab13
commit 4dca42bfca
7 changed files with 60 additions and 46 deletions

View File

@ -2,6 +2,9 @@
//
#include <QFileDialog>
#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;
}

View File

@ -78,7 +78,7 @@ class consoleWin_t : public QMainWindow
void aboutQPlot(void);
void openGamePadConfWin(void);
void openGameSndConfWin(void);
void updateDisplay(void);
void update(void);
};

View File

@ -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<Count; ++n)
MonoBuf[n] = Buffer[n] & 0xFFFF;
NESVideoLoggingAudio
(
MonoBuf,
FSettings.SndRate, 16, 1,
Count
);
delete [] MonoBuf;
}
Count /= 2;
if(inited & 1)
{
if(Count > 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<Count; ++n)
{
MonoBuf[n] = Buffer[n] & 0xFFFF;
}
NESVideoLoggingAudio
(
MonoBuf,
FSettings.SndRate, 16, 1,
Count
);
delete [] MonoBuf;
}
Count /= 2;
if (inited & 1)
{
if (Count > 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

View File

@ -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];

View File

@ -1,6 +1,8 @@
#ifndef _aosdfjk02fmasf
#define _aosdfjk02fmasf
#include <stdint.h>
#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

View File

@ -25,6 +25,7 @@ struct nes_shm_t
int pitch;
char runEmulator;
char blitUpdated;
// Pass Key Events back to QT Gui
struct

View File

@ -379,6 +379,7 @@ BlitScreen(uint8 *XBuf)
{
Blit8ToHigh(XBuf + NOFFSET, dest, NWIDTH, s_tlines, pitch, 1, 1);
}
nes_shm->blitUpdated = 1;
//guiPixelBufferReDraw();