Skip to content

Commit

Permalink
Core::SetState: Avoid Global System Accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
mitaclaw committed May 4, 2024
1 parent c23562b commit 70b870e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
11 changes: 5 additions & 6 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ static void CPUSetInitialExecutionState(bool force_paused = false)
{
// The CPU starts in stepping state, and will wait until a new state is set before executing.
// SetState must be called on the host thread, so we defer it for later.
QueueHostJob([force_paused](Core::System&) {
QueueHostJob([force_paused](Core::System& system) {
bool paused = SConfig::GetInstance().bBootToPause || force_paused;
SetState(paused ? State::Paused : State::Running);
SetState(system, paused ? State::Paused : State::Running);
Host_UpdateDisasmDialog();
Host_UpdateMainFrame();
Host_Message(HostMessageID::WMUserCreate);
Expand Down Expand Up @@ -700,13 +700,12 @@ static void EmuThread(Core::System& system, std::unique_ptr<BootParameters> boot

// Set or get the running state

void SetState(State state, bool report_state_change)
void SetState(Core::System& system, State state, bool report_state_change)
{
// State cannot be controlled until the CPU Thread is operational
if (!IsRunningAndStarted())
return;

auto& system = Core::System::GetInstance();
switch (state)
{
case State::Paused:
Expand Down Expand Up @@ -1061,12 +1060,12 @@ void DoFrameStep(Core::System& system)
// if already paused, frame advance for 1 frame
s_stop_frame_step = false;
s_frame_step = true;
SetState(State::Running, false);
SetState(system, State::Running, false);
}
else if (!s_frame_step)
{
// if not paused yet, pause immediately instead
SetState(State::Paused);
SetState(system, State::Paused);
}
}

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 @@ -143,7 +143,7 @@ bool IsHostThread();
bool WantsDeterminism();

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

void SaveScreenShot();
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinNoGUI/PlatformMacos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ - (void)togglePause
{
auto& system = Core::System::GetInstance();
if (Core::GetState(system) == Core::State::Running)
Core::SetState(Core::State::Paused);
Core::SetState(system, Core::State::Paused);
else
Core::SetState(Core::State::Running);
Core::SetState(system, Core::State::Running);
}

- (void)saveScreenShot
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinNoGUI/PlatformX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ void PlatformX11::ProcessEvents()
{
if (Config::Get(Config::MAIN_SHOW_CURSOR) == Config::ShowCursor::Never)
XUndefineCursor(m_display, m_window);
Core::SetState(Core::State::Paused);
Core::SetState(Core::System::GetInstance(), Core::State::Paused);
}
else
{
if (Config::Get(Config::MAIN_SHOW_CURSOR) == Config::ShowCursor::Never)
XDefineCursor(m_display, m_window, m_blank_cursor);
Core::SetState(Core::State::Running);
Core::SetState(Core::System::GetInstance(), Core::State::Running);
}
}
else if ((key == XK_Return) && (event.xkey.state & Mod1Mask))
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/DolphinQt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ void MainWindow::Play(const std::optional<std::string>& savestate_path)
// Otherwise, prompt for a new game.
if (Core::GetState(Core::System::GetInstance()) == Core::State::Paused)
{
Core::SetState(Core::State::Running);
Core::SetState(Core::System::GetInstance(), Core::State::Running);
}
else
{
Expand Down Expand Up @@ -853,7 +853,7 @@ void MainWindow::Play(const std::optional<std::string>& savestate_path)

void MainWindow::Pause()
{
Core::SetState(Core::State::Paused);
Core::SetState(Core::System::GetInstance(), Core::State::Paused);
}

void MainWindow::TogglePause()
Expand Down Expand Up @@ -932,7 +932,7 @@ bool MainWindow::RequestStop()
bool pause = !Settings::Instance().GetNetPlayClient();

if (pause)
Core::SetState(Core::State::Paused);
Core::SetState(Core::System::GetInstance(), Core::State::Paused);

if (rendered_widget_was_active)
{
Expand Down Expand Up @@ -962,7 +962,7 @@ bool MainWindow::RequestStop()
m_render_widget->SetWaitingForMessageBox(false);

if (pause)
Core::SetState(state);
Core::SetState(Core::System::GetInstance(), state);

return false;
}
Expand All @@ -984,7 +984,7 @@ bool MainWindow::RequestStop()
// Unpause because gracefully shutting down needs the game to actually request a shutdown.
// TODO: Do not unpause in debug mode to allow debugging until the complete shutdown.
if (Core::GetState(Core::System::GetInstance()) == Core::State::Paused)
Core::SetState(Core::State::Running);
Core::SetState(Core::System::GetInstance(), Core::State::Running);

// Tell NetPlay about the power event
if (NetPlay::IsNetPlayRunning())
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/RenderWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ bool RenderWidget::event(QEvent* event)
if (m_should_unpause_on_focus &&
Core::GetState(Core::System::GetInstance()) == Core::State::Paused)
{
Core::SetState(Core::State::Running);
Core::SetState(Core::System::GetInstance(), Core::State::Running);
}

m_should_unpause_on_focus = false;
Expand Down Expand Up @@ -457,7 +457,7 @@ bool RenderWidget::event(QEvent* event)
if (!Core::IsCPUThread() && !Core::IsGPUThread())
{
m_should_unpause_on_focus = true;
Core::SetState(Core::State::Paused);
Core::SetState(Core::System::GetInstance(), Core::State::Paused);
}
}

Expand Down

0 comments on commit 70b870e

Please sign in to comment.