Added ROM unload handling logic for netplay.

This commit is contained in:
harry 2024-03-26 20:58:21 -04:00
parent 25cab8195f
commit 2fe563181e
4 changed files with 43 additions and 0 deletions

View File

@ -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();

View File

@ -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<char*>(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();

View File

@ -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);

View File

@ -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,