Emu: implement on_exit callback

This commit is contained in:
Megamouse 2020-12-18 12:40:25 +01:00
parent 1adec3d8e5
commit b655e4aa47
4 changed files with 18 additions and 8 deletions

View file

@ -1979,13 +1979,13 @@ bool Emulator::Quit(bool force_quit)
{ {
m_force_boot = false; m_force_boot = false;
// Deinitialize object manager to prevent any hanging objects at program exit // The callback is only used if we actually quit RPCS3
if (force_quit) const auto on_exit = []()
{ {
// Deinitialize object manager to prevent any hanging objects at program exit
*g_fxo = {}; *g_fxo = {};
} };
return GetCallbacks().try_to_quit(force_quit, on_exit);
return GetCallbacks().exit(force_quit);
} }
std::string Emulator::GetFormattedTitle(double fps) const std::string Emulator::GetFormattedTitle(double fps) const

View file

@ -42,7 +42,7 @@ struct EmuCallbacks
std::function<void()> on_stop; std::function<void()> on_stop;
std::function<void()> on_ready; std::function<void()> on_ready;
std::function<bool()> on_missing_fw; std::function<bool()> on_missing_fw;
std::function<bool(bool)> exit; // (force_quit) close RPCS3 std::function<bool(bool, std::function<void()>)> try_to_quit; // (force_quit, on_exit) Try to 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;

View file

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

View file

@ -283,11 +283,16 @@ void gui_application::InitializeCallbacks()
{ {
EmuCallbacks callbacks = CreateCallbacks(); EmuCallbacks callbacks = CreateCallbacks();
callbacks.exit = [this](bool force_quit) -> bool callbacks.try_to_quit = [this](bool force_quit, std::function<void()> on_exit) -> 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)
{ {
if (on_exit)
{
on_exit();
}
if (m_main_window) if (m_main_window)
{ {
// Close main window in order to save its window state // Close main window in order to save its window state