Skip to content

Commit

Permalink
Core::SetState() allow state to change without sending a callback.
Browse files Browse the repository at this point in the history
Some state changes are meant to be near instantanoues, before switching to something else. By reporting ithe instant switch, the UI will flicker between states (pause/play button) and the debugger will unnecessarily update. Skipping the callback avoids these issues.
  • Loading branch information
TryTwo committed Nov 16, 2023
1 parent df8c0d2 commit b57ba42
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi

// Set or get the running state

void SetState(State state)
void SetState(State state, bool report_state_change)
{
// State cannot be controlled until the CPU Thread is operational
if (!IsRunningAndStarted())
Expand All @@ -739,7 +739,10 @@ void SetState(State state)
break;
}

CallOnStateChangedCallbacks(GetState());
// Certain callers only change the state momentarily. Sending a callback for them causes
// unwanted updates, such as the Pause/Play button flickering between states on frame advance.
if (report_state_change)
CallOnStateChangedCallbacks(GetState());
}

State GetState()
Expand Down Expand Up @@ -1083,7 +1086,7 @@ void DoFrameStep()
// if already paused, frame advance for 1 frame
s_stop_frame_step = false;
s_frame_step = true;
SetState(State::Running);
SetState(State::Running, false);
}
else if (!s_frame_step)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool IsHostThread();
bool WantsDeterminism();

// [NOT THREADSAFE] For use by Host only
void SetState(State state);
void SetState(State state, bool report_state_change = true);
State GetState();

void SaveScreenShot();
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/Debugger/CodeDiffDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void CodeDiffDialog::ClearBlockCache()
Core::State old_state = Core::GetState();

if (old_state == Core::State::Running)
Core::SetState(Core::State::Paused);
Core::SetState(Core::State::Paused, false);

Core::System::GetInstance().GetJitInterface().ClearCache();

Expand Down Expand Up @@ -349,7 +349,7 @@ void CodeDiffDialog::Update(bool include)
// Wrap everything in a pause
Core::State old_state = Core::GetState();
if (old_state == Core::State::Running)
Core::SetState(Core::State::Paused);
Core::SetState(Core::State::Paused, false);

// Main process
if (include)
Expand Down

0 comments on commit b57ba42

Please sign in to comment.