changed QThread setup to be a separate object from the console window.
This commit is contained in:
parent
acc02ee98e
commit
f2e7b66c61
|
@ -9,7 +9,7 @@
|
|||
#include "Qt/keyscan.h"
|
||||
#include "Qt/nes_shm.h"
|
||||
|
||||
gameWin_t::gameWin_t(QWidget *parent)
|
||||
consoleWin_t::consoleWin_t(QWidget *parent)
|
||||
: QMainWindow( parent )
|
||||
{
|
||||
|
||||
|
@ -21,27 +21,22 @@ gameWin_t::gameWin_t(QWidget *parent)
|
|||
setCentralWidget(viewport);
|
||||
|
||||
gameTimer = new QTimer( this );
|
||||
gameThread = new QThread( this );
|
||||
worker = new gameWorkerThread_t();
|
||||
mutex = new QMutex( QMutex::NonRecursive );
|
||||
emulatorThread = new emulatorThread_t();
|
||||
|
||||
worker->moveToThread(gameThread);
|
||||
connect(gameThread, &QThread::finished, worker, &QObject::deleteLater);
|
||||
connect(gameThread, SIGNAL (started()), worker, SLOT( runEmulator() ));
|
||||
connect(worker, SIGNAL (finished()), gameThread, SLOT (quit()));
|
||||
connect(worker, SIGNAL (finished()), worker, SLOT (deleteLater()));
|
||||
connect(emulatorThread, &QThread::finished, emulatorThread, &QObject::deleteLater);
|
||||
|
||||
connect( gameTimer, &QTimer::timeout, this, &gameWin_t::runGameFrame );
|
||||
connect( gameTimer, &QTimer::timeout, this, &consoleWin_t::updateDisplay );
|
||||
|
||||
gameTimer->setTimerType( Qt::PreciseTimer );
|
||||
gameTimer->start( 16 );
|
||||
gameTimer->start( 16 ); // 60hz
|
||||
|
||||
gameThread->start();
|
||||
emulatorThread->start();
|
||||
|
||||
gamePadConfWin = NULL;
|
||||
}
|
||||
|
||||
gameWin_t::~gameWin_t(void)
|
||||
consoleWin_t::~consoleWin_t(void)
|
||||
{
|
||||
nes_shm->runEmulator = 0;
|
||||
|
||||
|
@ -54,14 +49,14 @@ gameWin_t::~gameWin_t(void)
|
|||
fceuWrapperUnLock();
|
||||
|
||||
//printf("Thread Finished: %i \n", gameThread->isFinished() );
|
||||
gameThread->exit(0);
|
||||
gameThread->wait();
|
||||
emulatorThread->quit();
|
||||
emulatorThread->wait();
|
||||
|
||||
delete viewport;
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
void gameWin_t::setCyclePeriodms( int ms )
|
||||
void consoleWin_t::setCyclePeriodms( int ms )
|
||||
{
|
||||
// If timer is already running, it will be restarted.
|
||||
gameTimer->start( ms );
|
||||
|
@ -69,7 +64,7 @@ void gameWin_t::setCyclePeriodms( int ms )
|
|||
//printf("Period Set to: %i ms \n", ms );
|
||||
}
|
||||
|
||||
void gameWin_t::closeEvent(QCloseEvent *event)
|
||||
void consoleWin_t::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
//printf("Main Window Close Event\n");
|
||||
if ( gamePadConfWin != NULL )
|
||||
|
@ -82,20 +77,20 @@ void gameWin_t::closeEvent(QCloseEvent *event)
|
|||
closeApp();
|
||||
}
|
||||
|
||||
void gameWin_t::keyPressEvent(QKeyEvent *event)
|
||||
void consoleWin_t::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
//printf("Key Press: 0x%x \n", event->key() );
|
||||
pushKeyEvent( event, 1 );
|
||||
}
|
||||
|
||||
void gameWin_t::keyReleaseEvent(QKeyEvent *event)
|
||||
void consoleWin_t::keyReleaseEvent(QKeyEvent *event)
|
||||
{
|
||||
//printf("Key Release: 0x%x \n", event->key() );
|
||||
pushKeyEvent( event, 0 );
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
void gameWin_t::createMainMenu(void)
|
||||
void consoleWin_t::createMainMenu(void)
|
||||
{
|
||||
// This is needed for menu bar to show up on MacOS
|
||||
menuBar()->setNativeMenuBar(false);
|
||||
|
@ -161,7 +156,7 @@ void gameWin_t::createMainMenu(void)
|
|||
helpMenu->addAction(aboutAct);
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
void gameWin_t::closeApp(void)
|
||||
void consoleWin_t::closeApp(void)
|
||||
{
|
||||
nes_shm->runEmulator = 0;
|
||||
|
||||
|
@ -180,7 +175,7 @@ void gameWin_t::closeApp(void)
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void gameWin_t::openROMFile(void)
|
||||
void consoleWin_t::openROMFile(void)
|
||||
{
|
||||
int ret;
|
||||
QString filename;
|
||||
|
@ -231,14 +226,14 @@ void gameWin_t::openROMFile(void)
|
|||
return;
|
||||
}
|
||||
|
||||
void gameWin_t::closeROMCB(void)
|
||||
void consoleWin_t::closeROMCB(void)
|
||||
{
|
||||
fceuWrapperLock();
|
||||
CloseGame();
|
||||
fceuWrapperUnLock();
|
||||
}
|
||||
|
||||
void gameWin_t::openGamePadConfWin(void)
|
||||
void consoleWin_t::openGamePadConfWin(void)
|
||||
{
|
||||
if ( gamePadConfWin != NULL )
|
||||
{
|
||||
|
@ -256,7 +251,7 @@ void gameWin_t::openGamePadConfWin(void)
|
|||
//printf("GamePad Config Window Destroyed\n");
|
||||
}
|
||||
|
||||
void gameWin_t::openGameSndConfWin(void)
|
||||
void consoleWin_t::openGameSndConfWin(void)
|
||||
{
|
||||
GameSndConfDialog_t *sndConfWin;
|
||||
|
||||
|
@ -272,13 +267,13 @@ void gameWin_t::openGameSndConfWin(void)
|
|||
printf("Sound Config Window Destroyed\n");
|
||||
}
|
||||
|
||||
void gameWin_t::aboutQPlot(void)
|
||||
void consoleWin_t::aboutQPlot(void)
|
||||
{
|
||||
printf("About QPlot\n");
|
||||
return;
|
||||
}
|
||||
|
||||
void gameWin_t::runGameFrame(void)
|
||||
void consoleWin_t::updateDisplay(void)
|
||||
{
|
||||
//struct timespec ts;
|
||||
//double t;
|
||||
|
@ -293,7 +288,7 @@ void gameWin_t::runGameFrame(void)
|
|||
return;
|
||||
}
|
||||
|
||||
void gameWorkerThread_t::runEmulator(void)
|
||||
void emulatorThread_t::run(void)
|
||||
{
|
||||
printf("Emulator Start\n");
|
||||
nes_shm->runEmulator = 1;
|
||||
|
|
|
@ -21,23 +21,23 @@
|
|||
#include "Qt/GameViewerSDL.h"
|
||||
#include "Qt/GamePadConf.h"
|
||||
|
||||
class gameWorkerThread_t : public QObject
|
||||
class emulatorThread_t : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
void runEmulator( void );
|
||||
//public slots:
|
||||
void run( void ) override;
|
||||
signals:
|
||||
void finished();
|
||||
};
|
||||
|
||||
class gameWin_t : public QMainWindow
|
||||
class consoleWin_t : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
gameWin_t(QWidget *parent = 0);
|
||||
~gameWin_t(void);
|
||||
consoleWin_t(QWidget *parent = 0);
|
||||
~consoleWin_t(void);
|
||||
|
||||
gameViewGL_t *viewport;
|
||||
//gameViewSDL_t *viewport;
|
||||
|
@ -59,8 +59,7 @@ class gameWin_t : public QMainWindow
|
|||
QAction *aboutAct;
|
||||
|
||||
QTimer *gameTimer;
|
||||
QThread *gameThread;
|
||||
gameWorkerThread_t *worker;
|
||||
emulatorThread_t *emulatorThread;
|
||||
|
||||
GamePadConfDialog_t *gamePadConfWin;
|
||||
|
||||
|
@ -79,10 +78,10 @@ class gameWin_t : public QMainWindow
|
|||
void aboutQPlot(void);
|
||||
void openGamePadConfWin(void);
|
||||
void openGameSndConfWin(void);
|
||||
void runGameFrame(void);
|
||||
void updateDisplay(void);
|
||||
|
||||
};
|
||||
|
||||
extern gameWin_t *gameWindow;
|
||||
extern consoleWin_t *consoleWindow;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -776,7 +776,7 @@ static void DoFun(int frameskip, int periodic_saves)
|
|||
|
||||
void fceuWrapperLock(void)
|
||||
{
|
||||
gameWindow->mutex->lock();
|
||||
consoleWindow->mutex->lock();
|
||||
mutexLocked = 1;
|
||||
}
|
||||
|
||||
|
@ -784,7 +784,7 @@ bool fceuWrapperTryLock(int timeout)
|
|||
{
|
||||
bool lockAcq;
|
||||
|
||||
lockAcq = gameWindow->mutex->tryLock( timeout );
|
||||
lockAcq = consoleWindow->mutex->tryLock( timeout );
|
||||
|
||||
if ( lockAcq )
|
||||
{
|
||||
|
@ -797,7 +797,7 @@ void fceuWrapperUnLock(void)
|
|||
{
|
||||
if ( mutexLocked )
|
||||
{
|
||||
gameWindow->mutex->unlock();
|
||||
consoleWindow->mutex->unlock();
|
||||
mutexLocked = 0;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "Qt/GameApp.h"
|
||||
#include "Qt/fceuWrapper.h"
|
||||
|
||||
gameWin_t *gameWindow = NULL;
|
||||
consoleWin_t *consoleWindow = NULL;
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
|
@ -12,18 +12,18 @@ int main( int argc, char *argv[] )
|
|||
|
||||
fceuWrapperInit( argc, argv );
|
||||
|
||||
gameWindow = new gameWin_t();
|
||||
consoleWindow = new consoleWin_t();
|
||||
|
||||
gameWindow->resize( 512, 512 );
|
||||
gameWindow->show();
|
||||
consoleWindow->resize( 512, 512 );
|
||||
consoleWindow->show();
|
||||
|
||||
gameWindow->viewport->init();
|
||||
consoleWindow->viewport->init();
|
||||
|
||||
retval = app.exec();
|
||||
|
||||
//printf("App Return: %i \n", retval );
|
||||
|
||||
delete gameWindow;
|
||||
delete consoleWindow;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue