route run/pause/unpause through the message queue system
This commit is contained in:
parent
9b13b5e492
commit
438c989716
|
@ -75,7 +75,7 @@ void EmuThread::attachWindow(MainWindow* window)
|
||||||
connect(this, SIGNAL(windowTitleChange(QString)), window, SLOT(onTitleUpdate(QString)));
|
connect(this, SIGNAL(windowTitleChange(QString)), window, SLOT(onTitleUpdate(QString)));
|
||||||
connect(this, SIGNAL(windowEmuStart()), window, SLOT(onEmuStart()));
|
connect(this, SIGNAL(windowEmuStart()), window, SLOT(onEmuStart()));
|
||||||
connect(this, SIGNAL(windowEmuStop()), window, SLOT(onEmuStop()));
|
connect(this, SIGNAL(windowEmuStop()), window, SLOT(onEmuStop()));
|
||||||
connect(this, SIGNAL(windowEmuPause()), window->actPause, SLOT(trigger()));
|
connect(this, SIGNAL(windowEmuPause(bool)), window, SLOT(onEmuPause(bool)));
|
||||||
connect(this, SIGNAL(windowEmuReset()), window->actReset, SLOT(trigger()));
|
connect(this, SIGNAL(windowEmuReset()), window->actReset, SLOT(trigger()));
|
||||||
connect(this, SIGNAL(windowEmuFrameStep()), window->actFrameStep, SLOT(trigger()));
|
connect(this, SIGNAL(windowEmuFrameStep()), window->actFrameStep, SLOT(trigger()));
|
||||||
connect(this, SIGNAL(windowLimitFPSChange()), window->actLimitFramerate, SLOT(trigger()));
|
connect(this, SIGNAL(windowLimitFPSChange()), window->actLimitFramerate, SLOT(trigger()));
|
||||||
|
@ -91,7 +91,7 @@ void EmuThread::detachWindow(MainWindow* window)
|
||||||
disconnect(this, SIGNAL(windowTitleChange(QString)), window, SLOT(onTitleUpdate(QString)));
|
disconnect(this, SIGNAL(windowTitleChange(QString)), window, SLOT(onTitleUpdate(QString)));
|
||||||
disconnect(this, SIGNAL(windowEmuStart()), window, SLOT(onEmuStart()));
|
disconnect(this, SIGNAL(windowEmuStart()), window, SLOT(onEmuStart()));
|
||||||
disconnect(this, SIGNAL(windowEmuStop()), window, SLOT(onEmuStop()));
|
disconnect(this, SIGNAL(windowEmuStop()), window, SLOT(onEmuStop()));
|
||||||
disconnect(this, SIGNAL(windowEmuPause()), window->actPause, SLOT(trigger()));
|
disconnect(this, SIGNAL(windowEmuPause(bool)), window, SLOT(onEmuPause(bool)));
|
||||||
disconnect(this, SIGNAL(windowEmuReset()), window->actReset, SLOT(trigger()));
|
disconnect(this, SIGNAL(windowEmuReset()), window->actReset, SLOT(trigger()));
|
||||||
disconnect(this, SIGNAL(windowEmuFrameStep()), window->actFrameStep, SLOT(trigger()));
|
disconnect(this, SIGNAL(windowEmuFrameStep()), window->actFrameStep, SLOT(trigger()));
|
||||||
disconnect(this, SIGNAL(windowLimitFPSChange()), window->actLimitFramerate, SLOT(trigger()));
|
disconnect(this, SIGNAL(windowLimitFPSChange()), window->actLimitFramerate, SLOT(trigger()));
|
||||||
|
@ -158,7 +158,7 @@ void EmuThread::run()
|
||||||
|
|
||||||
if (emuInstance->hotkeyPressed(HK_FastForwardToggle)) emit windowLimitFPSChange();
|
if (emuInstance->hotkeyPressed(HK_FastForwardToggle)) emit windowLimitFPSChange();
|
||||||
|
|
||||||
if (emuInstance->hotkeyPressed(HK_Pause)) emit windowEmuPause();
|
if (emuInstance->hotkeyPressed(HK_Pause)) emuTogglePause();
|
||||||
if (emuInstance->hotkeyPressed(HK_Reset)) emit windowEmuReset();
|
if (emuInstance->hotkeyPressed(HK_Reset)) emit windowEmuReset();
|
||||||
if (emuInstance->hotkeyPressed(HK_FrameStep)) emit windowEmuFrameStep();
|
if (emuInstance->hotkeyPressed(HK_FrameStep)) emit windowEmuFrameStep();
|
||||||
|
|
||||||
|
@ -471,11 +471,13 @@ void EmuThread::sendMessage(Message msg)
|
||||||
|
|
||||||
void EmuThread::waitMessage()
|
void EmuThread::waitMessage()
|
||||||
{
|
{
|
||||||
|
if (QThread::currentThread() == this) return;
|
||||||
msgSemaphore.acquire();
|
msgSemaphore.acquire();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::waitAllMessages()
|
void EmuThread::waitAllMessages()
|
||||||
{
|
{
|
||||||
|
if (QThread::currentThread() == this) return;
|
||||||
msgSemaphore.acquire(msgSemaphore.available());
|
msgSemaphore.acquire(msgSemaphore.available());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,10 +489,51 @@ void EmuThread::handleMessages()
|
||||||
Message msg = msgQueue.dequeue();
|
Message msg = msgQueue.dequeue();
|
||||||
switch (msg.type)
|
switch (msg.type)
|
||||||
{
|
{
|
||||||
|
case msg_EmuRun:
|
||||||
|
EmuRunning = emuStatus_Running;
|
||||||
|
EmuPauseStack = EmuPauseStackRunning;
|
||||||
|
emuActive = true;
|
||||||
|
|
||||||
|
emuInstance->audioEnable();
|
||||||
|
emit windowEmuStart();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case msg_EmuPause:
|
||||||
|
EmuPauseStack++;
|
||||||
|
if (EmuPauseStack > EmuPauseStackPauseThreshold) break;
|
||||||
|
|
||||||
|
PrevEmuStatus = EmuRunning;
|
||||||
|
EmuRunning = emuStatus_Paused;
|
||||||
|
|
||||||
|
if (PrevEmuStatus != emuStatus_Paused)
|
||||||
|
{
|
||||||
|
emuInstance->audioDisable();
|
||||||
|
emit windowEmuPause(true);
|
||||||
|
emuInstance->osdAddMessage(0, "Paused");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case msg_EmuUnpause:
|
||||||
|
if (EmuPauseStack < EmuPauseStackPauseThreshold) break;
|
||||||
|
|
||||||
|
EmuPauseStack--;
|
||||||
|
if (EmuPauseStack >= EmuPauseStackPauseThreshold) break;
|
||||||
|
|
||||||
|
EmuRunning = PrevEmuStatus;
|
||||||
|
|
||||||
|
if (EmuRunning != emuStatus_Paused)
|
||||||
|
{
|
||||||
|
emuInstance->audioEnable();
|
||||||
|
emit windowEmuPause(false);
|
||||||
|
emuInstance->osdAddMessage(0, "Resumed");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case msg_EmuStop:
|
case msg_EmuStop:
|
||||||
if (msg.stopExternal) emuInstance->nds->Stop();
|
if (msg.stopExternal) emuInstance->nds->Stop();
|
||||||
EmuRunning = emuStatus_Paused;
|
EmuRunning = emuStatus_Paused;
|
||||||
emuActive = false;
|
emuActive = false;
|
||||||
|
|
||||||
emuInstance->audioDisable();
|
emuInstance->audioDisable();
|
||||||
emit windowEmuStop();
|
emit windowEmuStop();
|
||||||
break;
|
break;
|
||||||
|
@ -516,17 +559,6 @@ void EmuThread::changeWindowTitle(char* title)
|
||||||
emit windowTitleChange(QString(title));
|
emit windowTitleChange(QString(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuRun()
|
|
||||||
{
|
|
||||||
EmuRunning = emuStatus_Running;
|
|
||||||
EmuPauseStack = EmuPauseStackRunning;
|
|
||||||
emuActive = true;
|
|
||||||
|
|
||||||
// checkme
|
|
||||||
emit windowEmuStart();
|
|
||||||
emuInstance->audioEnable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void EmuThread::initContext()
|
void EmuThread::initContext()
|
||||||
{
|
{
|
||||||
sendMessage(msg_InitGL);
|
sendMessage(msg_InitGL);
|
||||||
|
@ -539,33 +571,36 @@ void EmuThread::deinitContext()
|
||||||
waitMessage();
|
waitMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EmuThread::emuRun()
|
||||||
|
{
|
||||||
|
sendMessage(msg_EmuRun);
|
||||||
|
waitMessage();
|
||||||
|
}
|
||||||
|
|
||||||
void EmuThread::emuPause()
|
void EmuThread::emuPause()
|
||||||
{
|
{
|
||||||
EmuPauseStack++;
|
sendMessage(msg_EmuPause);
|
||||||
if (EmuPauseStack > EmuPauseStackPauseThreshold) return;
|
waitMessage();
|
||||||
|
|
||||||
PrevEmuStatus = EmuRunning;
|
|
||||||
EmuRunning = emuStatus_Paused;
|
|
||||||
while (EmuStatus != emuStatus_Paused);
|
|
||||||
|
|
||||||
emuInstance->audioDisable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuUnpause()
|
void EmuThread::emuUnpause()
|
||||||
{
|
{
|
||||||
if (EmuPauseStack < EmuPauseStackPauseThreshold) return;
|
sendMessage(msg_EmuUnpause);
|
||||||
|
waitMessage();
|
||||||
|
}
|
||||||
|
|
||||||
EmuPauseStack--;
|
void EmuThread::emuTogglePause()
|
||||||
if (EmuPauseStack >= EmuPauseStackPauseThreshold) return;
|
{
|
||||||
|
if (EmuRunning == emuStatus_Paused)
|
||||||
EmuRunning = PrevEmuStatus;
|
emuUnpause();
|
||||||
|
else
|
||||||
emuInstance->audioEnable();
|
emuPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuStop(bool external)
|
void EmuThread::emuStop(bool external)
|
||||||
{
|
{
|
||||||
sendMessage({.type = msg_EmuStop, .stopExternal = external});
|
sendMessage({.type = msg_EmuStop, .stopExternal = external});
|
||||||
|
waitMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::emuExit()
|
void EmuThread::emuExit()
|
||||||
|
@ -578,7 +613,7 @@ void EmuThread::emuExit()
|
||||||
|
|
||||||
void EmuThread::emuFrameStep()
|
void EmuThread::emuFrameStep()
|
||||||
{
|
{
|
||||||
if (EmuPauseStack < EmuPauseStackPauseThreshold) emit windowEmuPause();
|
//if (EmuPauseStack < EmuPauseStackPauseThreshold) emit windowEmuPause();
|
||||||
EmuRunning = emuStatus_FrameStep;
|
EmuRunning = emuStatus_FrameStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,9 @@ public:
|
||||||
|
|
||||||
enum MessageType
|
enum MessageType
|
||||||
{
|
{
|
||||||
|
msg_EmuRun,
|
||||||
|
msg_EmuPause,
|
||||||
|
msg_EmuUnpause,
|
||||||
msg_EmuStop,
|
msg_EmuStop,
|
||||||
|
|
||||||
msg_InitGL,
|
msg_InitGL,
|
||||||
|
@ -87,6 +90,7 @@ public:
|
||||||
void emuRun();
|
void emuRun();
|
||||||
void emuPause();
|
void emuPause();
|
||||||
void emuUnpause();
|
void emuUnpause();
|
||||||
|
void emuTogglePause();
|
||||||
void emuStop(bool external);
|
void emuStop(bool external);
|
||||||
void emuExit();
|
void emuExit();
|
||||||
void emuFrameStep();
|
void emuFrameStep();
|
||||||
|
@ -107,7 +111,7 @@ signals:
|
||||||
|
|
||||||
void windowEmuStart();
|
void windowEmuStart();
|
||||||
void windowEmuStop();
|
void windowEmuStop();
|
||||||
void windowEmuPause();
|
void windowEmuPause(bool pause);
|
||||||
void windowEmuReset();
|
void windowEmuReset();
|
||||||
void windowEmuFrameStep();
|
void windowEmuFrameStep();
|
||||||
|
|
||||||
|
|
|
@ -1592,13 +1592,11 @@ void MainWindow::onPause(bool checked)
|
||||||
if (checked)
|
if (checked)
|
||||||
{
|
{
|
||||||
emuThread->emuPause();
|
emuThread->emuPause();
|
||||||
emuInstance->osdAddMessage(0, "Paused");
|
|
||||||
pausedManually = true;
|
pausedManually = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emuThread->emuUnpause();
|
emuThread->emuUnpause();
|
||||||
emuInstance->osdAddMessage(0, "Resumed");
|
|
||||||
pausedManually = false;
|
pausedManually = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1622,7 +1620,6 @@ void MainWindow::onStop()
|
||||||
if (!emuThread->emuIsActive()) return;
|
if (!emuThread->emuIsActive()) return;
|
||||||
|
|
||||||
emuThread->emuStop(true);
|
emuThread->emuStop(true);
|
||||||
emuThread->waitMessage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onFrameStep()
|
void MainWindow::onFrameStep()
|
||||||
|
@ -2086,6 +2083,11 @@ void MainWindow::onEmuStop()
|
||||||
actTitleManager->setEnabled(!globalCfg.GetString("DSi.NANDPath").empty());
|
actTitleManager->setEnabled(!globalCfg.GetString("DSi.NANDPath").empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onEmuPause(bool pause)
|
||||||
|
{
|
||||||
|
actPause->setChecked(pause);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onUpdateVideoSettings(bool glchange)
|
void MainWindow::onUpdateVideoSettings(bool glchange)
|
||||||
{
|
{
|
||||||
if (glchange)
|
if (glchange)
|
||||||
|
|
|
@ -208,6 +208,7 @@ private slots:
|
||||||
|
|
||||||
void onEmuStart();
|
void onEmuStart();
|
||||||
void onEmuStop();
|
void onEmuStop();
|
||||||
|
void onEmuPause(bool pause);
|
||||||
|
|
||||||
void onUpdateVideoSettings(bool glchange);
|
void onUpdateVideoSettings(bool glchange);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue