Emu: always use Emu.Quit() to quit RPCS3

This creates a single possible point of failure for calling quit()
This commit is contained in:
Megamouse 2020-07-03 17:11:28 +02:00
parent 332f9cae77
commit d91551c277
5 changed files with 37 additions and 24 deletions

View file

@ -1752,19 +1752,6 @@ void Emulator::Stop(bool restart)
vm::close(); vm::close();
if (do_exit)
{
GetCallbacks().exit(true);
}
else
{
if (full_stop)
{
GetCallbacks().exit(false);
}
Init();
}
#ifdef LLVM_AVAILABLE #ifdef LLVM_AVAILABLE
extern void jit_finalize(); extern void jit_finalize();
jit_finalize(); jit_finalize();
@ -1793,6 +1780,24 @@ void Emulator::Stop(bool restart)
{ {
enable_display_sleep(); enable_display_sleep();
} }
if (do_exit || full_stop)
{
if (Quit(do_exit))
{
return;
}
}
Init();
}
bool Emulator::Quit(bool force_quit) const
{
Emu.SetForceBoot(false);
Emu.Stop();
return GetCallbacks().exit(force_quit);
} }
std::string Emulator::GetFormattedTitle(double fps) const std::string Emulator::GetFormattedTitle(double fps) const

View file

@ -37,7 +37,7 @@ struct EmuCallbacks
std::function<void()> on_resume; std::function<void()> on_resume;
std::function<void()> on_stop; std::function<void()> on_stop;
std::function<void()> on_ready; std::function<void()> on_ready;
std::function<void(bool)> exit; // (force_quit) close RPCS3 std::function<bool(bool)> exit; // (force_quit) close RPCS3
std::function<void(s32, s32)> handle_taskbar_progress; // (type, value) type: 0 for reset, 1 for increment, 2 for set_limit std::function<void(s32, s32)> handle_taskbar_progress; // (type, value) type: 0 for reset, 1 for increment, 2 for set_limit
std::function<void()> init_kb_handler; std::function<void()> init_kb_handler;
std::function<void()> init_mouse_handler; std::function<void()> init_mouse_handler;
@ -202,6 +202,7 @@ public:
void Resume(); void Resume();
void Stop(bool restart = false); void Stop(bool restart = false);
void Restart() { Stop(true); } void Restart() { Stop(true); }
bool Quit(bool force_quit) const;
bool IsRunning() const { return m_state == system_state::running; } 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; }

View file

@ -39,12 +39,15 @@ void headless_application::InitializeCallbacks()
{ {
EmuCallbacks callbacks = CreateCallbacks(); EmuCallbacks callbacks = CreateCallbacks();
callbacks.exit = [this](bool force_quit) callbacks.exit = [this](bool force_quit) -> bool
{ {
if (force_quit) if (force_quit)
{ {
quit(); quit();
return true;
} }
return false;
}; };
callbacks.call_after = [=, this](std::function<void()> func) callbacks.call_after = [=, this](std::function<void()> func)
{ {

View file

@ -267,13 +267,21 @@ void gui_application::InitializeCallbacks()
{ {
EmuCallbacks callbacks = CreateCallbacks(); EmuCallbacks callbacks = CreateCallbacks();
callbacks.exit = [this](bool force_quit) callbacks.exit = [this](bool force_quit) -> bool
{ {
// Close rpcs3 if closed in no-gui mode // Close rpcs3 if closed in no-gui mode
if (force_quit || !m_main_window) if (force_quit || !m_main_window)
{ {
quit(); if (m_main_window)
{
// Close main window in order to save its window state
m_main_window->close();
} }
quit();
return true;
}
return false;
}; };
callbacks.call_after = [this](std::function<void()> func) callbacks.call_after = [this](std::function<void()> func)
{ {

View file

@ -72,6 +72,7 @@ main_window::main_window(std::shared_ptr<gui_settings> gui_settings, std::shared
main_window::~main_window() main_window::~main_window()
{ {
SaveWindowState();
delete ui; delete ui;
} }
@ -2140,7 +2141,7 @@ void main_window::mouseDoubleClickEvent(QMouseEvent *event)
} }
} }
/** Override the Qt close event to have the emulator stop and the application die. May add a warning dialog in future. /** Override the Qt close event to have the emulator stop and the application die.
*/ */
void main_window::closeEvent(QCloseEvent* closeEvent) void main_window::closeEvent(QCloseEvent* closeEvent)
{ {
@ -2150,13 +2151,8 @@ void main_window::closeEvent(QCloseEvent* closeEvent)
return; return;
} }
// Cleanly stop the emulator. // Cleanly stop and quit the emulator.
Emu.Stop(); Emu.Quit(true);
SaveWindowState();
// It's possible to have other windows open, like games. So, force the application to die.
QApplication::quit();
} }
/** /**