diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index b5bd563d..dc21571d 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -323,6 +323,11 @@ class consoleWin_t : public QMainWindow QString findHelpFile(void); + public: + signals: + void romLoaded(void); + void nesResetOccurred(void); + public slots: void openDebugWindow(void); void openHexEditor(void); diff --git a/src/drivers/Qt/NetPlay.cpp b/src/drivers/Qt/NetPlay.cpp index d8988041..c1f14897 100644 --- a/src/drivers/Qt/NetPlay.cpp +++ b/src/drivers/Qt/NetPlay.cpp @@ -144,6 +144,9 @@ NetPlayServer::NetPlayServer(QObject *parent) instance = this; 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() ); opsCrc32 = 0; + inputClear(); return 0; } @@ -366,6 +370,29 @@ bool NetPlayServer::claimRole(NetPlayClient* client, int _role) 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 ) { NetPlayServer *server = NetPlayServer::GetInstance(); @@ -587,7 +614,8 @@ void NetPlayServer::update(void) shouldRunFrame = (clientMinFrame != 0xFFFFFFFF) && (clientMinFrame >= lagFrame ) && (clientMaxFrame < leadFrame) && - (currFrame > lastFrame) && (numClientsPaused == 0); + ( (currFrame > lastFrame) || (lastFrame == 0) ) && + (numClientsPaused == 0); //printf("Client Frame: Min:%u Max:%u\n", clientMinFrame, clientMaxFrame); @@ -613,10 +641,8 @@ void NetPlayServer::update(void) runFrameReq.toNetworkByteOrder(); - for (auto it = clientList.begin(); it != clientList.end(); it++) + for (auto& client : clientList ) { - NetPlayClient *client = *it; - if (client->state > 0) { sendMsg( client, &runFrameReq, sizeof(runFrameReq) ); @@ -635,10 +661,8 @@ void NetPlayServer::update(void) ping.hostTimeStamp = ts.toMilliSeconds(); ping.toNetworkByteOrder(); - for (auto it = clientList.begin(); it != clientList.end(); it++) + for (auto& client : clientList ) { - NetPlayClient *client = *it; - if (client->state > 0) { sendMsg( client, &ping, sizeof(ping) ); @@ -649,10 +673,8 @@ void NetPlayServer::update(void) bool shouldFlushOutput = true; if (shouldFlushOutput) { - for (auto it = clientList.begin(); it != clientList.end(); it++) + for (auto& client : clientList ) { - NetPlayClient *client = *it; - client->flushData(); } } @@ -1051,6 +1073,7 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize ) opsCrc32 = 0; netPlayFrameData.reset(); + inputClear(); } break; case NETPLAY_RUN_FRAME_REQ: diff --git a/src/drivers/Qt/NetPlay.h b/src/drivers/Qt/NetPlay.h index 2abc3a94..b4cbf8cb 100644 --- a/src/drivers/Qt/NetPlay.h +++ b/src/drivers/Qt/NetPlay.h @@ -113,6 +113,12 @@ class NetPlayServer : public QTcpServer return frame; } + void inputClear() + { + FCEU::autoScopedLock alock(inputMtx); + input.clear(); + } + int sendMsg( NetPlayClient *client, void *msg, size_t msgSize); int sendRomLoadReq( NetPlayClient *client ); int sendStateSyncReq( NetPlayClient *client ); @@ -143,6 +149,8 @@ class NetPlayServer : public QTcpServer public slots: void newConnectionRdy(void); + void onRomLoad(void); + void onNesReset(void); }; class NetPlayClient : public QObject @@ -209,6 +217,12 @@ class NetPlayClient : public QObject return frame; } + void inputClear() + { + FCEU::autoScopedLock alock(inputMtx); + input.clear(); + } + bool isAuthenticated(); bool isPlayerRole(); bool shouldDestroy(){ return needsDestroy; } diff --git a/src/drivers/Qt/fceuWrapper.cpp b/src/drivers/Qt/fceuWrapper.cpp index 84730e3c..eb7efc47 100644 --- a/src/drivers/Qt/fceuWrapper.cpp +++ b/src/drivers/Qt/fceuWrapper.cpp @@ -467,7 +467,11 @@ int LoadGame(const char *path, bool silent) //} isloaded = 1; - //FCEUD_NetworkConnect(); + // Signal to listeners that a new ROM was loaded + if ( consoleWindow ) + { + emit consoleWindow->romLoaded(); + } return 1; } @@ -560,6 +564,11 @@ int fceuWrapperSoftReset(void) if ( isloaded ) { ResetNES(); + + if (consoleWindow != nullptr) + { + emit consoleWindow->nesResetOccurred(); + } } return 0; }