mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-30 01:29:42 -06:00
Merge pull request #6024 from ligfx/coreonstatechangedcallback
Qt: use Settings::EmulationStateChanged
This commit is contained in:
@ -98,11 +98,12 @@ 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;
|
||||
static bool s_is_throttler_temp_disabled = false;
|
||||
static bool s_frame_step = false;
|
||||
|
||||
struct HostJob
|
||||
{
|
||||
@ -454,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 ----");
|
||||
}};
|
||||
@ -473,6 +476,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot)
|
||||
|
||||
// For a time this acts as the CPU thread...
|
||||
DeclareAsCPUThread();
|
||||
s_frame_step = false;
|
||||
|
||||
Movie::Init(*boot);
|
||||
Common::ScopeGuard movie_guard{Movie::Shutdown};
|
||||
@ -683,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()
|
||||
@ -698,6 +705,9 @@ State GetState()
|
||||
return State::Running;
|
||||
}
|
||||
|
||||
if (s_is_booting.IsSet())
|
||||
return State::Starting;
|
||||
|
||||
return State::Uninitialized;
|
||||
}
|
||||
|
||||
@ -859,6 +869,14 @@ void Callback_VideoCopiedToXFB(bool video_update)
|
||||
s_drawn_frame++;
|
||||
|
||||
Movie::FrameUpdate();
|
||||
|
||||
if (s_frame_step)
|
||||
{
|
||||
s_frame_step = false;
|
||||
CPU::Break();
|
||||
if (s_on_state_changed_callback)
|
||||
s_on_state_changed_callback(Core::GetState());
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTitle()
|
||||
@ -951,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)
|
||||
@ -1024,4 +1042,21 @@ void HostDispatchJobs()
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Host Thread
|
||||
void DoFrameStep()
|
||||
{
|
||||
if (GetState() == State::Paused)
|
||||
{
|
||||
// if already paused, frame advance for 1 frame
|
||||
s_frame_step = true;
|
||||
RequestRefreshInfo();
|
||||
SetState(State::Running);
|
||||
}
|
||||
else if (!s_frame_step)
|
||||
{
|
||||
// if not paused yet, pause immediately instead
|
||||
SetState(State::Paused);
|
||||
}
|
||||
}
|
||||
|
||||
} // Core
|
||||
|
@ -31,7 +31,8 @@ enum class State
|
||||
Uninitialized,
|
||||
Paused,
|
||||
Running,
|
||||
Stopping
|
||||
Stopping,
|
||||
Starting,
|
||||
};
|
||||
|
||||
bool Init(std::unique_ptr<BootParameters> boot);
|
||||
@ -84,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);
|
||||
@ -105,4 +106,6 @@ void QueueHostJob(std::function<void()> job, bool run_during_stop = false);
|
||||
// WM_USER_JOB_DISPATCH will be sent when something is added to the queue.
|
||||
void HostDispatchJobs();
|
||||
|
||||
void DoFrameStep();
|
||||
|
||||
} // namespace
|
||||
|
@ -63,7 +63,6 @@
|
||||
|
||||
namespace Movie
|
||||
{
|
||||
static bool s_bFrameStep = false;
|
||||
static bool s_bReadOnly = true;
|
||||
static u32 s_rerecords = 0;
|
||||
static PlayMode s_playMode = MODE_NONE;
|
||||
@ -192,11 +191,6 @@ void FrameUpdate()
|
||||
s_totalFrames = s_currentFrame;
|
||||
s_totalLagCount = s_currentLagCount;
|
||||
}
|
||||
if (s_bFrameStep)
|
||||
{
|
||||
s_bFrameStep = false;
|
||||
CPU::Break();
|
||||
}
|
||||
|
||||
s_bPolled = false;
|
||||
}
|
||||
@ -215,7 +209,6 @@ void Init(const BootParameters& boot)
|
||||
s_current_file_name.clear();
|
||||
|
||||
s_bPolled = false;
|
||||
s_bFrameStep = false;
|
||||
s_bSaveConfig = false;
|
||||
if (IsPlayingInput())
|
||||
{
|
||||
@ -274,23 +267,6 @@ void SetPolledDevice()
|
||||
s_bPolled = true;
|
||||
}
|
||||
|
||||
// NOTE: Host Thread
|
||||
void DoFrameStep()
|
||||
{
|
||||
if (Core::GetState() == Core::State::Paused)
|
||||
{
|
||||
// if already paused, frame advance for 1 frame
|
||||
s_bFrameStep = true;
|
||||
Core::RequestRefreshInfo();
|
||||
Core::SetState(Core::State::Running);
|
||||
}
|
||||
else if (!s_bFrameStep)
|
||||
{
|
||||
// if not paused yet, pause immediately instead
|
||||
Core::SetState(Core::State::Paused);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Host Thread
|
||||
void SetReadOnly(bool bEnabled)
|
||||
{
|
||||
|
@ -148,7 +148,6 @@ bool IsUsingBongo(int controller);
|
||||
void ChangePads(bool instantly = false);
|
||||
void ChangeWiiPads(bool instantly = false);
|
||||
|
||||
void DoFrameStep();
|
||||
void SetReadOnly(bool bEnabled);
|
||||
|
||||
bool BeginRecordingInput(int controllers);
|
||||
|
Reference in New Issue
Block a user