Savestates: Do not restart after Ctrl+S for now

This commit is contained in:
Eladash 2022-07-15 22:11:39 +03:00 committed by Ivan
parent 56619b20cf
commit d22b8b1d3a
3 changed files with 18 additions and 34 deletions

View File

@ -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<utils::serial> Emulator::Kill(bool allow_autoexit, bool savestate)
{
std::shared_ptr<utils::serial> 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<utils::serial>();
to_ar = std::make_unique<utils::serial>();
// 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<std::pair<u16, u16>> 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;
}

View File

@ -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<utils::serial> Kill(bool allow_autoexit = true, bool savestate = false);
game_boot_result Restart();
bool Quit(bool force_quit);
static void CleanUp();

View File

@ -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;