diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index c2d0acd8..2d8e029e 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -3601,6 +3601,9 @@ void consoleWin_t::consolePause(void) fceuWrapperTogglePause(); FCEU_WRAPPER_UNLOCK(); + bool isPaused = FCEUI_EmulationPaused() ? true : false; + emit pauseToggled( isPaused ); + mainMenuEmuPauseSet = false; return; } diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 5e092277..0b49aeb7 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -331,6 +331,7 @@ class consoleWin_t : public QMainWindow void romUnload(void); void stateLoaded(void); void nesResetOccurred(void); + void pauseToggled(bool state); public slots: void openDebugWindow(void); diff --git a/src/drivers/Qt/NetPlay.cpp b/src/drivers/Qt/NetPlay.cpp index 650f4623..03e41365 100644 --- a/src/drivers/Qt/NetPlay.cpp +++ b/src/drivers/Qt/NetPlay.cpp @@ -182,6 +182,7 @@ NetPlayServer::NetPlayServer(QObject *parent) connect(consoleWindow, SIGNAL(romUnload(void)), this, SLOT(onRomUnload(void))); connect(consoleWindow, SIGNAL(stateLoaded(void)), this, SLOT(onStateLoad(void))); connect(consoleWindow, SIGNAL(nesResetOccurred(void)), this, SLOT(onNesReset(void))); + connect(consoleWindow, SIGNAL(pauseToggled(bool)), this, SLOT(onPauseToggled(bool))); FCEU_WRAPPER_LOCK(); inputFrameCount = static_cast(currFrameCounter); @@ -373,7 +374,6 @@ int NetPlayServer::sendRomLoadReq( NetPlayClient *client ) Strlcpy( msg.fileName, GameInfo->filename, sizeof(msg.fileName) ); printf("Sending ROM Load Request: %s %lu\n", filepath, fileSize ); - FCEUI_SetEmulationPaused(EMULATIONPAUSED_PAUSED); sendMsg( client, &msg, sizeof(netPlayLoadRomReq), [&msg]{ msg.toNetworkByteOrder(); } ); @@ -431,7 +431,6 @@ int NetPlayServer::sendStateSyncReq( NetPlayClient *client ) } printf("Sending ROM Sync Request: %zu\n", em.size()); - FCEUI_SetEmulationPaused(EMULATIONPAUSED_PAUSED); sendMsg( client, &resp, sizeof(netPlayLoadStateResp), [&resp]{ resp.toNetworkByteOrder(); } ); sendMsg( client, em.buf(), em.size() ); @@ -441,6 +440,44 @@ int NetPlayServer::sendStateSyncReq( NetPlayClient *client ) return 0; } //----------------------------------------------------------------------------- +int NetPlayServer::sendPause( NetPlayClient *client ) +{ + netPlayMsgHdr msg(NETPLAY_CLIENT_PAUSE_REQ); + + sendMsg( client, &msg, sizeof(netPlayMsgHdr), [&msg]{ msg.toNetworkByteOrder(); } ); + + return 0; +} +//----------------------------------------------------------------------------- +int NetPlayServer::sendUnpause( NetPlayClient *client ) +{ + netPlayMsgHdr msg(NETPLAY_CLIENT_UNPAUSE_REQ); + + sendMsg( client, &msg, sizeof(netPlayMsgHdr), [&msg]{ msg.toNetworkByteOrder(); } ); + + return 0; +} +//----------------------------------------------------------------------------- +int NetPlayServer::sendPauseAll() +{ + int ret = 0; + for (auto& client : clientList ) + { + ret |= sendPause( client ); + } + return ret; +} +//----------------------------------------------------------------------------- +int NetPlayServer::sendUnpauseAll() +{ + int ret = 0; + for (auto& client : clientList ) + { + ret |= sendUnpause( client ); + } + return ret; +} +//----------------------------------------------------------------------------- void NetPlayServer::setRole(int _role) { role = _role; @@ -507,6 +544,8 @@ void NetPlayServer::onRomLoad() inputClear(); inputFrameCount = static_cast(currFrameCounter); + sendPauseAll(); + // New ROM has been loaded by server, signal clients to load and sync for (auto& client : clientList ) { @@ -524,6 +563,8 @@ void NetPlayServer::onRomUnload() unloadMsg.toNetworkByteOrder(); + sendPauseAll(); + // New ROM has been loaded by server, signal clients to load and sync for (auto& client : clientList ) { @@ -542,6 +583,8 @@ void NetPlayServer::onStateLoad() inputClear(); inputFrameCount = static_cast(currFrameCounter); + sendPauseAll(); + // New State has been loaded by server, signal clients to load and sync for (auto& client : clientList ) { @@ -562,6 +605,8 @@ void NetPlayServer::onNesReset() inputClear(); inputFrameCount = static_cast(currFrameCounter); + sendPauseAll(); + // NES Reset has occurred on server, signal clients sync for (auto& client : clientList ) { @@ -571,6 +616,18 @@ void NetPlayServer::onNesReset() FCEU_WRAPPER_UNLOCK(); } //----------------------------------------------------------------------------- +void NetPlayServer::onPauseToggled( bool isPaused ) +{ + if (isPaused) + { + sendPauseAll(); + } + else + { + sendUnpauseAll(); + } +} +//----------------------------------------------------------------------------- void NetPlayServer::resyncClient( NetPlayClient *client ) { FCEU_WRAPPER_LOCK(); @@ -667,6 +724,14 @@ void NetPlayServer::serverProcessMessage( NetPlayClient *client, void *msgBuf, s FCEU_WRAPPER_LOCK(); resyncClient(client); client->state = 1; + if (FCEUI_EmulationPaused()) + { + sendPauseAll(); + } + else + { + sendUnpauseAll(); + } FCEU_WRAPPER_UNLOCK(); FCEU_DispMessage("%s Joined",0, client->userName.toLocal8Bit().constData()); } @@ -787,6 +852,13 @@ void NetPlayServer::serverProcessMessage( NetPlayClient *client, void *msgBuf, s } } break; + case NETPLAY_SYNC_STATE_REQ: + { + FCEU_WRAPPER_LOCK(); + resyncClient( client ); + FCEU_WRAPPER_UNLOCK(); + } + break; case NETPLAY_SYNC_STATE_RESP: { netPlayLoadStateResp* msg = static_cast(msgBuf); @@ -817,13 +889,6 @@ void NetPlayServer::serverProcessMessage( NetPlayClient *client, void *msgBuf, s } } break; - case NETPLAY_CLIENT_SYNC_REQ: - { - FCEU_WRAPPER_LOCK(); - resyncClient( client ); - FCEU_WRAPPER_UNLOCK(); - } - break; default: printf("Unknown Msg: %08X\n", msgId); break; @@ -878,6 +943,7 @@ void NetPlayServer::processClientRomLoadRequests(void) FCEUI_SetEmulationPaused(EMULATIONPAUSED_PAUSED); FCEU_WRAPPER_UNLOCK(); + sendPauseAll(); resyncAllClients(); } else @@ -1394,7 +1460,6 @@ int NetPlayClient::requestRomLoad( const char *romPath ) Strlcpy( msg.fileName, fi.fileName().toLocal8Bit().constData(), sizeof(msg.fileName) ); printf("Sending ROM Load Request: %s %lu\n", romPath, fileSize ); - FCEUI_SetEmulationPaused(EMULATIONPAUSED_PAUSED); msg.toNetworkByteOrder(); sock->write( reinterpret_cast(&msg), sizeof(netPlayLoadRomReq) ); @@ -1467,7 +1532,7 @@ int NetPlayClient::requestStateLoad(EMUFILE *is) //----------------------------------------------------------------------------- int NetPlayClient::requestSync(void) { - netPlayMsgHdr hdr(NETPLAY_CLIENT_SYNC_REQ); + netPlayMsgHdr hdr(NETPLAY_SYNC_STATE_REQ); hdr.toNetworkByteOrder(); sock->write( reinterpret_cast(&hdr), sizeof(netPlayMsgHdr)); @@ -1717,7 +1782,6 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize ) FCEU_WRAPPER_LOCK(); LoadGame( filepath.toLocal8Bit().constData(), true, true ); - FCEUI_SetEmulationPaused(EMULATIONPAUSED_PAUSED); opsCrc32 = 0; netPlayFrameData.reset(); @@ -1817,6 +1881,22 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize ) sock->write( (const char*)&pong, sizeof(netPlayPingResp) ); } break; + case NETPLAY_CLIENT_PAUSE_REQ: + { + if (!FCEUI_EmulationPaused()) + { + FCEUI_ToggleEmulationPause(); + } + } + break; + case NETPLAY_CLIENT_UNPAUSE_REQ: + { + if (FCEUI_EmulationPaused()) + { + FCEUI_ToggleEmulationPause(); + } + } + break; default: printf("Unknown Msg: %08X\n", msgId); break; @@ -2480,6 +2560,7 @@ void NetPlayHostStatusDialog::resyncAllPlayers(void) if (server != nullptr) { + server->sendPauseAll(); server->resyncAllClients(); } } diff --git a/src/drivers/Qt/NetPlay.h b/src/drivers/Qt/NetPlay.h index d41f6e35..36117724 100644 --- a/src/drivers/Qt/NetPlay.h +++ b/src/drivers/Qt/NetPlay.h @@ -131,6 +131,10 @@ class NetPlayServer : public QTcpServer int sendMsg( NetPlayClient *client, void *msg, size_t msgSize, std::function netByteOrderConvertFunc = []{}); int sendRomLoadReq( NetPlayClient *client ); int sendStateSyncReq( NetPlayClient *client ); + int sendPause( NetPlayClient *client ); + int sendUnpause( NetPlayClient *client ); + int sendPauseAll(void); + int sendUnpauseAll(void); void setRole(int _role); int getRole(void){ return role; } bool claimRole(NetPlayClient* client, int _role); @@ -181,6 +185,7 @@ class NetPlayServer : public QTcpServer void onRomUnload(void); void onStateLoad(void); void onNesReset(void); + void onPauseToggled(bool); void processClientRomLoadRequests(void); void processClientStateLoadRequests(void); }; diff --git a/src/drivers/Qt/NetPlayMsgDef.h b/src/drivers/Qt/NetPlayMsgDef.h index 27b6bde0..6a5fd303 100644 --- a/src/drivers/Qt/NetPlayMsgDef.h +++ b/src/drivers/Qt/NetPlayMsgDef.h @@ -23,7 +23,8 @@ enum netPlayMsgType NETPLAY_SYNC_STATE_RESP, NETPLAY_RUN_FRAME_REQ = 30, NETPLAY_CLIENT_STATE = 40, - NETPLAY_CLIENT_SYNC_REQ, + NETPLAY_CLIENT_PAUSE_REQ, + NETPLAY_CLIENT_UNPAUSE_REQ, NETPLAY_INFO_MSG = 50, NETPLAY_ERROR_MSG, NETPLAY_CHAT_MSG,