Added ROM loaded and NES reset signals to allow for net play to reconfigure accordingly during those events.

This commit is contained in:
harry 2024-02-26 07:02:59 -05:00
parent 145fc1614f
commit d212b894a7
4 changed files with 62 additions and 11 deletions

View File

@ -323,6 +323,11 @@ class consoleWin_t : public QMainWindow
QString findHelpFile(void); QString findHelpFile(void);
public:
signals:
void romLoaded(void);
void nesResetOccurred(void);
public slots: public slots:
void openDebugWindow(void); void openDebugWindow(void);
void openHexEditor(void); void openHexEditor(void);

View File

@ -144,6 +144,9 @@ NetPlayServer::NetPlayServer(QObject *parent)
instance = this; instance = this;
connect(this, SIGNAL(newConnection(void)), this, SLOT(newConnectionRdy(void))); connect(this, SIGNAL(newConnection(void)), this, SLOT(newConnectionRdy(void)));
connect(consoleWindow, SIGNAL(romLoaded(void)), this, SLOT(onRomLoad(void)));
connect(consoleWindow, SIGNAL(nesResetOccurred(void)), this, SLOT(onNesReset(void)));
} }
@ -329,6 +332,7 @@ int NetPlayServer::sendStateSyncReq( NetPlayClient *client )
sendMsg( client, em.buf(), em.size() ); sendMsg( client, em.buf(), em.size() );
opsCrc32 = 0; opsCrc32 = 0;
inputClear();
return 0; return 0;
} }
@ -366,6 +370,29 @@ bool NetPlayServer::claimRole(NetPlayClient* client, int _role)
return success; return success;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void NetPlayServer::onRomLoad()
{
//printf("New ROM Loaded!\n");
// New ROM has been loaded by server, signal clients to load and sync
for (auto& client : clientList )
{
sendRomLoadReq( client );
sendStateSyncReq( client );
}
}
//-----------------------------------------------------------------------------
void NetPlayServer::onNesReset()
{
//printf("New ROM Loaded!\n");
// NES Reset has occurred on server, signal clients sync
for (auto& client : clientList )
{
sendStateSyncReq( client );
}
}
//-----------------------------------------------------------------------------
static void serverMessageCallback( void *userData, void *msgBuf, size_t msgSize ) static void serverMessageCallback( void *userData, void *msgBuf, size_t msgSize )
{ {
NetPlayServer *server = NetPlayServer::GetInstance(); NetPlayServer *server = NetPlayServer::GetInstance();
@ -587,7 +614,8 @@ void NetPlayServer::update(void)
shouldRunFrame = (clientMinFrame != 0xFFFFFFFF) && shouldRunFrame = (clientMinFrame != 0xFFFFFFFF) &&
(clientMinFrame >= lagFrame ) && (clientMinFrame >= lagFrame ) &&
(clientMaxFrame < leadFrame) && (clientMaxFrame < leadFrame) &&
(currFrame > lastFrame) && (numClientsPaused == 0); ( (currFrame > lastFrame) || (lastFrame == 0) ) &&
(numClientsPaused == 0);
//printf("Client Frame: Min:%u Max:%u\n", clientMinFrame, clientMaxFrame); //printf("Client Frame: Min:%u Max:%u\n", clientMinFrame, clientMaxFrame);
@ -613,10 +641,8 @@ void NetPlayServer::update(void)
runFrameReq.toNetworkByteOrder(); runFrameReq.toNetworkByteOrder();
for (auto it = clientList.begin(); it != clientList.end(); it++) for (auto& client : clientList )
{ {
NetPlayClient *client = *it;
if (client->state > 0) if (client->state > 0)
{ {
sendMsg( client, &runFrameReq, sizeof(runFrameReq) ); sendMsg( client, &runFrameReq, sizeof(runFrameReq) );
@ -635,10 +661,8 @@ void NetPlayServer::update(void)
ping.hostTimeStamp = ts.toMilliSeconds(); ping.hostTimeStamp = ts.toMilliSeconds();
ping.toNetworkByteOrder(); ping.toNetworkByteOrder();
for (auto it = clientList.begin(); it != clientList.end(); it++) for (auto& client : clientList )
{ {
NetPlayClient *client = *it;
if (client->state > 0) if (client->state > 0)
{ {
sendMsg( client, &ping, sizeof(ping) ); sendMsg( client, &ping, sizeof(ping) );
@ -649,10 +673,8 @@ void NetPlayServer::update(void)
bool shouldFlushOutput = true; bool shouldFlushOutput = true;
if (shouldFlushOutput) if (shouldFlushOutput)
{ {
for (auto it = clientList.begin(); it != clientList.end(); it++) for (auto& client : clientList )
{ {
NetPlayClient *client = *it;
client->flushData(); client->flushData();
} }
} }
@ -1051,6 +1073,7 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize )
opsCrc32 = 0; opsCrc32 = 0;
netPlayFrameData.reset(); netPlayFrameData.reset();
inputClear();
} }
break; break;
case NETPLAY_RUN_FRAME_REQ: case NETPLAY_RUN_FRAME_REQ:

View File

@ -113,6 +113,12 @@ class NetPlayServer : public QTcpServer
return frame; return frame;
} }
void inputClear()
{
FCEU::autoScopedLock alock(inputMtx);
input.clear();
}
int sendMsg( NetPlayClient *client, void *msg, size_t msgSize); int sendMsg( NetPlayClient *client, void *msg, size_t msgSize);
int sendRomLoadReq( NetPlayClient *client ); int sendRomLoadReq( NetPlayClient *client );
int sendStateSyncReq( NetPlayClient *client ); int sendStateSyncReq( NetPlayClient *client );
@ -143,6 +149,8 @@ class NetPlayServer : public QTcpServer
public slots: public slots:
void newConnectionRdy(void); void newConnectionRdy(void);
void onRomLoad(void);
void onNesReset(void);
}; };
class NetPlayClient : public QObject class NetPlayClient : public QObject
@ -209,6 +217,12 @@ class NetPlayClient : public QObject
return frame; return frame;
} }
void inputClear()
{
FCEU::autoScopedLock alock(inputMtx);
input.clear();
}
bool isAuthenticated(); bool isAuthenticated();
bool isPlayerRole(); bool isPlayerRole();
bool shouldDestroy(){ return needsDestroy; } bool shouldDestroy(){ return needsDestroy; }

View File

@ -467,7 +467,11 @@ int LoadGame(const char *path, bool silent)
//} //}
isloaded = 1; isloaded = 1;
//FCEUD_NetworkConnect(); // Signal to listeners that a new ROM was loaded
if ( consoleWindow )
{
emit consoleWindow->romLoaded();
}
return 1; return 1;
} }
@ -560,6 +564,11 @@ int fceuWrapperSoftReset(void)
if ( isloaded ) if ( isloaded )
{ {
ResetNES(); ResetNES();
if (consoleWindow != nullptr)
{
emit consoleWindow->nesResetOccurred();
}
} }
return 0; return 0;
} }