From 16c609dcd45780a1cc97660d6e8a23936f9adfe3 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Fri, 1 Mar 2024 23:39:04 -0800 Subject: [PATCH] BootManager: Avoid Global System Accessor --- Source/Android/jni/MainAndroid.cpp | 2 +- Source/Core/Core/BootManager.cpp | 4 ++-- Source/Core/Core/BootManager.h | 7 ++++++- Source/Core/DolphinNoGUI/MainNoGUI.cpp | 3 ++- Source/Core/DolphinQt/MainWindow.cpp | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 6a74cabd87..827b535c8f 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -570,7 +570,7 @@ static void Run(JNIEnv* env, std::unique_ptr&& boot, bool riivol s_need_nonblocking_alert_msg = true; std::unique_lock surface_guard(s_surface_lock); - if (BootManager::BootCore(std::move(boot), wsi)) + if (BootManager::BootCore(Core::System::GetInstance(), std::move(boot), wsi)) { static constexpr int WAIT_STEP = 25; while (Core::GetState() == Core::State::Starting) diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index 1c0bc7e04c..1c87994bf9 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -55,12 +55,12 @@ namespace BootManager { // Boot the ISO or file -bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) +bool BootCore(Core::System& system, std::unique_ptr boot, + const WindowSystemInfo& wsi) { if (!boot) return false; - auto& system = Core::System::GetInstance(); SConfig& StartUp = SConfig::GetInstance(); if (!StartUp.SetPathsAndGameMetadata(system, *boot)) diff --git a/Source/Core/Core/BootManager.h b/Source/Core/Core/BootManager.h index 10474c5f3f..e8ec568921 100644 --- a/Source/Core/Core/BootManager.h +++ b/Source/Core/Core/BootManager.h @@ -5,12 +5,17 @@ #include +namespace Core +{ +class System; +} struct BootParameters; struct WindowSystemInfo; namespace BootManager { -bool BootCore(std::unique_ptr parameters, const WindowSystemInfo& wsi); +bool BootCore(Core::System& system, std::unique_ptr parameters, + const WindowSystemInfo& wsi); // Synchronise Dolphin's configuration with the SYSCONF (which may have changed during emulation), // and restore settings that were overriden by per-game INIs or for some other reason. diff --git a/Source/Core/DolphinNoGUI/MainNoGUI.cpp b/Source/Core/DolphinNoGUI/MainNoGUI.cpp index ff69e6bf7a..9db8ef8a47 100644 --- a/Source/Core/DolphinNoGUI/MainNoGUI.cpp +++ b/Source/Core/DolphinNoGUI/MainNoGUI.cpp @@ -24,6 +24,7 @@ #include "Core/Core.h" #include "Core/DolphinAnalytics.h" #include "Core/Host.h" +#include "Core/System.h" #include "UICommon/CommandLineParse.h" #ifdef USE_DISCORD_PRESENCE @@ -304,7 +305,7 @@ int main(int argc, char* argv[]) DolphinAnalytics::Instance().ReportDolphinStart("nogui"); - if (!BootManager::BootCore(std::move(boot), wsi)) + if (!BootManager::BootCore(Core::System::GetInstance(), std::move(boot), wsi)) { fprintf(stderr, "Could not boot the specified file\n"); return 1; diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index ff028f5d37..54b75c05c1 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -1126,7 +1126,7 @@ void MainWindow::StartGame(std::unique_ptr&& parameters) ShowRenderWidget(); // Boot up, show an error if it fails to load the game. - if (!BootManager::BootCore(std::move(parameters), + if (!BootManager::BootCore(Core::System::GetInstance(), std::move(parameters), ::GetWindowSystemInfo(m_render_widget->windowHandle()))) { ModalMessageBox::critical(this, tr("Error"), tr("Failed to init core"), QMessageBox::Ok);