From 8e805dcbf43505aaf5b9af06f6f23159f3c083e4 Mon Sep 17 00:00:00 2001 From: Michael M Date: Mon, 4 Sep 2017 10:57:42 -0700 Subject: [PATCH] Core: SetOnStoppedCallback -> SetOnStateChangedCallback --- Source/Core/Core/Core.cpp | 17 ++++++++++++----- Source/Core/Core/Core.h | 4 ++-- Source/Core/DolphinNoGUI/MainNoGUI.cpp | 5 ++++- Source/Core/DolphinQt2/MainWindow.cpp | 5 ++++- Source/Core/DolphinWX/Frame.cpp | 5 +++-- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index d3d34e1ee4..d70d9ff712 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -98,7 +98,7 @@ static Common::Flag s_is_booting; static void* s_window_handle = nullptr; static std::string s_state_filename; static std::thread s_emu_thread; -static StoppedCallbackFunc s_on_stopped_callback; +static StateChangedCallbackFunc s_on_state_changed_callback; static std::thread s_cpu_thread; static bool s_request_refresh_info = false; @@ -455,14 +455,16 @@ static void EmuThread(std::unique_ptr boot) { const SConfig& core_parameter = SConfig::GetInstance(); s_is_booting.Set(); + if (s_on_state_changed_callback) + s_on_state_changed_callback(State::Starting); Common::ScopeGuard flag_guard{[] { s_is_booting.Clear(); s_is_started = false; s_is_stopping = false; s_wants_determinism = false; - if (s_on_stopped_callback) - s_on_stopped_callback(); + if (s_on_state_changed_callback) + s_on_state_changed_callback(State::Uninitialized); INFO_LOG(CONSOLE, "Stop\t\t---- Shutdown complete ----"); }}; @@ -685,6 +687,9 @@ void SetState(State state) PanicAlert("Invalid state"); break; } + + if (s_on_state_changed_callback) + s_on_state_changed_callback(GetState()); } State GetState() @@ -869,6 +874,8 @@ void Callback_VideoCopiedToXFB(bool video_update) { s_frame_step = false; CPU::Break(); + if (s_on_state_changed_callback) + s_on_state_changed_callback(Core::GetState()); } } @@ -962,9 +969,9 @@ void Shutdown() HostDispatchJobs(); } -void SetOnStoppedCallback(StoppedCallbackFunc callback) +void SetOnStateChangedCallback(StateChangedCallbackFunc callback) { - s_on_stopped_callback = std::move(callback); + s_on_state_changed_callback = std::move(callback); } void UpdateWantDeterminism(bool initial) diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h index a796f0addf..4ed2570081 100644 --- a/Source/Core/Core/Core.h +++ b/Source/Core/Core/Core.h @@ -85,8 +85,8 @@ void UpdateTitle(); void RunAsCPUThread(std::function function); // for calling back into UI code without introducing a dependency on it in core -using StoppedCallbackFunc = std::function; -void SetOnStoppedCallback(StoppedCallbackFunc callback); +using StateChangedCallbackFunc = std::function; +void SetOnStateChangedCallback(StateChangedCallbackFunc callback); // Run on the Host thread when the factors change. [NOT THREADSAFE] void UpdateWantDeterminism(bool initial = false); diff --git a/Source/Core/DolphinNoGUI/MainNoGUI.cpp b/Source/Core/DolphinNoGUI/MainNoGUI.cpp index 37860057aa..ecd2d3ba88 100644 --- a/Source/Core/DolphinNoGUI/MainNoGUI.cpp +++ b/Source/Core/DolphinNoGUI/MainNoGUI.cpp @@ -392,7 +392,10 @@ int main(int argc, char* argv[]) UICommon::SetUserDirectory(user_directory); UICommon::Init(); - Core::SetOnStoppedCallback([]() { s_running.Clear(); }); + Core::SetOnStateChangedCallback([](Core::State state) { + if (state == Core::State::Uninitialized) + s_running.Clear(); + }); platform->Init(); // Shut down cleanly on SIGINT and SIGTERM diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index f4dee4f7e0..5f52b407bb 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -121,7 +121,10 @@ void MainWindow::ShutdownControllers() void MainWindow::InitCoreCallbacks() { - Core::SetOnStoppedCallback([this] { emit EmulationStopped(); }); + Core::SetOnStateChangedCallback([=](Core::State state) { + if (state == Core::State::Uninitialized) + emit EmulationStopped(); + }); installEventFilter(this); m_render_widget->installEventFilter(this); } diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 7800907a37..7bc9daab15 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -530,8 +530,9 @@ void CFrame::InitializeCoreCallbacks() }); // Warning: this gets called from the EmuThread - Core::SetOnStoppedCallback([this] { - AddPendingEvent(wxCommandEvent{wxEVT_HOST_COMMAND, IDM_STOPPED}); + Core::SetOnStateChangedCallback([this](Core::State state) { + if (state == Core::State::Uninitialized) + AddPendingEvent(wxCommandEvent{wxEVT_HOST_COMMAND, IDM_STOPPED}); }); }