diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 1d32ae02..67ed42b9 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -274,6 +274,17 @@ consoleWin_t::consoleWin_t(QWidget *parent) aviDiskThread = new AviRecordDiskThread_t(this); scrHandlerConnected = false; + + // Register State Load Callback with Emulation Core + auto stateLoadCallback = []( bool loadSuccess ) + { + //printf("State Loaded: %i \n", loadSuccess ); + if (loadSuccess && (consoleWindow != nullptr) ) + { + emit consoleWindow->stateLoaded(); + } + }; + FCEUSS_SetLoadCallback( stateLoadCallback ); } consoleWin_t::~consoleWin_t(void) diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index a753341d..a89d742b 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -328,6 +328,7 @@ class consoleWin_t : public QMainWindow public: signals: void romLoaded(void); + void stateLoaded(void); void nesResetOccurred(void); public slots: diff --git a/src/drivers/Qt/NetPlay.cpp b/src/drivers/Qt/NetPlay.cpp index badce2da..de55d820 100644 --- a/src/drivers/Qt/NetPlay.cpp +++ b/src/drivers/Qt/NetPlay.cpp @@ -176,6 +176,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(stateLoaded(void)), this, SLOT(onStateLoad(void))); connect(consoleWindow, SIGNAL(nesResetOccurred(void)), this, SLOT(onNesReset(void))); FCEU_WRAPPER_LOCK(); @@ -454,9 +455,26 @@ void NetPlayServer::onRomLoad() FCEU_WRAPPER_UNLOCK(); } //----------------------------------------------------------------------------- +void NetPlayServer::onStateLoad() +{ + //printf("New State Loaded!\n"); + FCEU_WRAPPER_LOCK(); + + inputClear(); + inputFrameCount = static_cast(currFrameCounter); + + // New State has been loaded by server, signal clients to load and sync + for (auto& client : clientList ) + { + //sendRomLoadReq( client ); + sendStateSyncReq( client ); + } + FCEU_WRAPPER_UNLOCK(); +} +//----------------------------------------------------------------------------- void NetPlayServer::onNesReset() { - //printf("New ROM Loaded!\n"); + //printf("NES Reset Event!\n"); FCEU_WRAPPER_LOCK(); inputClear(); diff --git a/src/drivers/Qt/NetPlay.h b/src/drivers/Qt/NetPlay.h index 28af832a..08e4d85f 100644 --- a/src/drivers/Qt/NetPlay.h +++ b/src/drivers/Qt/NetPlay.h @@ -175,6 +175,7 @@ class NetPlayServer : public QTcpServer public slots: void newConnectionRdy(void); void onRomLoad(void); + void onStateLoad(void); void onNesReset(void); }; diff --git a/src/state.cpp b/src/state.cpp index b5905741..58c7dde2 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -63,6 +63,7 @@ using namespace std; static void (*SPreSave)(void) = NULL; static void (*SPostSave)(void) = NULL; +static void (*SPostLoad)(bool) = NULL; static int SaveStateStatus[10]; static int StateShow; @@ -640,8 +641,8 @@ int FCEUSS_LoadFP_old(EMUFILE* is, ENUM_SSLOADPARAMS params) } #ifdef __QT_DRIVER__ -// Qt Driver NetPlay state load handler. This is to control state loading, -// only hosts can load states and clients can request loads. +// Qt Driver NetPlay state load handler. This is to control state loading +// during netplay, only hosts can load states and clients can request loads. bool NetPlayStateLoadReq(EMUFILE* is); #endif @@ -730,9 +731,18 @@ bool FCEUSS_LoadFP(EMUFILE* is, ENUM_SSLOADPARAMS params) FCEUSS_LoadFP(&msBackupSavestate,SSLOADPARAM_NOBACKUP); } + // Post state load callback that is used to notify driver code that a new state load occurred. + if (SPostLoad != NULL) + { + SPostLoad(x); + } return x; } +void FCEUSS_SetLoadCallback( void (*cb)(bool) ) +{ + SPostLoad = cb; +} bool FCEUSS_Load(const char *fname, bool display_message) { diff --git a/src/state.h b/src/state.h index 705d7e86..caae5ed6 100644 --- a/src/state.h +++ b/src/state.h @@ -28,6 +28,7 @@ enum ENUM_SSLOADPARAMS void FCEUSS_Save(const char *, bool display_message=true); bool FCEUSS_Load(const char *, bool display_message=true); +void FCEUSS_SetLoadCallback( void (*cb)(bool) ); //zlib values: 0 (none) through 9 (max) or -1 (default) bool FCEUSS_SaveMS(EMUFILE* outstream, int compressionLevel);