synchronize pause/unpause across all instances
Some checks are pending
macOS / ${{ matrix.arch }} (arm64) (push) Waiting to run
macOS / ${{ matrix.arch }} (x86_64) (push) Waiting to run
macOS / Universal binary (push) Blocked by required conditions
Ubuntu / x86_64 (push) Waiting to run
Ubuntu / aarch64 (push) Waiting to run
Windows / build (push) Waiting to run

This commit is contained in:
Arisotura 2024-10-27 11:21:30 +01:00
parent e6f0d77aa0
commit e576538268
7 changed files with 40 additions and 19 deletions

View File

@ -241,11 +241,24 @@ void EmuInstance::deleteAllWindows()
}
void EmuInstance::updateConfigInfo(int kind)
void EmuInstance::broadcastCommand(int cmd)
{
switch (kind)
broadcastInstanceCommand(cmd, instanceID);
}
void EmuInstance::handleCommand(int cmd)
{
switch (cmd)
{
case Config_RecentFiles:
case InstCmd_Pause:
emuThread->emuPause(false);
break;
case InstCmd_Unpause:
emuThread->emuUnpause(false);
break;
case InstCmd_UpdateRecentFiles:
for (int i = 0; i < kMaxWindows; i++)
{
if (windowList[i])

View File

@ -92,7 +92,8 @@ public:
Config::Table& getGlobalConfig() { return globalCfg; }
Config::Table& getLocalConfig() { return localCfg; }
void updateConfigInfo(int kind);
void broadcastCommand(int cmd);
void handleCommand(int cmd);
std::string instanceFileSuffix();

View File

@ -70,7 +70,6 @@ EmuThread::EmuThread(EmuInstance* inst, QObject* parent) : QThread(parent)
void EmuThread::attachWindow(MainWindow* window)
{
//connect(this, SIGNAL(windowUpdate()), window->panel, SLOT(repaint()));
connect(this, SIGNAL(windowTitleChange(QString)), window, SLOT(onTitleUpdate(QString)));
connect(this, SIGNAL(windowEmuStart()), window, SLOT(onEmuStart()));
connect(this, SIGNAL(windowEmuStop()), window, SLOT(onEmuStop()));
@ -89,7 +88,6 @@ void EmuThread::attachWindow(MainWindow* window)
void EmuThread::detachWindow(MainWindow* window)
{
//disconnect(this, SIGNAL(windowUpdate()), window->panel, SLOT(repaint()));
disconnect(this, SIGNAL(windowTitleChange(QString)), window, SLOT(onTitleUpdate(QString)));
disconnect(this, SIGNAL(windowEmuStart()), window, SLOT(onEmuStart()));
disconnect(this, SIGNAL(windowEmuStop()), window, SLOT(onEmuStop()));
@ -676,24 +674,30 @@ void EmuThread::emuRun()
waitMessage();
}
void EmuThread::emuPause()
void EmuThread::emuPause(bool broadcast)
{
sendMessage(msg_EmuPause);
waitMessage();
if (broadcast)
emuInstance->broadcastCommand(InstCmd_Pause);
}
void EmuThread::emuUnpause()
void EmuThread::emuUnpause(bool broadcast)
{
sendMessage(msg_EmuUnpause);
waitMessage();
if (broadcast)
emuInstance->broadcastCommand(InstCmd_Unpause);
}
void EmuThread::emuTogglePause()
void EmuThread::emuTogglePause(bool broadcast)
{
if (emuStatus == emuStatus_Paused)
emuUnpause();
emuUnpause(broadcast);
else
emuPause();
emuPause(broadcast);
}
void EmuThread::emuStop(bool external)

View File

@ -104,9 +104,9 @@ public:
// to be called from the UI thread
void emuRun();
void emuPause();
void emuUnpause();
void emuTogglePause();
void emuPause(bool broadcast = true);
void emuUnpause(bool broadcast = true);
void emuTogglePause(bool broadcast = true);
void emuStop(bool external);
void emuExit();
void emuFrameStep();

View File

@ -1349,7 +1349,7 @@ void MainWindow::updateRecentFilesMenu()
Config::Save();
loadRecentFilesMenu(false);
updateConfigInfoAll(Config_RecentFiles, emuInstance->getInstanceID());
emuInstance->broadcastCommand(InstCmd_UpdateRecentFiles);
}
void MainWindow::onClickRecentFile()

View File

@ -168,14 +168,14 @@ int numEmuInstances()
}
void updateConfigInfoAll(int kind, int sourceinst)
void broadcastInstanceCommand(int cmd, int sourceinst)
{
for (int i = 0; i < kMaxEmuInstances; i++)
{
if (i == sourceinst) continue;
if (!emuInstances[i]) continue;
emuInstances[i]->updateConfigInfo(kind);
emuInstances[i]->handleCommand(cmd);
}
}

View File

@ -33,7 +33,10 @@
enum
{
Config_RecentFiles,
InstCmd_Pause,
InstCmd_Unpause,
InstCmd_UpdateRecentFiles,
};
class MelonApplication : public QApplication
@ -55,7 +58,7 @@ void deleteEmuInstance(int id);
void deleteAllEmuInstances(int first = 0);
int numEmuInstances();
void updateConfigInfoAll(int kind, int sourceinst);
void broadcastInstanceCommand(int cmd, int sourceinst);
void setMPInterface(melonDS::MPInterfaceType type);