From 2fe563181e3519a395e17ab0b871a389c48b5e31 Mon Sep 17 00:00:00 2001 From: harry Date: Tue, 26 Mar 2024 20:58:21 -0400 Subject: [PATCH] Added ROM unload handling logic for netplay. --- src/drivers/Qt/ConsoleWindow.cpp | 12 ++++++++++++ src/drivers/Qt/NetPlay.cpp | 28 ++++++++++++++++++++++++++++ src/drivers/Qt/NetPlay.h | 2 ++ src/drivers/Qt/NetPlayMsgDef.h | 1 + 4 files changed, 43 insertions(+) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 67ed42b9..fe994e74 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -2643,6 +2643,18 @@ void consoleWin_t::loadRomRequestCB( QString s ) void consoleWin_t::closeROMCB(void) { + if (isNetPlayClient()) + { + QString msgBoxTxt = tr("Unloading ROM will cause a disconnect from the current netplay session.\n\nDo you want to continue with unloading and disconnection?"); + int ans = QMessageBox::question( this, tr("NetPlay Client ROM Unload Warning"), msgBoxTxt, QMessageBox::Yes | QMessageBox::No ); + + if (ans == QMessageBox::No) + { + return; + } + NetPlayCloseSession(); + } + FCEU_WRAPPER_LOCK(); CloseGame(); FCEU_WRAPPER_UNLOCK(); diff --git a/src/drivers/Qt/NetPlay.cpp b/src/drivers/Qt/NetPlay.cpp index 158e1fbe..0ee93dba 100644 --- a/src/drivers/Qt/NetPlay.cpp +++ b/src/drivers/Qt/NetPlay.cpp @@ -177,6 +177,7 @@ NetPlayServer::NetPlayServer(QObject *parent) connect(this, SIGNAL(newConnection(void)), this, SLOT(newConnectionRdy(void))); connect(consoleWindow, SIGNAL(romLoaded(void)), this, SLOT(onRomLoad(void))); + 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))); @@ -473,6 +474,21 @@ void NetPlayServer::onRomLoad() FCEU_WRAPPER_UNLOCK(); } //----------------------------------------------------------------------------- +void NetPlayServer::onRomUnload() +{ + netPlayMsgHdr unloadMsg(NETPLAY_UNLOAD_ROM_REQ); + + romCrc32 = 0; + + unloadMsg.toNetworkByteOrder(); + + // New ROM has been loaded by server, signal clients to load and sync + for (auto& client : clientList ) + { + sendMsg( client, &unloadMsg, sizeof(unloadMsg) ); + } +} +//----------------------------------------------------------------------------- void NetPlayServer::onStateLoad() { //printf("New State Loaded!\n"); @@ -1512,6 +1528,13 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize ) FCEU_WRAPPER_UNLOCK(); } break; + case NETPLAY_UNLOAD_ROM_REQ: + { + FCEU_WRAPPER_LOCK(); + CloseGame(); + FCEU_WRAPPER_UNLOCK(); + } + break; case NETPLAY_SYNC_STATE_RESP: { char *stateData = &static_cast(msgBuf)[ sizeof(netPlayMsgHdr) ]; @@ -2266,6 +2289,11 @@ bool isNetPlayHost(void) return (NetPlayServer::GetInstance() != nullptr); } //---------------------------------------------------------------------------- +bool isNetPlayClient(void) +{ + return (NetPlayClient::GetInstance() != nullptr); +} +//---------------------------------------------------------------------------- void NetPlayPeriodicUpdate(void) { NetPlayClient *client = NetPlayClient::GetInstance(); diff --git a/src/drivers/Qt/NetPlay.h b/src/drivers/Qt/NetPlay.h index e892a0c1..f3df2275 100644 --- a/src/drivers/Qt/NetPlay.h +++ b/src/drivers/Qt/NetPlay.h @@ -178,6 +178,7 @@ class NetPlayServer : public QTcpServer public slots: void newConnectionRdy(void); void onRomLoad(void); + void onRomUnload(void); void onStateLoad(void); void onNesReset(void); }; @@ -435,6 +436,7 @@ public slots: bool NetPlayActive(void); bool isNetPlayHost(void); +bool isNetPlayClient(void); void NetPlayPeriodicUpdate(void); bool NetPlaySkipWait(void); int NetPlayFrameWait(void); diff --git a/src/drivers/Qt/NetPlayMsgDef.h b/src/drivers/Qt/NetPlayMsgDef.h index f9982388..40d72fd1 100644 --- a/src/drivers/Qt/NetPlayMsgDef.h +++ b/src/drivers/Qt/NetPlayMsgDef.h @@ -18,6 +18,7 @@ enum netPlayMsgType NETPLAY_AUTH_REQ, NETPLAY_AUTH_RESP, NETPLAY_LOAD_ROM_REQ, + NETPLAY_UNLOAD_ROM_REQ, NETPLAY_SYNC_STATE_REQ, NETPLAY_SYNC_STATE_RESP, NETPLAY_RUN_FRAME_REQ,