Core: SetOnStoppedCallback -> SetOnStateChangedCallback
This commit is contained in:
parent
22a9a08b24
commit
8e805dcbf4
|
@ -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<BootParameters> 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)
|
||||
|
|
|
@ -85,8 +85,8 @@ void UpdateTitle();
|
|||
void RunAsCPUThread(std::function<void()> function);
|
||||
|
||||
// for calling back into UI code without introducing a dependency on it in core
|
||||
using StoppedCallbackFunc = std::function<void()>;
|
||||
void SetOnStoppedCallback(StoppedCallbackFunc callback);
|
||||
using StateChangedCallbackFunc = std::function<void(Core::State)>;
|
||||
void SetOnStateChangedCallback(StateChangedCallbackFunc callback);
|
||||
|
||||
// Run on the Host thread when the factors change. [NOT THREADSAFE]
|
||||
void UpdateWantDeterminism(bool initial = false);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue