From 3caebb31ae386cad2e32f787f5b5c739008d5447 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 31 Jan 2022 15:24:33 +1000 Subject: [PATCH] Qt: Add save state loading/loaded/saved events --- pcsx2-qt/EmuThread.cpp | 16 ++++++++++++++++ pcsx2-qt/EmuThread.h | 23 +++++++++++++++++++++++ pcsx2/VMManager.cpp | 4 ++++ pcsx2/VMManager.h | 10 ++++++++++ 4 files changed, 53 insertions(+) diff --git a/pcsx2-qt/EmuThread.cpp b/pcsx2-qt/EmuThread.cpp index 705553189e..c304ae2575 100644 --- a/pcsx2-qt/EmuThread.cpp +++ b/pcsx2-qt/EmuThread.cpp @@ -42,6 +42,7 @@ #include "EmuThread.h" #include "MainWindow.h" #include "QtHost.h" +#include "QtUtils.h" EmuThread* g_emu_thread = nullptr; WindowInfo g_gs_window_info; @@ -708,6 +709,21 @@ void Host::OnGameChanged(const std::string& disc_path, const std::string& game_s QString::fromStdString(game_name), game_crc); } +void Host::OnSaveStateLoading(const std::string_view& filename) +{ + emit g_emu_thread->onSaveStateLoading(QtUtils::StringViewToQString(filename)); +} + +void Host::OnSaveStateLoaded(const std::string_view& filename, bool was_successful) +{ + emit g_emu_thread->onSaveStateLoaded(QtUtils::StringViewToQString(filename), was_successful); +} + +void Host::OnSaveStateSaved(const std::string_view& filename) +{ + emit g_emu_thread->onSaveStateSaved(QtUtils::StringViewToQString(filename)); +} + void Host::PumpMessagesOnCPUThread() { g_emu_thread->getEventLoop()->processEvents(QEventLoop::AllEvents); diff --git a/pcsx2-qt/EmuThread.h b/pcsx2-qt/EmuThread.h index 04da15a10a..3ab714a662 100644 --- a/pcsx2-qt/EmuThread.h +++ b/pcsx2-qt/EmuThread.h @@ -80,17 +80,40 @@ Q_SIGNALS: DisplayWidget* onUpdateDisplayRequested(bool fullscreen, bool render_to_main); void onResizeDisplayRequested(qint32 width, qint32 height); void onDestroyDisplayRequested(); + + /// Called when the VM is starting initialization, but has not been completed yet. void onVMStarting(); + + /// Called when the VM is created. void onVMStarted(); + + /// Called when the VM is paused. void onVMPaused(); + + /// Called when the VM is resumed after being paused. void onVMResumed(); + + /// Called when the VM is shut down or destroyed. void onVMStopped(); + + /// Provided by the host; called when the running executable changes. void onGameChanged(const QString& path, const QString& serial, const QString& name, quint32 crc); + void onInputDevicesEnumerated(const QList>& devices); void onInputDeviceConnected(const QString& identifier, const QString& device_name); void onInputDeviceDisconnected(const QString& identifier); void onVibrationMotorsEnumerated(const QList& motors); + /// Called when a save state is loading, before the file is processed. + void onSaveStateLoading(const QString& path); + + /// Called after a save state is successfully loaded. If the save state was invalid, was_successful will be false. + void onSaveStateLoaded(const QString& path, bool was_successful); + + /// Called when a save state is being created/saved. The compression/write to disk is asynchronous, so this callback + /// just signifies that the save has started, not necessarily completed. + void onSaveStateSaved(const QString& path); + protected: void run(); diff --git a/pcsx2/VMManager.cpp b/pcsx2/VMManager.cpp index 9c9041bc14..399eaa4c15 100644 --- a/pcsx2/VMManager.cpp +++ b/pcsx2/VMManager.cpp @@ -784,13 +784,16 @@ bool VMManager::DoLoadState(const char* filename) { try { + Host::OnSaveStateLoading(filename); SaveState_UnzipFromDisk(wxString::FromUTF8(filename)); UpdateRunningGame(false); + Host::OnSaveStateLoaded(filename, true); return true; } catch (Exception::BaseException& e) { Host::ReportErrorAsync("Failed to load save state", static_cast(e.UserMsg().c_str())); + Host::OnSaveStateLoaded(filename, false); return false; } } @@ -803,6 +806,7 @@ bool VMManager::DoSaveState(const char* filename, s32 slot_for_message) SaveState_DownloadState(elist.get()); SaveState_ZipToDisk(elist.release(), SaveState_SaveScreenshot(), wxString::FromUTF8(filename), slot_for_message); Host::InvalidateSaveStateCache(); + Host::OnSaveStateSaved(filename); return true; } catch (Exception::BaseException& e) diff --git a/pcsx2/VMManager.h b/pcsx2/VMManager.h index 075cbec776..f373297810 100644 --- a/pcsx2/VMManager.h +++ b/pcsx2/VMManager.h @@ -173,6 +173,16 @@ namespace Host /// Called when the VM is resumed after being paused. void OnVMResumed(); + /// Called when a save state is loading, before the file is processed. + void OnSaveStateLoading(const std::string_view& filename); + + /// Called after a save state is successfully loaded. If the save state was invalid, was_successful will be false. + void OnSaveStateLoaded(const std::string_view& filename, bool was_successful); + + /// Called when a save state is being created/saved. The compression/write to disk is asynchronous, so this callback + /// just signifies that the save has started, not necessarily completed. + void OnSaveStateSaved(const std::string_view& filename); + /// Provided by the host; called when the running executable changes. void OnGameChanged(const std::string& disc_path, const std::string& game_serial, const std::string& game_name, u32 game_crc);