Skip to content

Commit

Permalink
Merge pull request #12695 from mitaclaw/core-global-system-4
Browse files Browse the repository at this point in the history
Core::IsRunning: Avoid Global System Accessor
  • Loading branch information
AdmiralCurtiss committed May 4, 2024
2 parents e2dc6f3 + 0df401b commit c23562b
Show file tree
Hide file tree
Showing 25 changed files with 90 additions and 74 deletions.
7 changes: 4 additions & 3 deletions Source/Android/jni/MainAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void Host_Message(HostMessageID id)
}
else if (id == HostMessageID::WMUserStop)
{
if (Core::IsRunning())
if (Core::IsRunning(Core::System::GetInstance()))
Core::QueueHostJob(&Core::Stop);
}
}
Expand Down Expand Up @@ -272,7 +272,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetIsBooting

JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv*, jclass)
{
return s_is_booting.IsSet() || static_cast<jboolean>(Core::IsRunning());
return s_is_booting.IsSet() ||
static_cast<jboolean>(Core::IsRunning(Core::System::GetInstance()));
}

JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndStarted(JNIEnv*,
Expand Down Expand Up @@ -589,7 +590,7 @@ static void Run(JNIEnv* env, std::unique_ptr<BootParameters>&& boot, bool riivol
s_need_nonblocking_alert_msg = false;
surface_guard.unlock();

while (Core::IsRunning())
while (Core::IsRunning(Core::System::GetInstance()))
{
host_identity_guard.Unlock();
s_update_main_frame_event.Wait();
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
#include "Core/IOS/IOS.h"
#include "Core/IOS/USB/Bluetooth/BTBase.h"
#include "Core/SysConf.h"
#include "Core/System.h"

namespace ConfigLoaders
{
void SaveToSYSCONF(Config::LayerType layer, std::function<bool(const Config::Location&)> predicate)
{
if (Core::IsRunning())
if (Core::IsRunning(Core::System::GetInstance()))
return;

IOS::HLE::Kernel ios;
Expand Down Expand Up @@ -182,7 +183,7 @@ class BaseConfigLayerLoader final : public Config::ConfigLayerLoader
private:
void LoadFromSYSCONF(Config::Layer* layer)
{
if (Core::IsRunning())
if (Core::IsRunning(Core::System::GetInstance()))
return;

IOS::HLE::Kernel ios;
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/Core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,24 @@ void SConfig::SetRunningGameMetadata(const std::string& game_id, const std::stri
m_title_description = title_database.Describe(m_gametdb_id, language);
NOTICE_LOG_FMT(CORE, "Active title: {}", m_title_description);
Host_TitleChanged();
if (Core::IsRunning())
if (Core::IsRunning(system))
{
Core::UpdateTitle(system);
}

Config::AddLayer(ConfigLoaders::GenerateGlobalGameConfigLoader(game_id, revision));
Config::AddLayer(ConfigLoaders::GenerateLocalGameConfigLoader(game_id, revision));

if (Core::IsRunning())
if (Core::IsRunning(system))
DolphinAnalytics::Instance().ReportGameStart();
}

void SConfig::OnNewTitleLoad(const Core::CPUThreadGuard& guard)
{
if (!Core::IsRunning())
auto& system = guard.GetSystem();
if (!Core::IsRunning(system))
return;

auto& system = guard.GetSystem();
auto& ppc_symbol_db = system.GetPPCSymbolDB();
if (!ppc_symbol_db.IsEmpty())
{
Expand Down
11 changes: 5 additions & 6 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ std::string StopMessage(bool main_thread, std::string_view message)

void DisplayMessage(std::string message, int time_in_ms)
{
if (!IsRunning())
if (!IsRunning(Core::System::GetInstance()))
return;

// Actually displaying non-ASCII could cause things to go pear-shaped
Expand All @@ -200,9 +200,8 @@ void DisplayMessage(std::string message, int time_in_ms)
OSD::AddMessage(std::move(message), time_in_ms);
}

bool IsRunning()
bool IsRunning(Core::System& system)
{
auto& system = Core::System::GetInstance();
return (GetState(system) != State::Uninitialized || s_hardware_initialized) && !s_is_stopping;
}

Expand Down Expand Up @@ -237,7 +236,7 @@ bool Init(Core::System& system, std::unique_ptr<BootParameters> boot, const Wind
{
if (s_emu_thread.joinable())
{
if (IsRunning())
if (IsRunning(system))
{
PanicAlertFmtT("Emu Thread already running");
return false;
Expand Down Expand Up @@ -842,7 +841,7 @@ static bool PauseAndLock(Core::System& system, bool do_lock, bool unpause_on_unl
void RunOnCPUThread(Core::System& system, std::function<void()> function, bool wait_for_completion)
{
// If the CPU thread is not running, assume there is no active CPU thread we can race against.
if (!IsRunning() || IsCPUThread())
if (!IsRunning(system) || IsCPUThread())
{
function();
return;
Expand Down Expand Up @@ -1038,7 +1037,7 @@ void HostDispatchJobs(Core::System& system)
// Core::State::Uninitialized: s_is_booting -> s_hardware_initialized
// We need to check variables in the same order as the state
// transition, otherwise we race and get transient failures.
if (!job.run_after_stop && !s_is_booting.IsSet() && !IsRunning())
if (!job.run_after_stop && !s_is_booting.IsSet() && !IsRunning(system))
continue;

guard.unlock();
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 @@ -134,7 +134,7 @@ void UndeclareAsHostThread();

std::string StopMessage(bool main_thread, std::string_view message);

bool IsRunning();
bool IsRunning(Core::System& system);
bool IsRunningAndStarted(); // is running and the CPU loop has been entered
bool IsCPUThread(); // this tells us whether we are the CPU thread.
bool IsGPUThread();
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/Debugger/Debugger_SymbolMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ static void WalkTheStack(const Core::CPUThreadGuard& guard,
// instead of "pointing ahead"
bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector<CallstackEntry>& output)
{
auto& power_pc = guard.GetSystem().GetPowerPC();
auto& system = guard.GetSystem();
auto& power_pc = system.GetPowerPC();
const auto& ppc_state = power_pc.GetPPCState();

if (!Core::IsRunning() || !PowerPC::MMU::HostIsRAMAddress(guard, ppc_state.gpr[1]))
if (!Core::IsRunning(system) || !PowerPC::MMU::HostIsRAMAddress(guard, ppc_state.gpr[1]))
return false;

if (LR(ppc_state) == 0)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/FifoPlayer/FifoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void FifoPlayer::Close()

bool FifoPlayer::IsPlaying() const
{
return GetFile() != nullptr && Core::IsRunning();
return GetFile() != nullptr && Core::IsRunning(m_system);
}

class FifoPlayer::CPUCore final : public CPUCoreBase
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/HW/ProcessorInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void ProcessorInterfaceManager::IOSNotifyPowerButtonCallback(Core::System& syste

void ProcessorInterfaceManager::ResetButton_Tap()
{
if (!Core::IsRunning())
if (!Core::IsRunning(m_system))
return;

auto& core_timing = m_system.GetCoreTiming();
Expand All @@ -268,7 +268,7 @@ void ProcessorInterfaceManager::ResetButton_Tap()

void ProcessorInterfaceManager::PowerButton_Tap()
{
if (!Core::IsRunning())
if (!Core::IsRunning(m_system))
return;

auto& core_timing = m_system.GetCoreTiming();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/IOS/IOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ bool EmulationKernel::BootIOS(const u64 ios_title_id, HangPPC hang_ppc,

void EmulationKernel::InitIPC()
{
if (!Core::IsRunning())
if (!Core::IsRunning(m_system))
return;

INFO_LOG_FMT(IOS, "IPC initialised.");
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/Movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ bool MovieManager::IsNetPlayRecording() const
// NOTE: Host Thread
void MovieManager::ChangePads()
{
if (!Core::IsRunning())
if (!Core::IsRunning(m_system))
return;

ControllerTypeArray controllers{};
Expand Down Expand Up @@ -572,7 +572,7 @@ bool MovieManager::BeginRecordingInput(const ControllerTypeArray& controllers,
ConfigLoaders::SaveToDTM(&header);
Config::AddLayer(ConfigLoaders::GenerateMovieConfigLoader(&header));

if (Core::IsRunning())
if (Core::IsRunning(m_system))
Core::UpdateWantDeterminism(m_system);
};
Core::RunOnCPUThread(m_system, start_recording, true);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ static void LoadFileStateData(const std::string& filename, std::vector<u8>& ret_

void LoadAs(Core::System& system, const std::string& filename)
{
if (!Core::IsRunning())
if (!Core::IsRunning(system))
return;

if (NetPlay::IsNetPlayRunning())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ void AchievementSettingsWidget::LoadSettings()
SignalBlocking(m_common_password_input)->setVisible(logged_out);
SignalBlocking(m_common_password_input)->setEnabled(enabled);
SignalBlocking(m_common_login_button)->setVisible(logged_out);
SignalBlocking(m_common_login_button)->setEnabled(enabled && !Core::IsRunning());
SignalBlocking(m_common_login_button)
->setEnabled(enabled && !Core::IsRunning(Core::System::GetInstance()));
SignalBlocking(m_common_logout_button)->setVisible(!logged_out);
SignalBlocking(m_common_logout_button)->setEnabled(enabled);

Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinQt/Config/CheatWarningWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/System.h"

#include "DolphinQt/Settings.h"

Expand All @@ -22,11 +23,11 @@ CheatWarningWidget::CheatWarningWidget(const std::string& game_id, bool restart_
ConnectWidgets();

connect(&Settings::Instance(), &Settings::EnableCheatsChanged, this,
[this] { Update(Core::IsRunning()); });
[this] { Update(Core::IsRunning(Core::System::GetInstance())); });
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
[this](Core::State state) { Update(state == Core::State::Running); });

Update(Core::IsRunning());
Update(Core::IsRunning(Core::System::GetInstance()));
}

void CheatWarningWidget::CreateWidgets()
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ void GamecubeControllersWidget::SaveSettings()
{
Config::ConfigChangeCallbackGuard config_guard;

auto& system = Core::System::GetInstance();
for (size_t i = 0; i < m_gc_groups.size(); ++i)
{
const SerialInterface::SIDevices si_device =
FromGCMenuIndex(m_gc_controller_boxes[i]->currentIndex());
Config::SetBaseOrCurrent(Config::GetInfoForSIDevice(static_cast<int>(i)), si_device);

if (Core::IsRunning())
if (Core::IsRunning(system))
{
Core::System::GetInstance().GetSerialInterface().ChangeDevice(si_device,
static_cast<s32>(i));
system.GetSerialInterface().ChangeDevice(si_device, static_cast<s32>(i));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Config/Graphics/GeneralWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void GeneralWidget::OnBackendChanged(const QString& backend_name)
const bool supports_adapters = !adapters.empty();

m_adapter_combo->setCurrentIndex(g_Config.iAdapter);
m_adapter_combo->setEnabled(supports_adapters && !Core::IsRunning());
m_adapter_combo->setEnabled(supports_adapters && !Core::IsRunning(Core::System::GetInstance()));

static constexpr char TR_ADAPTER_AVAILABLE_DESCRIPTION[] =
QT_TR_NOOP("Selects a hardware adapter to use.<br><br>"
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/Debugger/MemoryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ QByteArray MemoryWidget::GetInputData() const

void MemoryWidget::OnSetValue()
{
if (!Core::IsRunning())
if (!Core::IsRunning(m_system))
return;

auto target_addr = GetTargetAddress();
Expand Down Expand Up @@ -675,7 +675,7 @@ void MemoryWidget::OnSetValue()

void MemoryWidget::OnSetValueFromFile()
{
if (!Core::IsRunning())
if (!Core::IsRunning(m_system))
return;

auto target_addr = GetTargetAddress();
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/DolphinQt/Debugger/WatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void WatchWidget::UpdateButtonsEnabled()
if (!isVisible())
return;

const bool is_enabled = Core::IsRunning();
const bool is_enabled = Core::IsRunning(m_system);
m_new->setEnabled(is_enabled);
m_delete->setEnabled(is_enabled);
m_clear->setEnabled(is_enabled);
Expand Down Expand Up @@ -195,10 +195,10 @@ void WatchWidget::Update()

QBrush brush = QPalette().brush(QPalette::Text);

if (!Core::IsRunning() || !PowerPC::MMU::HostIsRAMAddress(guard, entry.address))
if (!Core::IsRunning(m_system) || !PowerPC::MMU::HostIsRAMAddress(guard, entry.address))
brush.setColor(Qt::red);

if (Core::IsRunning())
if (Core::IsRunning(m_system))
{
if (PowerPC::MMU::HostIsRAMAddress(guard, entry.address))
{
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinQt/FIFO/FIFOPlayerWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Core/FifoPlayer/FifoDataFile.h"
#include "Core/FifoPlayer/FifoPlayer.h"
#include "Core/FifoPlayer/FifoRecorder.h"
#include "Core/System.h"

#include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h"
#include "DolphinQt/FIFO/FIFOAnalyzer.h"
Expand Down Expand Up @@ -316,7 +317,7 @@ void FIFOPlayerWindow::UpdateInfo()
return;
}

if (Core::IsRunning() && m_fifo_recorder.IsRecording())
if (Core::IsRunning(Core::System::GetInstance()) && m_fifo_recorder.IsRecording())
{
m_info_label->setText(tr("Recording..."));
return;
Expand Down Expand Up @@ -375,7 +376,7 @@ void FIFOPlayerWindow::UpdateLimits()

void FIFOPlayerWindow::UpdateControls()
{
bool running = Core::IsRunning();
bool running = Core::IsRunning(Core::System::GetInstance());
bool is_recording = m_fifo_recorder.IsRecording();
bool is_playing = m_fifo_player.IsPlaying();

Expand Down
Loading

0 comments on commit c23562b

Please sign in to comment.