From aad52837869641f0252c52f7b7155e3b8cf30f19 Mon Sep 17 00:00:00 2001 From: Eladash Date: Tue, 2 Mar 2021 16:56:23 +0200 Subject: [PATCH] Fix Emulator::IsPaused() --- rpcs3/Emu/GDB.cpp | 2 +- rpcs3/Emu/System.cpp | 32 +++++--------------------------- rpcs3/Emu/System.h | 4 ++-- rpcs3/rpcs3qt/gs_frame.cpp | 8 ++++++-- rpcs3/rpcs3qt/main_window.cpp | 31 ++++++++++++++++++------------- 5 files changed, 32 insertions(+), 45 deletions(-) diff --git a/rpcs3/Emu/GDB.cpp b/rpcs3/Emu/GDB.cpp index 7f172dd9ed..e4647c329b 100644 --- a/rpcs3/Emu/GDB.cpp +++ b/rpcs3/Emu/GDB.cpp @@ -741,7 +741,7 @@ bool gdb_thread::cmd_vcont(gdb_cmd& cmd) } ppu->state -= cpu_flag::dbg_pause; //special case if app didn't start yet (only loaded) - if (!Emu.IsPaused() && !Emu.IsRunning()) { + if (Emu.IsReady()) { Emu.Run(true); } if (Emu.IsPaused()) { diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 989d19c3f0..b828253c5a 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1651,7 +1651,9 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool return game_boot_result::invalid_file_or_folder; } - if ((m_force_boot || g_cfg.misc.autostart) && IsReady()) + ensure(IsReady()); + + if (m_force_boot || g_cfg.misc.autostart) { if (ppu_exec == elf_error::ok) { @@ -1684,38 +1686,14 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool m_force_boot = false; } - else if (IsPaused()) - { - m_state = system_state::ready; - GetCallbacks().on_ready(); - } + return game_boot_result::no_errors; } } void Emulator::Run(bool start_playtime) { - if (!IsReady()) - { - // Reload with prior configuration. - Load(m_title_id, false, m_force_global_config); - - if (!IsReady()) - { - return; - } - } - - if (IsRunning()) - { - Stop(); - } - - if (IsPaused()) - { - Resume(); - return; - } + ensure(IsReady()); GetCallbacks().on_run(start_playtime); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 7215d54a30..a5a4ebfef1 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -16,8 +16,8 @@ enum class video_renderer; enum class system_state : u32 { running, - paused, stopped, + paused, ready, }; @@ -238,7 +238,7 @@ public: void CleanUp(); bool IsRunning() const { return m_state == system_state::running; } - bool IsPaused() const { return m_state == system_state::paused; } + bool IsPaused() const { return m_state >= system_state::paused; } // ready is also considered paused by this function bool IsStopped() const { return m_state == system_state::stopped; } bool IsReady() const { return m_state == system_state::ready; } auto GetStatus() const { return m_state.load(); } diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index a5e71d75d8..cf4bc6bc5c 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -199,16 +199,20 @@ void gs_frame::keyPressEvent(QKeyEvent *keyEvent) case Qt::Key_E: if (keyEvent->modifiers() == Qt::ControlModifier && !m_disable_kb_hotkeys) { - if (Emu.IsReady()) + switch (Emu.GetStatus()) + { + case system_state::ready: { Emu.Run(true); return; } - else if (Emu.IsPaused()) + case system_state::paused: { Emu.Resume(); return; } + default: break; + } } break; case Qt::Key_C: diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 05c082d20b..5c76ce7407 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -296,19 +296,12 @@ void main_window::ResizeIcons(int index) void main_window::OnPlayOrPause() { - if (Emu.IsReady()) + switch (Emu.GetStatus()) { - Emu.Run(true); - } - else if (Emu.IsPaused()) - { - Emu.Resume(); - } - else if (Emu.IsRunning()) - { - Emu.Pause(); - } - else if (Emu.IsStopped()) + case system_state::ready: Emu.Run(true); return; + case system_state::paused: Emu.Resume(); return; + case system_state::running: Emu.Pause(); return; + case system_state::stopped: { if (m_selected_game) { @@ -326,6 +319,10 @@ void main_window::OnPlayOrPause() { BootRecentAction(m_recent_game_acts.first()); } + + return; + } + default: fmt::throw_exception("Unreachable"); } } @@ -2640,7 +2637,15 @@ void main_window::keyPressEvent(QKeyEvent *keyEvent) { switch (keyEvent->key()) { - case Qt::Key_E: if (Emu.IsPaused()) Emu.Resume(); else if (Emu.IsReady()) Emu.Run(true); return; + case Qt::Key_E: + { + switch (Emu.GetStatus()) + { + case system_state::paused: Emu.Resume(); return; + case system_state::ready: Emu.Run(true); return; + default: return; + } + } case Qt::Key_P: if (Emu.IsRunning()) Emu.Pause(); return; case Qt::Key_S: if (!Emu.IsStopped()) Emu.Stop(); return; case Qt::Key_R: if (!Emu.GetBoot().empty()) Emu.Restart(); return;