From d22b8b1d3ade5c2a70f06b8d28d39ab92580f545 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 15 Jul 2022 22:11:39 +0300 Subject: [PATCH] Savestates: Do not restart after Ctrl+S for now --- rpcs3/Emu/System.cpp | 46 +++++++++++++------------------------- rpcs3/Emu/System.h | 4 ++-- rpcs3/rpcs3qt/gs_frame.cpp | 2 +- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index e4e7b50823..692a232563 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -2155,8 +2155,10 @@ void Emulator::GracefulShutdown(bool allow_autoexit, bool async_op, bool savesta extern bool try_lock_vdec_context_creation(); extern bool try_lock_spu_threads_in_a_state_compatible_with_savestates(); -void Emulator::Kill(bool allow_autoexit, bool savestate) +std::shared_ptr Emulator::Kill(bool allow_autoexit, bool savestate) { + std::shared_ptr to_ar; + if (savestate && !try_lock_spu_threads_in_a_state_compatible_with_savestates()) { sys_log.error("Failed to savestate: failed to lock SPU threads execution."); @@ -2169,7 +2171,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate) "\nYou need to close the game for to take effect." "\nIf you cannot close the game due to losing important progress your best chance is to skip the current cutscenes if any are played and retry."); - return; + return to_ar; } g_tls_log_prefix = []() @@ -2191,7 +2193,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate) m_config_path.clear(); m_config_mode = cfg_mode::custom; read_used_savestate_versions(); - return; + return to_ar; } sys_log.notice("Stopping emulator..."); @@ -2292,7 +2294,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate) if (savestate) { - m_ar = std::make_unique(); + to_ar = std::make_unique(); // Savestate thread named_thread emu_state_cap_thread("Emu State Capture Thread", [&]() @@ -2302,7 +2304,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate) return fmt::format("Emu State Capture Thread: '%s'", g_tls_serialize_name); }; - auto& ar = *m_ar; + auto& ar = *to_ar; read_used_savestate_versions(); // Reset version data USING_SERIALIZATION_VERSION(global_version); @@ -2387,7 +2389,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate) if (emu_state_cap_thread == thread_state::errored) { sys_log.error("Saving savestate failed due to fatal error!"); - m_ar.reset(); + to_ar.reset(); savestate = false; } } @@ -2443,7 +2445,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate) // Identifer -> version std::vector> used_serial = read_used_savestate_versions(); - auto& ar = *m_ar; + auto& ar = *to_ar; const usz pos = ar.seek_end(); std::memcpy(&ar.data[10], &pos, 8);// Set offset ar(used_serial); @@ -2470,6 +2472,7 @@ void Emulator::Kill(bool allow_autoexit, bool savestate) init_mem_containers = nullptr; m_config_path.clear(); m_config_mode = cfg_mode::custom; + m_ar.reset(); read_used_savestate_versions(); // Always Enable display sleep, not only if it was prevented. @@ -2477,14 +2480,13 @@ void Emulator::Kill(bool allow_autoexit, bool savestate) if (allow_autoexit) { - if (Quit(g_cfg.misc.autoexit.get())) - { - return; - } + Quit(g_cfg.misc.autoexit.get()); } + + return to_ar; } -game_boot_result Emulator::Restart(bool savestate) +game_boot_result Emulator::Restart() { if (m_state == system_state::stopped) { @@ -2493,34 +2495,16 @@ game_boot_result Emulator::Restart(bool savestate) auto save_args = std::make_tuple(argv, envp, data, disc, klic, hdd1, m_config_mode, m_config_mode); - GracefulShutdown(false, false, savestate); + GracefulShutdown(false, false); std::tie(argv, envp, data, disc, klic, hdd1, m_config_mode, m_config_mode) = std::move(save_args); - if (savestate) - { - if (!m_ar) - { - return game_boot_result::generic_error; - } - - if (g_cfg.savestate.suspend_emu) - { - m_ar.reset(); - return game_boot_result::no_errors; - } - } - // Reload with prior configs. if (const auto error = Load(m_title_id); error != game_boot_result::no_errors) { sys_log.error("Restart failed: %s", error); return error; } - else - { - m_ar.reset(); - } return game_boot_result::no_errors; } diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 8e4772aa58..f45b9dab62 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -301,8 +301,8 @@ public: bool Pause(bool freeze_emulation = false); void Resume(); void GracefulShutdown(bool allow_autoexit = true, bool async_op = false, bool savestate = false); - void Kill(bool allow_autoexit = true, bool savestate = false); - game_boot_result Restart(bool savestate = false); + std::shared_ptr Kill(bool allow_autoexit = true, bool savestate = false); + game_boot_result Restart(); bool Quit(bool force_quit); static void CleanUp(); diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index 58fcd31e18..0eb8c07a78 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -272,7 +272,7 @@ void gs_frame::keyPressEvent(QKeyEvent *keyEvent) case Qt::Key_S: if (keyEvent->modifiers() == Qt::ControlModifier && !m_disable_kb_hotkeys) { - Emu.Restart(true); + Emu.Kill(false, true); return; } break;