Merge pull request #7182 from Morph1984/system

yuzu: Remove all remaining global system instances
This commit is contained in:
Mai M 2021-10-15 17:57:58 -04:00 committed by GitHub
commit dc385b7392
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 164 additions and 180 deletions

View file

@ -139,8 +139,8 @@ struct System::Impl {
: kernel{system}, fs_controller{system}, memory{system}, : kernel{system}, fs_controller{system}, memory{system},
cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system} {} cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system} {}
ResultStatus Run() { SystemResultStatus Run() {
status = ResultStatus::Success; status = SystemResultStatus::Success;
kernel.Suspend(false); kernel.Suspend(false);
core_timing.SyncPause(false); core_timing.SyncPause(false);
@ -149,8 +149,8 @@ struct System::Impl {
return status; return status;
} }
ResultStatus Pause() { SystemResultStatus Pause() {
status = ResultStatus::Success; status = SystemResultStatus::Success;
core_timing.SyncPause(true); core_timing.SyncPause(true);
kernel.Suspend(true); kernel.Suspend(true);
@ -159,7 +159,7 @@ struct System::Impl {
return status; return status;
} }
ResultStatus Init(System& system, Frontend::EmuWindow& emu_window) { SystemResultStatus Init(System& system, Frontend::EmuWindow& emu_window) {
LOG_DEBUG(Core, "initialized OK"); LOG_DEBUG(Core, "initialized OK");
device_memory = std::make_unique<Core::DeviceMemory>(); device_memory = std::make_unique<Core::DeviceMemory>();
@ -197,7 +197,7 @@ struct System::Impl {
gpu_core = VideoCore::CreateGPU(emu_window, system); gpu_core = VideoCore::CreateGPU(emu_window, system);
if (!gpu_core) { if (!gpu_core) {
return ResultStatus::ErrorVideoCore; return SystemResultStatus::ErrorVideoCore;
} }
service_manager = std::make_shared<Service::SM::ServiceManager>(kernel); service_manager = std::make_shared<Service::SM::ServiceManager>(kernel);
@ -217,21 +217,22 @@ struct System::Impl {
LOG_DEBUG(Core, "Initialized OK"); LOG_DEBUG(Core, "Initialized OK");
return ResultStatus::Success; return SystemResultStatus::Success;
} }
ResultStatus Load(System& system, Frontend::EmuWindow& emu_window, const std::string& filepath, SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window,
u64 program_id, std::size_t program_index) { const std::string& filepath, u64 program_id,
std::size_t program_index) {
app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath), app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath),
program_id, program_index); program_id, program_index);
if (!app_loader) { if (!app_loader) {
LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
return ResultStatus::ErrorGetLoader; return SystemResultStatus::ErrorGetLoader;
} }
ResultStatus init_result{Init(system, emu_window)}; SystemResultStatus init_result{Init(system, emu_window)};
if (init_result != ResultStatus::Success) { if (init_result != SystemResultStatus::Success) {
LOG_CRITICAL(Core, "Failed to initialize system (Error {})!", LOG_CRITICAL(Core, "Failed to initialize system (Error {})!",
static_cast<int>(init_result)); static_cast<int>(init_result));
Shutdown(); Shutdown();
@ -249,8 +250,8 @@ struct System::Impl {
LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result);
Shutdown(); Shutdown();
return static_cast<ResultStatus>(static_cast<u32>(ResultStatus::ErrorLoader) + return static_cast<SystemResultStatus>(
static_cast<u32>(load_result)); static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result));
} }
AddGlueRegistrationForProcess(*app_loader, *main_process); AddGlueRegistrationForProcess(*app_loader, *main_process);
kernel.MakeCurrentProcess(main_process.get()); kernel.MakeCurrentProcess(main_process.get());
@ -282,7 +283,7 @@ struct System::Impl {
GetAndResetPerfStats(); GetAndResetPerfStats();
perf_stats->BeginSystemFrame(); perf_stats->BeginSystemFrame();
status = ResultStatus::Success; status = SystemResultStatus::Success;
return status; return status;
} }
@ -355,7 +356,7 @@ struct System::Impl {
arp_manager.Register(launch.title_id, launch, std::move(nacp_data)); arp_manager.Register(launch.title_id, launch, std::move(nacp_data));
} }
void SetStatus(ResultStatus new_status, const char* details = nullptr) { void SetStatus(SystemResultStatus new_status, const char* details = nullptr) {
status = new_status; status = new_status;
if (details) { if (details) {
status_details = details; status_details = details;
@ -411,7 +412,7 @@ struct System::Impl {
/// Network instance /// Network instance
Network::NetworkInstance network_instance; Network::NetworkInstance network_instance;
ResultStatus status = ResultStatus::Success; SystemResultStatus status = SystemResultStatus::Success;
std::string status_details = ""; std::string status_details = "";
std::unique_ptr<Core::PerfStats> perf_stats; std::unique_ptr<Core::PerfStats> perf_stats;
@ -428,22 +429,9 @@ struct System::Impl {
}; };
System::System() : impl{std::make_unique<Impl>(*this)} {} System::System() : impl{std::make_unique<Impl>(*this)} {}
System::~System() = default; System::~System() = default;
System& System::GetInstance() {
if (!s_instance) {
throw std::runtime_error("Using System instance before its initialization");
}
return *s_instance;
}
void System::InitializeGlobalInstance() {
if (s_instance) {
throw std::runtime_error("Reinitializing Global System instance.");
}
s_instance = std::unique_ptr<System>(new System);
}
CpuManager& System::GetCpuManager() { CpuManager& System::GetCpuManager() {
return impl->cpu_manager; return impl->cpu_manager;
} }
@ -452,16 +440,16 @@ const CpuManager& System::GetCpuManager() const {
return impl->cpu_manager; return impl->cpu_manager;
} }
System::ResultStatus System::Run() { SystemResultStatus System::Run() {
return impl->Run(); return impl->Run();
} }
System::ResultStatus System::Pause() { SystemResultStatus System::Pause() {
return impl->Pause(); return impl->Pause();
} }
System::ResultStatus System::SingleStep() { SystemResultStatus System::SingleStep() {
return ResultStatus::Success; return SystemResultStatus::Success;
} }
void System::InvalidateCpuInstructionCaches() { void System::InvalidateCpuInstructionCaches() {
@ -476,7 +464,7 @@ void System::Shutdown() {
impl->Shutdown(); impl->Shutdown();
} }
System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath, SystemResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath,
u64 program_id, std::size_t program_index) { u64 program_id, std::size_t program_index) {
return impl->Load(*this, emu_window, filepath, program_id, program_index); return impl->Load(*this, emu_window, filepath, program_id, program_index);
} }
@ -637,7 +625,7 @@ Loader::ResultStatus System::GetGameName(std::string& out) const {
return impl->GetGameName(out); return impl->GetGameName(out);
} }
void System::SetStatus(ResultStatus new_status, const char* details) { void System::SetStatus(SystemResultStatus new_status, const char* details) {
impl->SetStatus(new_status, details); impl->SetStatus(new_status, details);
} }

View file

@ -104,28 +104,8 @@ struct PerfStatsResults;
FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
const std::string& path); const std::string& path);
class System {
public:
using CurrentBuildProcessID = std::array<u8, 0x20>;
System(const System&) = delete;
System& operator=(const System&) = delete;
System(System&&) = delete;
System& operator=(System&&) = delete;
~System();
/**
* Gets the instance of the System singleton class.
* @returns Reference to the instance of the System singleton class.
*/
[[deprecated("Use of the global system instance is deprecated")]] static System& GetInstance();
static void InitializeGlobalInstance();
/// Enumeration representing the return values of the System Initialize and Load process. /// Enumeration representing the return values of the System Initialize and Load process.
enum class ResultStatus : u32 { enum class SystemResultStatus : u32 {
Success, ///< Succeeded Success, ///< Succeeded
ErrorNotInitialized, ///< Error trying to use core prior to initialization ErrorNotInitialized, ///< Error trying to use core prior to initialization
ErrorGetLoader, ///< Error finding the correct application loader ErrorGetLoader, ///< Error finding the correct application loader
@ -136,23 +116,37 @@ public:
ErrorLoader, ///< The base for loader errors (too many to repeat) ErrorLoader, ///< The base for loader errors (too many to repeat)
}; };
class System {
public:
using CurrentBuildProcessID = std::array<u8, 0x20>;
explicit System();
~System();
System(const System&) = delete;
System& operator=(const System&) = delete;
System(System&&) = delete;
System& operator=(System&&) = delete;
/** /**
* Run the OS and Application * Run the OS and Application
* This function will start emulation and run the relevant devices * This function will start emulation and run the relevant devices
*/ */
[[nodiscard]] ResultStatus Run(); [[nodiscard]] SystemResultStatus Run();
/** /**
* Pause the OS and Application * Pause the OS and Application
* This function will pause emulation and stop the relevant devices * This function will pause emulation and stop the relevant devices
*/ */
[[nodiscard]] ResultStatus Pause(); [[nodiscard]] SystemResultStatus Pause();
/** /**
* Step the CPU one instruction * Step the CPU one instruction
* @return Result status, indicating whether or not the operation succeeded. * @return Result status, indicating whether or not the operation succeeded.
*/ */
[[nodiscard]] ResultStatus SingleStep(); [[nodiscard]] SystemResultStatus SingleStep();
/** /**
* Invalidate the CPU instruction caches * Invalidate the CPU instruction caches
@ -172,10 +166,11 @@ public:
* input. * input.
* @param filepath String path to the executable application to load on the host file system. * @param filepath String path to the executable application to load on the host file system.
* @param program_index Specifies the index within the container of the program to launch. * @param program_index Specifies the index within the container of the program to launch.
* @returns ResultStatus code, indicating if the operation succeeded. * @returns SystemResultStatus code, indicating if the operation succeeded.
*/ */
[[nodiscard]] ResultStatus Load(Frontend::EmuWindow& emu_window, const std::string& filepath, [[nodiscard]] SystemResultStatus Load(Frontend::EmuWindow& emu_window,
u64 program_id = 0, std::size_t program_index = 0); const std::string& filepath, u64 program_id = 0,
std::size_t program_index = 0);
/** /**
* Indicates if the emulated system is powered on (all subsystems initialized and able to run an * Indicates if the emulated system is powered on (all subsystems initialized and able to run an
@ -301,7 +296,7 @@ public:
/// Gets the name of the current game /// Gets the name of the current game
[[nodiscard]] Loader::ResultStatus GetGameName(std::string& out) const; [[nodiscard]] Loader::ResultStatus GetGameName(std::string& out) const;
void SetStatus(ResultStatus new_status, const char* details); void SetStatus(SystemResultStatus new_status, const char* details);
[[nodiscard]] const std::string& GetStatusDetails() const; [[nodiscard]] const std::string& GetStatusDetails() const;
@ -403,12 +398,8 @@ public:
void ApplySettings(); void ApplySettings();
private: private:
System();
struct Impl; struct Impl;
std::unique_ptr<Impl> impl; std::unique_ptr<Impl> impl;
inline static std::unique_ptr<System> s_instance{};
}; };
} // namespace Core } // namespace Core

View file

@ -86,15 +86,15 @@ void EmuThread::run() {
} }
running_guard = true; running_guard = true;
Core::System::ResultStatus result = system.Run(); Core::SystemResultStatus result = system.Run();
if (result != Core::System::ResultStatus::Success) { if (result != Core::SystemResultStatus::Success) {
running_guard = false; running_guard = false;
this->SetRunning(false); this->SetRunning(false);
emit ErrorThrown(result, system.GetStatusDetails()); emit ErrorThrown(result, system.GetStatusDetails());
} }
running_wait.Wait(); running_wait.Wait();
result = system.Pause(); result = system.Pause();
if (result != Core::System::ResultStatus::Success) { if (result != Core::SystemResultStatus::Success) {
running_guard = false; running_guard = false;
this->SetRunning(false); this->SetRunning(false);
emit ErrorThrown(result, system.GetStatusDetails()); emit ErrorThrown(result, system.GetStatusDetails());

View file

@ -16,7 +16,6 @@
#include <QWindow> #include <QWindow>
#include "common/thread.h" #include "common/thread.h"
#include "core/core.h"
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
class GRenderWindow; class GRenderWindow;
@ -24,6 +23,11 @@ class GMainWindow;
class QKeyEvent; class QKeyEvent;
class QStringList; class QStringList;
namespace Core {
enum class SystemResultStatus : u32;
class System;
} // namespace Core
namespace InputCommon { namespace InputCommon {
class InputSubsystem; class InputSubsystem;
} }
@ -123,7 +127,7 @@ signals:
*/ */
void DebugModeLeft(); void DebugModeLeft();
void ErrorThrown(Core::System::ResultStatus, std::string); void ErrorThrown(Core::SystemResultStatus, std::string);
void LoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total); void LoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total);
}; };

View file

@ -172,7 +172,7 @@ void GMainWindow::ShowTelemetryCallout() {
"<br/><br/>Would you like to share your usage data with us?"); "<br/><br/>Would you like to share your usage data with us?");
if (QMessageBox::question(this, tr("Telemetry"), telemetry_message) != QMessageBox::Yes) { if (QMessageBox::question(this, tr("Telemetry"), telemetry_message) != QMessageBox::Yes) {
Settings::values.enable_telemetry = false; Settings::values.enable_telemetry = false;
system.ApplySettings(); system->ApplySettings();
} }
} }
@ -191,9 +191,10 @@ static void RemoveCachedContents() {
Common::FS::RemoveDirRecursively(offline_system_data); Common::FS::RemoveDirRecursively(offline_system_data);
} }
GMainWindow::GMainWindow(Core::System& system_) GMainWindow::GMainWindow()
: input_subsystem{std::make_shared<InputCommon::InputSubsystem>()}, system{system_}, : system{std::make_unique<Core::System>()},
config{std::make_unique<Config>(system_)}, input_subsystem{std::make_shared<InputCommon::InputSubsystem>()},
config{std::make_unique<Config>(*system)},
vfs{std::make_shared<FileSys::RealVfsFilesystem>()}, vfs{std::make_shared<FileSys::RealVfsFilesystem>()},
provider{std::make_unique<FileSys::ManualContentProvider>()} { provider{std::make_unique<FileSys::ManualContentProvider>()} {
Common::Log::Initialize(); Common::Log::Initialize();
@ -257,10 +258,10 @@ GMainWindow::GMainWindow(Core::System& system_)
show(); show();
system.SetContentProvider(std::make_unique<FileSys::ContentProviderUnion>()); system->SetContentProvider(std::make_unique<FileSys::ContentProviderUnion>());
system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::FrontendManual, system->RegisterContentProvider(FileSys::ContentProviderUnionSlot::FrontendManual,
provider.get()); provider.get());
system.GetFileSystemController().CreateFactories(*vfs); system->GetFileSystemController().CreateFactories(*vfs);
// Remove cached contents generated during the previous session // Remove cached contents generated during the previous session
RemoveCachedContents(); RemoveCachedContents();
@ -406,12 +407,12 @@ void GMainWindow::RegisterMetaTypes() {
qRegisterMetaType<Service::AM::Applets::WebExitReason>("Service::AM::Applets::WebExitReason"); qRegisterMetaType<Service::AM::Applets::WebExitReason>("Service::AM::Applets::WebExitReason");
// Register loader types // Register loader types
qRegisterMetaType<Core::System::ResultStatus>("Core::System::ResultStatus"); qRegisterMetaType<Core::SystemResultStatus>("Core::SystemResultStatus");
} }
void GMainWindow::ControllerSelectorReconfigureControllers( void GMainWindow::ControllerSelectorReconfigureControllers(
const Core::Frontend::ControllerParameters& parameters) { const Core::Frontend::ControllerParameters& parameters) {
QtControllerSelectorDialog dialog(this, parameters, input_subsystem.get(), system); QtControllerSelectorDialog dialog(this, parameters, input_subsystem.get(), *system);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint |
Qt::WindowTitleHint | Qt::WindowSystemMenuHint); Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
@ -421,7 +422,7 @@ void GMainWindow::ControllerSelectorReconfigureControllers(
emit ControllerSelectorReconfigureFinished(); emit ControllerSelectorReconfigureFinished();
// Don't forget to apply settings. // Don't forget to apply settings.
system.ApplySettings(); system->ApplySettings();
config->Save(); config->Save();
UpdateStatusButtons(); UpdateStatusButtons();
@ -455,7 +456,7 @@ void GMainWindow::SoftwareKeyboardInitialize(
return; return;
} }
software_keyboard = new QtSoftwareKeyboardDialog(render_window, system, is_inline, software_keyboard = new QtSoftwareKeyboardDialog(render_window, *system, is_inline,
std::move(initialize_parameters)); std::move(initialize_parameters));
if (is_inline) { if (is_inline) {
@ -567,7 +568,7 @@ void GMainWindow::WebBrowserOpenWebPage(const std::string& main_url,
return; return;
} }
QtNXWebEngineView web_browser_view(this, system, input_subsystem.get()); QtNXWebEngineView web_browser_view(this, *system, input_subsystem.get());
ui->action_Pause->setEnabled(false); ui->action_Pause->setEnabled(false);
ui->action_Restart->setEnabled(false); ui->action_Restart->setEnabled(false);
@ -699,10 +700,10 @@ void GMainWindow::InitializeWidgets() {
#ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING #ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING
ui->action_Report_Compatibility->setVisible(true); ui->action_Report_Compatibility->setVisible(true);
#endif #endif
render_window = new GRenderWindow(this, emu_thread.get(), input_subsystem, system); render_window = new GRenderWindow(this, emu_thread.get(), input_subsystem, *system);
render_window->hide(); render_window->hide();
game_list = new GameList(vfs, provider.get(), system, this); game_list = new GameList(vfs, provider.get(), *system, this);
ui->horizontalLayout->addWidget(game_list); ui->horizontalLayout->addWidget(game_list);
game_list_placeholder = new GameListPlaceholder(this); game_list_placeholder = new GameListPlaceholder(this);
@ -768,14 +769,14 @@ void GMainWindow::InitializeWidgets() {
tr("Handheld controller can't be used on docked mode. Pro " tr("Handheld controller can't be used on docked mode. Pro "
"controller will be selected.")); "controller will be selected."));
controller_type = Settings::ControllerType::ProController; controller_type = Settings::ControllerType::ProController;
ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), system); ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), *system);
configure_dialog.ApplyConfiguration(); configure_dialog.ApplyConfiguration();
controller_dialog->refreshConfiguration(); controller_dialog->refreshConfiguration();
} }
Settings::values.use_docked_mode.SetValue(!is_docked); Settings::values.use_docked_mode.SetValue(!is_docked);
dock_status_button->setChecked(!is_docked); dock_status_button->setChecked(!is_docked);
OnDockedModeChanged(is_docked, !is_docked, system); OnDockedModeChanged(is_docked, !is_docked, *system);
}); });
dock_status_button->setText(tr("DOCK")); dock_status_button->setText(tr("DOCK"));
dock_status_button->setCheckable(true); dock_status_button->setCheckable(true);
@ -799,7 +800,7 @@ void GMainWindow::InitializeWidgets() {
} }
} }
system.ApplySettings(); system->ApplySettings();
UpdateGPUAccuracyButton(); UpdateGPUAccuracyButton();
}); });
UpdateGPUAccuracyButton(); UpdateGPUAccuracyButton();
@ -827,7 +828,7 @@ void GMainWindow::InitializeWidgets() {
Settings::values.renderer_backend.SetValue(Settings::RendererBackend::OpenGL); Settings::values.renderer_backend.SetValue(Settings::RendererBackend::OpenGL);
} }
system.ApplySettings(); system->ApplySettings();
}); });
statusBar()->insertPermanentWidget(0, renderer_status_button); statusBar()->insertPermanentWidget(0, renderer_status_button);
@ -844,7 +845,7 @@ void GMainWindow::InitializeDebugWidgets() {
debug_menu->addAction(microProfileDialog->toggleViewAction()); debug_menu->addAction(microProfileDialog->toggleViewAction());
#endif #endif
waitTreeWidget = new WaitTreeWidget(system, this); waitTreeWidget = new WaitTreeWidget(*system, this);
addDockWidget(Qt::LeftDockWidgetArea, waitTreeWidget); addDockWidget(Qt::LeftDockWidgetArea, waitTreeWidget);
waitTreeWidget->hide(); waitTreeWidget->hide();
debug_menu->addAction(waitTreeWidget->toggleViewAction()); debug_menu->addAction(waitTreeWidget->toggleViewAction());
@ -947,7 +948,7 @@ void GMainWindow::InitializeHotkeys() {
}); });
connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Restart Emulation"), this), connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Restart Emulation"), this),
&QShortcut::activated, this, [this] { &QShortcut::activated, this, [this] {
if (!system.IsPoweredOn()) { if (!system->IsPoweredOn()) {
return; return;
} }
BootGame(game_path); BootGame(game_path);
@ -1003,7 +1004,7 @@ void GMainWindow::InitializeHotkeys() {
Settings::values.use_docked_mode.SetValue( Settings::values.use_docked_mode.SetValue(
!Settings::values.use_docked_mode.GetValue()); !Settings::values.use_docked_mode.GetValue());
OnDockedModeChanged(!Settings::values.use_docked_mode.GetValue(), OnDockedModeChanged(!Settings::values.use_docked_mode.GetValue(),
Settings::values.use_docked_mode.GetValue(), system); Settings::values.use_docked_mode.GetValue(), *system);
dock_status_button->setChecked(Settings::values.use_docked_mode.GetValue()); dock_status_button->setChecked(Settings::values.use_docked_mode.GetValue());
}); });
connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Mute Audio"), this), connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Mute Audio"), this),
@ -1240,9 +1241,9 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p
return false; return false;
} }
system.SetFilesystem(vfs); system->SetFilesystem(vfs);
system.SetAppletFrontendSet({ system->SetAppletFrontendSet({
std::make_unique<QtControllerSelector>(*this), // Controller Selector std::make_unique<QtControllerSelector>(*this), // Controller Selector
std::make_unique<QtErrorDisplay>(*this), // Error Display std::make_unique<QtErrorDisplay>(*this), // Error Display
nullptr, // Parental Controls nullptr, // Parental Controls
@ -1252,14 +1253,14 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p
std::make_unique<QtWebBrowser>(*this), // Web Browser std::make_unique<QtWebBrowser>(*this), // Web Browser
}); });
const Core::System::ResultStatus result{ const Core::SystemResultStatus result{
system.Load(*render_window, filename.toStdString(), program_id, program_index)}; system->Load(*render_window, filename.toStdString(), program_id, program_index)};
const auto drd_callout = (UISettings::values.callout_flags.GetValue() & const auto drd_callout = (UISettings::values.callout_flags.GetValue() &
static_cast<u32>(CalloutFlag::DRDDeprecation)) == 0; static_cast<u32>(CalloutFlag::DRDDeprecation)) == 0;
if (result == Core::System::ResultStatus::Success && if (result == Core::SystemResultStatus::Success &&
system.GetAppLoader().GetFileType() == Loader::FileType::DeconstructedRomDirectory && system->GetAppLoader().GetFileType() == Loader::FileType::DeconstructedRomDirectory &&
drd_callout) { drd_callout) {
UISettings::values.callout_flags = UISettings::values.callout_flags.GetValue() | UISettings::values.callout_flags = UISettings::values.callout_flags.GetValue() |
static_cast<u32>(CalloutFlag::DRDDeprecation); static_cast<u32>(CalloutFlag::DRDDeprecation);
@ -1273,14 +1274,14 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p
"wiki</a>. This message will not be shown again.")); "wiki</a>. This message will not be shown again."));
} }
if (result != Core::System::ResultStatus::Success) { if (result != Core::SystemResultStatus::Success) {
switch (result) { switch (result) {
case Core::System::ResultStatus::ErrorGetLoader: case Core::SystemResultStatus::ErrorGetLoader:
LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filename.toStdString()); LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filename.toStdString());
QMessageBox::critical(this, tr("Error while loading ROM!"), QMessageBox::critical(this, tr("Error while loading ROM!"),
tr("The ROM format is not supported.")); tr("The ROM format is not supported."));
break; break;
case Core::System::ResultStatus::ErrorVideoCore: case Core::SystemResultStatus::ErrorVideoCore:
QMessageBox::critical( QMessageBox::critical(
this, tr("An error occurred initializing the video core."), this, tr("An error occurred initializing the video core."),
tr("yuzu has encountered an error while running the video core, please see the " tr("yuzu has encountered an error while running the video core, please see the "
@ -1294,8 +1295,8 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p
break; break;
default: default:
if (result > Core::System::ResultStatus::ErrorLoader) { if (result > Core::SystemResultStatus::ErrorLoader) {
const u16 loader_id = static_cast<u16>(Core::System::ResultStatus::ErrorLoader); const u16 loader_id = static_cast<u16>(Core::SystemResultStatus::ErrorLoader);
const u16 error_id = static_cast<u16>(result) - loader_id; const u16 error_id = static_cast<u16>(result) - loader_id;
const std::string error_code = fmt::format("({:04X}-{:04X})", loader_id, error_id); const std::string error_code = fmt::format("({:04X}-{:04X})", loader_id, error_id);
LOG_CRITICAL(Frontend, "Failed to load ROM! {}", error_code); LOG_CRITICAL(Frontend, "Failed to load ROM! {}", error_code);
@ -1323,7 +1324,7 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p
} }
game_path = filename; game_path = filename;
system.TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend", "Qt"); system->TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend", "Qt");
return true; return true;
} }
@ -1350,7 +1351,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
last_filename_booted = filename; last_filename_booted = filename;
const auto v_file = Core::GetGameFileFromPath(vfs, filename.toUtf8().constData()); const auto v_file = Core::GetGameFileFromPath(vfs, filename.toUtf8().constData());
const auto loader = Loader::GetLoader(system, v_file, program_id, program_index); const auto loader = Loader::GetLoader(*system, v_file, program_id, program_index);
if (loader != nullptr && loader->ReadProgramId(title_id) == Loader::ResultStatus::Success && if (loader != nullptr && loader->ReadProgramId(title_id) == Loader::ResultStatus::Success &&
type == StartGameType::Normal) { type == StartGameType::Normal) {
@ -1359,7 +1360,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
const auto config_file_name = title_id == 0 const auto config_file_name = title_id == 0
? Common::FS::PathToUTF8String(file_path.filename()) ? Common::FS::PathToUTF8String(file_path.filename())
: fmt::format("{:016X}", title_id); : fmt::format("{:016X}", title_id);
Config per_game_config(system, config_file_name, Config::ConfigType::PerGameConfig); Config per_game_config(*system, config_file_name, Config::ConfigType::PerGameConfig);
} }
ConfigureVibration::SetAllVibrationDevices(); ConfigureVibration::SetAllVibrationDevices();
@ -1382,16 +1383,16 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
return; return;
// Create and start the emulation thread // Create and start the emulation thread
emu_thread = std::make_unique<EmuThread>(system); emu_thread = std::make_unique<EmuThread>(*system);
emit EmulationStarting(emu_thread.get()); emit EmulationStarting(emu_thread.get());
emu_thread->start(); emu_thread->start();
// Register an ExecuteProgram callback such that Core can execute a sub-program // Register an ExecuteProgram callback such that Core can execute a sub-program
system.RegisterExecuteProgramCallback( system->RegisterExecuteProgramCallback(
[this](std::size_t program_index) { render_window->ExecuteProgram(program_index); }); [this](std::size_t program_index) { render_window->ExecuteProgram(program_index); });
// Register an Exit callback such that Core can exit the currently running application. // Register an Exit callback such that Core can exit the currently running application.
system.RegisterExitCallback([this]() { render_window->Exit(); }); system->RegisterExitCallback([this]() { render_window->Exit(); });
connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame); connect(render_window, &GRenderWindow::Closed, this, &GMainWindow::OnStopGame);
connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity); connect(render_window, &GRenderWindow::MouseActivity, this, &GMainWindow::OnMouseActivity);
@ -1425,11 +1426,11 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
std::string title_name; std::string title_name;
std::string title_version; std::string title_version;
const auto res = system.GetGameName(title_name); const auto res = system->GetGameName(title_name);
const auto metadata = [this, title_id] { const auto metadata = [this, title_id] {
const FileSys::PatchManager pm(title_id, system.GetFileSystemController(), const FileSys::PatchManager pm(title_id, system->GetFileSystemController(),
system.GetContentProvider()); system->GetContentProvider());
return pm.GetControlMetadata(); return pm.GetControlMetadata();
}(); }();
if (metadata.first != nullptr) { if (metadata.first != nullptr) {
@ -1440,16 +1441,16 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
title_name = Common::FS::PathToUTF8String( title_name = Common::FS::PathToUTF8String(
std::filesystem::path{filename.toStdU16String()}.filename()); std::filesystem::path{filename.toStdU16String()}.filename());
} }
const bool is_64bit = system.Kernel().CurrentProcess()->Is64BitProcess(); const bool is_64bit = system->Kernel().CurrentProcess()->Is64BitProcess();
const auto instruction_set_suffix = is_64bit ? tr("(64-bit)") : tr("(32-bit)"); const auto instruction_set_suffix = is_64bit ? tr("(64-bit)") : tr("(32-bit)");
title_name = tr("%1 %2", "%1 is the title name. %2 indicates if the title is 64-bit or 32-bit") title_name = tr("%1 %2", "%1 is the title name. %2 indicates if the title is 64-bit or 32-bit")
.arg(QString::fromStdString(title_name), instruction_set_suffix) .arg(QString::fromStdString(title_name), instruction_set_suffix)
.toStdString(); .toStdString();
LOG_INFO(Frontend, "Booting game: {:016X} | {} | {}", title_id, title_name, title_version); LOG_INFO(Frontend, "Booting game: {:016X} | {} | {}", title_id, title_name, title_version);
const auto gpu_vendor = system.GPU().Renderer().GetDeviceVendor(); const auto gpu_vendor = system->GPU().Renderer().GetDeviceVendor();
UpdateWindowTitle(title_name, title_version, gpu_vendor); UpdateWindowTitle(title_name, title_version, gpu_vendor);
loading_screen->Prepare(system.GetAppLoader()); loading_screen->Prepare(system->GetAppLoader());
loading_screen->show(); loading_screen->show();
emulation_running = true; emulation_running = true;
@ -1568,15 +1569,15 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
QString open_target; QString open_target;
const auto [user_save_size, device_save_size] = [this, &game_path, &program_id] { const auto [user_save_size, device_save_size] = [this, &game_path, &program_id] {
const FileSys::PatchManager pm{program_id, system.GetFileSystemController(), const FileSys::PatchManager pm{program_id, system->GetFileSystemController(),
system.GetContentProvider()}; system->GetContentProvider()};
const auto control = pm.GetControlMetadata().first; const auto control = pm.GetControlMetadata().first;
if (control != nullptr) { if (control != nullptr) {
return std::make_pair(control->GetDefaultNormalSaveSize(), return std::make_pair(control->GetDefaultNormalSaveSize(),
control->GetDeviceSaveDataSize()); control->GetDeviceSaveDataSize());
} else { } else {
const auto file = Core::GetGameFileFromPath(vfs, game_path); const auto file = Core::GetGameFileFromPath(vfs, game_path);
const auto loader = Loader::GetLoader(system, file); const auto loader = Loader::GetLoader(*system, file);
FileSys::NACP nacp{}; FileSys::NACP nacp{};
loader->ReadControlData(nacp); loader->ReadControlData(nacp);
@ -1619,14 +1620,14 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
ASSERT(user_id); ASSERT(user_id);
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(
system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData, *system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
program_id, user_id->uuid, 0); program_id, user_id->uuid, 0);
path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path); path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path);
} else { } else {
// Device save data // Device save data
const auto device_save_data_path = FileSys::SaveDataFactory::GetFullPath( const auto device_save_data_path = FileSys::SaveDataFactory::GetFullPath(
system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData, *system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData,
program_id, {}, 0); program_id, {}, 0);
path = Common::FS::ConcatPathSafe(nand_dir, device_save_data_path); path = Common::FS::ConcatPathSafe(nand_dir, device_save_data_path);
@ -1753,7 +1754,7 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
} }
void GMainWindow::RemoveBaseContent(u64 program_id, const QString& entry_type) { void GMainWindow::RemoveBaseContent(u64 program_id, const QString& entry_type) {
const auto& fs_controller = system.GetFileSystemController(); const auto& fs_controller = system->GetFileSystemController();
const auto res = fs_controller.GetUserNANDContents()->RemoveExistingEntry(program_id) || const auto res = fs_controller.GetUserNANDContents()->RemoveExistingEntry(program_id) ||
fs_controller.GetSDMCContents()->RemoveExistingEntry(program_id); fs_controller.GetSDMCContents()->RemoveExistingEntry(program_id);
@ -1769,7 +1770,7 @@ void GMainWindow::RemoveBaseContent(u64 program_id, const QString& entry_type) {
void GMainWindow::RemoveUpdateContent(u64 program_id, const QString& entry_type) { void GMainWindow::RemoveUpdateContent(u64 program_id, const QString& entry_type) {
const auto update_id = program_id | 0x800; const auto update_id = program_id | 0x800;
const auto& fs_controller = system.GetFileSystemController(); const auto& fs_controller = system->GetFileSystemController();
const auto res = fs_controller.GetUserNANDContents()->RemoveExistingEntry(update_id) || const auto res = fs_controller.GetUserNANDContents()->RemoveExistingEntry(update_id) ||
fs_controller.GetSDMCContents()->RemoveExistingEntry(update_id); fs_controller.GetSDMCContents()->RemoveExistingEntry(update_id);
@ -1784,8 +1785,8 @@ void GMainWindow::RemoveUpdateContent(u64 program_id, const QString& entry_type)
void GMainWindow::RemoveAddOnContent(u64 program_id, const QString& entry_type) { void GMainWindow::RemoveAddOnContent(u64 program_id, const QString& entry_type) {
u32 count{}; u32 count{};
const auto& fs_controller = system.GetFileSystemController(); const auto& fs_controller = system->GetFileSystemController();
const auto dlc_entries = system.GetContentProvider().ListEntriesFilter( const auto dlc_entries = system->GetContentProvider().ListEntriesFilter(
FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); FileSys::TitleType::AOC, FileSys::ContentRecordType::Data);
for (const auto& entry : dlc_entries) { for (const auto& entry : dlc_entries) {
@ -1923,7 +1924,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
"cancelled the operation.")); "cancelled the operation."));
}; };
const auto loader = Loader::GetLoader(system, vfs->OpenFile(game_path, FileSys::Mode::Read)); const auto loader = Loader::GetLoader(*system, vfs->OpenFile(game_path, FileSys::Mode::Read));
if (loader == nullptr) { if (loader == nullptr) {
failed(); failed();
return; return;
@ -1935,7 +1936,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
return; return;
} }
const auto& installed = system.GetContentProvider(); const auto& installed = system->GetContentProvider();
const auto romfs_title_id = SelectRomFSDumpTarget(installed, program_id); const auto romfs_title_id = SelectRomFSDumpTarget(installed, program_id);
if (!romfs_title_id) { if (!romfs_title_id) {
@ -1955,7 +1956,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
if (*romfs_title_id == program_id) { if (*romfs_title_id == program_id) {
const u64 ivfc_offset = loader->ReadRomFSIVFCOffset(); const u64 ivfc_offset = loader->ReadRomFSIVFCOffset();
const FileSys::PatchManager pm{program_id, system.GetFileSystemController(), installed}; const FileSys::PatchManager pm{program_id, system->GetFileSystemController(), installed};
romfs = romfs =
pm.PatchRomFS(file, ivfc_offset, FileSys::ContentRecordType::Program, nullptr, false); pm.PatchRomFS(file, ivfc_offset, FileSys::ContentRecordType::Program, nullptr, false);
} else { } else {
@ -2090,7 +2091,7 @@ void GMainWindow::OnGameListShowList(bool show) {
void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) { void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) {
u64 title_id{}; u64 title_id{};
const auto v_file = Core::GetGameFileFromPath(vfs, file); const auto v_file = Core::GetGameFileFromPath(vfs, file);
const auto loader = Loader::GetLoader(system, v_file); const auto loader = Loader::GetLoader(*system, v_file);
if (loader == nullptr || loader->ReadProgramId(title_id) != Loader::ResultStatus::Success) { if (loader == nullptr || loader->ReadProgramId(title_id) != Loader::ResultStatus::Success) {
QMessageBox::information(this, tr("Properties"), QMessageBox::information(this, tr("Properties"),
@ -2304,7 +2305,7 @@ InstallResult GMainWindow::InstallNSPXCI(const QString& filename) {
if (nsp->GetStatus() != Loader::ResultStatus::Success) { if (nsp->GetStatus() != Loader::ResultStatus::Success) {
return InstallResult::Failure; return InstallResult::Failure;
} }
const auto res = system.GetFileSystemController().GetUserNANDContents()->InstallEntry( const auto res = system->GetFileSystemController().GetUserNANDContents()->InstallEntry(
*nsp, true, qt_raw_copy); *nsp, true, qt_raw_copy);
switch (res) { switch (res) {
case FileSys::InstallResult::Success: case FileSys::InstallResult::Success:
@ -2384,7 +2385,7 @@ InstallResult GMainWindow::InstallNCA(const QString& filename) {
} }
const bool is_application = index >= static_cast<s32>(FileSys::TitleType::Application); const bool is_application = index >= static_cast<s32>(FileSys::TitleType::Application);
const auto& fs_controller = system.GetFileSystemController(); const auto& fs_controller = system->GetFileSystemController();
auto* registered_cache = is_application ? fs_controller.GetUserNANDContents() auto* registered_cache = is_application ? fs_controller.GetUserNANDContents()
: fs_controller.GetSystemNANDContents(); : fs_controller.GetSystemNANDContents();
@ -2449,13 +2450,13 @@ void GMainWindow::OnPauseGame() {
} }
void GMainWindow::OnStopGame() { void GMainWindow::OnStopGame() {
if (system.GetExitLock() && !ConfirmForceLockedExit()) { if (system->GetExitLock() && !ConfirmForceLockedExit()) {
return; return;
} }
ShutdownGame(); ShutdownGame();
Settings::RestoreGlobalState(system.IsPoweredOn()); Settings::RestoreGlobalState(system->IsPoweredOn());
UpdateStatusButtons(); UpdateStatusButtons();
} }
@ -2473,7 +2474,7 @@ void GMainWindow::OnExit() {
} }
void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) { void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) {
OverlayDialog dialog(render_window, system, error_code, error_text, QString{}, tr("OK"), OverlayDialog dialog(render_window, *system, error_code, error_text, QString{}, tr("OK"),
Qt::AlignLeft | Qt::AlignVCenter); Qt::AlignLeft | Qt::AlignVCenter);
dialog.exec(); dialog.exec();
@ -2483,7 +2484,7 @@ void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_tex
void GMainWindow::OnMenuReportCompatibility() { void GMainWindow::OnMenuReportCompatibility() {
if (!Settings::values.yuzu_token.GetValue().empty() && if (!Settings::values.yuzu_token.GetValue().empty() &&
!Settings::values.yuzu_username.GetValue().empty()) { !Settings::values.yuzu_username.GetValue().empty()) {
CompatDB compatdb{system.TelemetrySession(), this}; CompatDB compatdb{system->TelemetrySession(), this};
compatdb.exec(); compatdb.exec();
} else { } else {
QMessageBox::critical( QMessageBox::critical(
@ -2647,7 +2648,7 @@ void GMainWindow::OnConfigure() {
const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue(); const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue();
Settings::SetConfiguringGlobal(true); Settings::SetConfiguringGlobal(true);
ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), system); ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), *system);
connect(&configure_dialog, &ConfigureDialog::LanguageChanged, this, connect(&configure_dialog, &ConfigureDialog::LanguageChanged, this,
&GMainWindow::OnLanguageChanged); &GMainWindow::OnLanguageChanged);
@ -2683,7 +2684,7 @@ void GMainWindow::OnConfigure() {
Settings::values.disabled_addons.clear(); Settings::values.disabled_addons.clear();
config = std::make_unique<Config>(system); config = std::make_unique<Config>(*system);
UISettings::values.reset_to_defaults = false; UISettings::values.reset_to_defaults = false;
UISettings::values.game_dirs = std::move(old_game_dirs); UISettings::values.game_dirs = std::move(old_game_dirs);
@ -2732,12 +2733,11 @@ void GMainWindow::OnConfigure() {
} }
void GMainWindow::OnConfigureTas() { void GMainWindow::OnConfigureTas() {
const auto& system = Core::System::GetInstance();
ConfigureTasDialog dialog(this); ConfigureTasDialog dialog(this);
const auto result = dialog.exec(); const auto result = dialog.exec();
if (result != QDialog::Accepted && !UISettings::values.configuration_applied) { if (result != QDialog::Accepted && !UISettings::values.configuration_applied) {
Settings::RestoreGlobalState(system.IsPoweredOn()); Settings::RestoreGlobalState(system->IsPoweredOn());
return; return;
} else if (result == QDialog::Accepted) { } else if (result == QDialog::Accepted) {
dialog.ApplyConfiguration(); dialog.ApplyConfiguration();
@ -2745,7 +2745,7 @@ void GMainWindow::OnConfigureTas() {
} }
void GMainWindow::OnConfigurePerGame() { void GMainWindow::OnConfigurePerGame() {
const u64 title_id = system.CurrentProcess()->GetTitleID(); const u64 title_id = system->CurrentProcess()->GetTitleID();
OpenPerGameConfiguration(title_id, game_path.toStdString()); OpenPerGameConfiguration(title_id, game_path.toStdString());
} }
@ -2753,12 +2753,12 @@ void GMainWindow::OpenPerGameConfiguration(u64 title_id, const std::string& file
const auto v_file = Core::GetGameFileFromPath(vfs, file_name); const auto v_file = Core::GetGameFileFromPath(vfs, file_name);
Settings::SetConfiguringGlobal(false); Settings::SetConfiguringGlobal(false);
ConfigurePerGame dialog(this, title_id, file_name, system); ConfigurePerGame dialog(this, title_id, file_name, *system);
dialog.LoadFromFile(v_file); dialog.LoadFromFile(v_file);
const auto result = dialog.exec(); const auto result = dialog.exec();
if (result != QDialog::Accepted && !UISettings::values.configuration_applied) { if (result != QDialog::Accepted && !UISettings::values.configuration_applied) {
Settings::RestoreGlobalState(system.IsPoweredOn()); Settings::RestoreGlobalState(system->IsPoweredOn());
return; return;
} else if (result == QDialog::Accepted) { } else if (result == QDialog::Accepted) {
dialog.ApplyConfiguration(); dialog.ApplyConfiguration();
@ -2770,7 +2770,7 @@ void GMainWindow::OpenPerGameConfiguration(u64 title_id, const std::string& file
} }
// Do not cause the global config to write local settings into the config file // Do not cause the global config to write local settings into the config file
const bool is_powered_on = system.IsPoweredOn(); const bool is_powered_on = system->IsPoweredOn();
Settings::RestoreGlobalState(is_powered_on); Settings::RestoreGlobalState(is_powered_on);
UISettings::values.configuration_applied = false; UISettings::values.configuration_applied = false;
@ -2793,7 +2793,7 @@ void GMainWindow::OnLoadAmiibo() {
} }
void GMainWindow::LoadAmiibo(const QString& filename) { void GMainWindow::LoadAmiibo(const QString& filename) {
Service::SM::ServiceManager& sm = system.ServiceManager(); Service::SM::ServiceManager& sm = system->ServiceManager();
auto nfc = sm.GetService<Service::NFP::Module::Interface>("nfp:user"); auto nfc = sm.GetService<Service::NFP::Module::Interface>("nfp:user");
if (nfc == nullptr) { if (nfc == nullptr) {
return; return;
@ -2844,7 +2844,7 @@ void GMainWindow::OnToggleFilterBar() {
} }
void GMainWindow::OnCaptureScreenshot() { void GMainWindow::OnCaptureScreenshot() {
const u64 title_id = system.CurrentProcess()->GetTitleID(); const u64 title_id = system->CurrentProcess()->GetTitleID();
const auto screenshot_path = const auto screenshot_path =
QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir)); QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir));
const auto date = const auto date =
@ -2950,8 +2950,8 @@ void GMainWindow::UpdateStatusBar() {
tas_label->clear(); tas_label->clear();
} }
auto results = system.GetAndResetPerfStats(); auto results = system->GetAndResetPerfStats();
auto& shader_notify = system.GPU().ShaderNotify(); auto& shader_notify = system->GPU().ShaderNotify();
const int shaders_building = shader_notify.ShadersBuilding(); const int shaders_building = shader_notify.ShadersBuilding();
if (shaders_building > 0) { if (shaders_building > 0) {
@ -3052,7 +3052,7 @@ void GMainWindow::OnMouseActivity() {
} }
} }
void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string details) { void GMainWindow::OnCoreError(Core::SystemResultStatus result, std::string details) {
QMessageBox::StandardButton answer; QMessageBox::StandardButton answer;
QString status_message; QString status_message;
const QString common_message = const QString common_message =
@ -3067,7 +3067,7 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string det
"back to the game list? Continuing emulation may result in crashes, corrupted save " "back to the game list? Continuing emulation may result in crashes, corrupted save "
"data, or other bugs."); "data, or other bugs.");
switch (result) { switch (result) {
case Core::System::ResultStatus::ErrorSystemFiles: { case Core::SystemResultStatus::ErrorSystemFiles: {
QString message; QString message;
if (details.empty()) { if (details.empty()) {
message = message =
@ -3083,7 +3083,7 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string det
break; break;
} }
case Core::System::ResultStatus::ErrorSharedFont: { case Core::SystemResultStatus::ErrorSharedFont: {
const QString message = const QString message =
tr("yuzu was unable to locate the Switch shared fonts. %1").arg(common_message); tr("yuzu was unable to locate the Switch shared fonts. %1").arg(common_message);
answer = QMessageBox::question(this, tr("Shared Fonts Not Found"), message, answer = QMessageBox::question(this, tr("Shared Fonts Not Found"), message,
@ -3112,7 +3112,7 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string det
if (emu_thread) { if (emu_thread) {
ShutdownGame(); ShutdownGame();
Settings::RestoreGlobalState(system.IsPoweredOn()); Settings::RestoreGlobalState(system->IsPoweredOn());
UpdateStatusButtons(); UpdateStatusButtons();
} }
} else { } else {
@ -3154,8 +3154,8 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) {
const auto function = [this, &keys, &pdm] { const auto function = [this, &keys, &pdm] {
keys.PopulateFromPartitionData(pdm); keys.PopulateFromPartitionData(pdm);
system.GetFileSystemController().CreateFactories(*vfs); system->GetFileSystemController().CreateFactories(*vfs);
keys.DeriveETicket(pdm, system.GetContentProvider()); keys.DeriveETicket(pdm, system->GetContentProvider());
}; };
QString errors; QString errors;
@ -3197,7 +3197,7 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) {
prog.close(); prog.close();
} }
system.GetFileSystemController().CreateFactories(*vfs); system->GetFileSystemController().CreateFactories(*vfs);
if (behavior == ReinitializeKeyBehavior::Warning) { if (behavior == ReinitializeKeyBehavior::Warning) {
game_list->PopulateAsync(UISettings::values.game_dirs); game_list->PopulateAsync(UISettings::values.game_dirs);
@ -3265,7 +3265,7 @@ void GMainWindow::closeEvent(QCloseEvent* event) {
if (emu_thread != nullptr) { if (emu_thread != nullptr) {
ShutdownGame(); ShutdownGame();
Settings::RestoreGlobalState(system.IsPoweredOn()); Settings::RestoreGlobalState(system->IsPoweredOn());
UpdateStatusButtons(); UpdateStatusButtons();
} }
@ -3340,7 +3340,7 @@ bool GMainWindow::ConfirmForceLockedExit() {
} }
void GMainWindow::RequestGameExit() { void GMainWindow::RequestGameExit() {
auto& sm{system.ServiceManager()}; auto& sm{system->ServiceManager()};
auto applet_oe = sm.GetService<Service::AM::AppletOE>("appletOE"); auto applet_oe = sm.GetService<Service::AM::AppletOE>("appletOE");
auto applet_ae = sm.GetService<Service::AM::AppletAE>("appletAE"); auto applet_ae = sm.GetService<Service::AM::AppletAE>("appletAE");
bool has_signalled = false; bool has_signalled = false;
@ -3434,7 +3434,7 @@ void GMainWindow::OnLanguageChanged(const QString& locale) {
void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) { void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
#ifdef USE_DISCORD_PRESENCE #ifdef USE_DISCORD_PRESENCE
if (state) { if (state) {
discord_rpc = std::make_unique<DiscordRPC::DiscordImpl>(system); discord_rpc = std::make_unique<DiscordRPC::DiscordImpl>(*system);
} else { } else {
discord_rpc = std::make_unique<DiscordRPC::NullImpl>(); discord_rpc = std::make_unique<DiscordRPC::NullImpl>();
} }
@ -3488,8 +3488,7 @@ int main(int argc, char* argv[]) {
// generating shaders // generating shaders
setlocale(LC_ALL, "C"); setlocale(LC_ALL, "C");
Core::System::InitializeGlobalInstance(); GMainWindow main_window{};
GMainWindow main_window{Core::System::GetInstance()};
// After settings have been loaded by GMainWindow, apply the filter // After settings have been loaded by GMainWindow, apply the filter
main_window.show(); main_window.show();

View file

@ -13,7 +13,6 @@
#include <QTranslator> #include <QTranslator>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/core.h"
#include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/acc/profile_manager.h"
#include "yuzu/compatibility_list.h" #include "yuzu/compatibility_list.h"
#include "yuzu/hotkeys.h" #include "yuzu/hotkeys.h"
@ -44,6 +43,11 @@ enum class StartGameType {
Global, // Only uses global configuration Global, // Only uses global configuration
}; };
namespace Core {
enum class SystemResultStatus : u32;
class System;
} // namespace Core
namespace Core::Frontend { namespace Core::Frontend {
struct ControllerParameters; struct ControllerParameters;
struct InlineAppearParameters; struct InlineAppearParameters;
@ -110,7 +114,7 @@ class GMainWindow : public QMainWindow {
public: public:
void filterBarSetChecked(bool state); void filterBarSetChecked(bool state);
void UpdateUITheme(); void UpdateUITheme();
GMainWindow(Core::System& system_); explicit GMainWindow();
~GMainWindow() override; ~GMainWindow() override;
bool DropAction(QDropEvent* event); bool DropAction(QDropEvent* event);
@ -280,7 +284,7 @@ private slots:
void ResetWindowSize900(); void ResetWindowSize900();
void ResetWindowSize1080(); void ResetWindowSize1080();
void OnCaptureScreenshot(); void OnCaptureScreenshot();
void OnCoreError(Core::System::ResultStatus, std::string); void OnCoreError(Core::SystemResultStatus, std::string);
void OnReinitializeKeys(ReinitializeKeyBehavior behavior); void OnReinitializeKeys(ReinitializeKeyBehavior behavior);
void OnLanguageChanged(const QString& locale); void OnLanguageChanged(const QString& locale);
void OnMouseActivity(); void OnMouseActivity();
@ -311,11 +315,10 @@ private:
std::unique_ptr<Ui::MainWindow> ui; std::unique_ptr<Ui::MainWindow> ui;
std::unique_ptr<Core::System> system;
std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc; std::unique_ptr<DiscordRPC::DiscordInterface> discord_rpc;
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem; std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
Core::System& system;
GRenderWindow* render_window; GRenderWindow* render_window;
GameList* game_list; GameList* game_list;
LoadingScreen* loading_screen; LoadingScreen* loading_screen;

View file

@ -146,9 +146,8 @@ int main(int argc, char** argv) {
return -1; return -1;
} }
Core::System::InitializeGlobalInstance(); Core::System system{};
auto& system{Core::System::GetInstance()}; InputCommon::InputSubsystem input_subsystem{};
InputCommon::InputSubsystem input_subsystem;
// Apply the command line arguments // Apply the command line arguments
system.ApplySettings(); system.ApplySettings();
@ -167,27 +166,27 @@ int main(int argc, char** argv) {
system.SetFilesystem(std::make_shared<FileSys::RealVfsFilesystem>()); system.SetFilesystem(std::make_shared<FileSys::RealVfsFilesystem>());
system.GetFileSystemController().CreateFactories(*system.GetFilesystem()); system.GetFileSystemController().CreateFactories(*system.GetFilesystem());
const Core::System::ResultStatus load_result{system.Load(*emu_window, filepath)}; const Core::SystemResultStatus load_result{system.Load(*emu_window, filepath)};
switch (load_result) { switch (load_result) {
case Core::System::ResultStatus::ErrorGetLoader: case Core::SystemResultStatus::ErrorGetLoader:
LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filepath); LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filepath);
return -1; return -1;
case Core::System::ResultStatus::ErrorLoader: case Core::SystemResultStatus::ErrorLoader:
LOG_CRITICAL(Frontend, "Failed to load ROM!"); LOG_CRITICAL(Frontend, "Failed to load ROM!");
return -1; return -1;
case Core::System::ResultStatus::ErrorNotInitialized: case Core::SystemResultStatus::ErrorNotInitialized:
LOG_CRITICAL(Frontend, "CPUCore not initialized"); LOG_CRITICAL(Frontend, "CPUCore not initialized");
return -1; return -1;
case Core::System::ResultStatus::ErrorVideoCore: case Core::SystemResultStatus::ErrorVideoCore:
LOG_CRITICAL(Frontend, "Failed to initialize VideoCore!"); LOG_CRITICAL(Frontend, "Failed to initialize VideoCore!");
return -1; return -1;
case Core::System::ResultStatus::Success: case Core::SystemResultStatus::Success:
break; // Expected case break; // Expected case
default: default:
if (static_cast<u32>(load_result) > if (static_cast<u32>(load_result) >
static_cast<u32>(Core::System::ResultStatus::ErrorLoader)) { static_cast<u32>(Core::SystemResultStatus::ErrorLoader)) {
const u16 loader_id = static_cast<u16>(Core::System::ResultStatus::ErrorLoader); const u16 loader_id = static_cast<u16>(Core::SystemResultStatus::ErrorLoader);
const u16 error_id = static_cast<u16>(load_result) - loader_id; const u16 error_id = static_cast<u16>(load_result) - loader_id;
LOG_CRITICAL(Frontend, LOG_CRITICAL(Frontend,
"While attempting to load the ROM requested, an error occurred. Please " "While attempting to load the ROM requested, an error occurred. Please "