From b6719094e69bba468ecbc275fd892c4d412b92a3 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 14 Oct 2021 14:21:15 -0400 Subject: core: Remove static system instance --- src/core/core.cpp | 15 +-------------- src/core/core.h | 18 ++++-------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index bb268a319..ae1d56b27 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -428,21 +428,8 @@ struct System::Impl { }; System::System() : impl{std::make_unique(*this)} {} -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(new System); -} +System::~System() = default; CpuManager& System::GetCpuManager() { return impl->cpu_manager; diff --git a/src/core/core.h b/src/core/core.h index a796472b2..cae578c69 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -108,22 +108,16 @@ class System { public: using CurrentBuildProcessID = std::array; + explicit System(); + + ~System(); + 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. enum class ResultStatus : u32 { Success, ///< Succeeded @@ -403,12 +397,8 @@ public: void ApplySettings(); private: - System(); - struct Impl; std::unique_ptr impl; - - inline static std::unique_ptr s_instance{}; }; } // namespace Core -- cgit v1.2.3 From 218ebc1fe869fdfcb9bc2aafb175f187a3401360 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 14 Oct 2021 14:31:28 -0400 Subject: yuzu_cmd: Remove remaining static system instances --- src/yuzu_cmd/yuzu.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index ba2c993ba..5c36a21a2 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -146,9 +146,8 @@ int main(int argc, char** argv) { return -1; } - Core::System::InitializeGlobalInstance(); - auto& system{Core::System::GetInstance()}; - InputCommon::InputSubsystem input_subsystem; + Core::System system{}; + InputCommon::InputSubsystem input_subsystem{}; // Apply the command line arguments system.ApplySettings(); -- cgit v1.2.3 From 17763a44d5426f7a3e52d6d4aebc26afb1d0ce65 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 14 Oct 2021 18:14:40 -0400 Subject: core: Move ResultStatus outside of System Allows it to be a forward declaration in other header files. --- src/core/core.cpp | 49 ++++++++++++++++++++++++------------------------ src/core/core.h | 39 +++++++++++++++++++------------------- src/yuzu/bootmanager.cpp | 6 +++--- src/yuzu/bootmanager.h | 2 +- src/yuzu/main.cpp | 22 +++++++++++----------- src/yuzu/main.h | 2 +- src/yuzu_cmd/yuzu.cpp | 16 ++++++++-------- 7 files changed, 69 insertions(+), 67 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index ae1d56b27..3532839df 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -139,8 +139,8 @@ struct System::Impl { : kernel{system}, fs_controller{system}, memory{system}, cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system} {} - ResultStatus Run() { - status = ResultStatus::Success; + SystemResultStatus Run() { + status = SystemResultStatus::Success; kernel.Suspend(false); core_timing.SyncPause(false); @@ -149,8 +149,8 @@ struct System::Impl { return status; } - ResultStatus Pause() { - status = ResultStatus::Success; + SystemResultStatus Pause() { + status = SystemResultStatus::Success; core_timing.SyncPause(true); kernel.Suspend(true); @@ -159,7 +159,7 @@ struct System::Impl { return status; } - ResultStatus Init(System& system, Frontend::EmuWindow& emu_window) { + SystemResultStatus Init(System& system, Frontend::EmuWindow& emu_window) { LOG_DEBUG(Core, "initialized OK"); device_memory = std::make_unique(); @@ -197,7 +197,7 @@ struct System::Impl { gpu_core = VideoCore::CreateGPU(emu_window, system); if (!gpu_core) { - return ResultStatus::ErrorVideoCore; + return SystemResultStatus::ErrorVideoCore; } service_manager = std::make_shared(kernel); @@ -217,21 +217,22 @@ struct System::Impl { LOG_DEBUG(Core, "Initialized OK"); - return ResultStatus::Success; + return SystemResultStatus::Success; } - ResultStatus Load(System& system, Frontend::EmuWindow& emu_window, const std::string& filepath, - u64 program_id, std::size_t program_index) { + SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window, + const std::string& filepath, u64 program_id, + std::size_t program_index) { app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath), program_id, program_index); if (!app_loader) { LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); - return ResultStatus::ErrorGetLoader; + return SystemResultStatus::ErrorGetLoader; } - ResultStatus init_result{Init(system, emu_window)}; - if (init_result != ResultStatus::Success) { + SystemResultStatus init_result{Init(system, emu_window)}; + if (init_result != SystemResultStatus::Success) { LOG_CRITICAL(Core, "Failed to initialize system (Error {})!", static_cast(init_result)); Shutdown(); @@ -249,8 +250,8 @@ struct System::Impl { LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); Shutdown(); - return static_cast(static_cast(ResultStatus::ErrorLoader) + - static_cast(load_result)); + return static_cast( + static_cast(SystemResultStatus::ErrorLoader) + static_cast(load_result)); } AddGlueRegistrationForProcess(*app_loader, *main_process); kernel.MakeCurrentProcess(main_process.get()); @@ -282,7 +283,7 @@ struct System::Impl { GetAndResetPerfStats(); perf_stats->BeginSystemFrame(); - status = ResultStatus::Success; + status = SystemResultStatus::Success; return status; } @@ -355,7 +356,7 @@ struct System::Impl { 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; if (details) { status_details = details; @@ -411,7 +412,7 @@ struct System::Impl { /// Network instance Network::NetworkInstance network_instance; - ResultStatus status = ResultStatus::Success; + SystemResultStatus status = SystemResultStatus::Success; std::string status_details = ""; std::unique_ptr perf_stats; @@ -439,16 +440,16 @@ const CpuManager& System::GetCpuManager() const { return impl->cpu_manager; } -System::ResultStatus System::Run() { +SystemResultStatus System::Run() { return impl->Run(); } -System::ResultStatus System::Pause() { +SystemResultStatus System::Pause() { return impl->Pause(); } -System::ResultStatus System::SingleStep() { - return ResultStatus::Success; +SystemResultStatus System::SingleStep() { + return SystemResultStatus::Success; } void System::InvalidateCpuInstructionCaches() { @@ -463,8 +464,8 @@ void System::Shutdown() { impl->Shutdown(); } -System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath, - u64 program_id, std::size_t program_index) { +SystemResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath, + u64 program_id, std::size_t program_index) { return impl->Load(*this, emu_window, filepath, program_id, program_index); } @@ -624,7 +625,7 @@ Loader::ResultStatus System::GetGameName(std::string& out) const { 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); } diff --git a/src/core/core.h b/src/core/core.h index cae578c69..c1234ef77 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -104,6 +104,18 @@ struct PerfStatsResults; FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, const std::string& path); +/// Enumeration representing the return values of the System Initialize and Load process. +enum class SystemResultStatus : u32 { + Success, ///< Succeeded + ErrorNotInitialized, ///< Error trying to use core prior to initialization + ErrorGetLoader, ///< Error finding the correct application loader + ErrorSystemFiles, ///< Error in finding system files + ErrorSharedFont, ///< Error in finding shared font + ErrorVideoCore, ///< Error in the video core + ErrorUnknown, ///< Any other error + ErrorLoader, ///< The base for loader errors (too many to repeat) +}; + class System { public: using CurrentBuildProcessID = std::array; @@ -118,35 +130,23 @@ public: System(System&&) = delete; System& operator=(System&&) = delete; - /// Enumeration representing the return values of the System Initialize and Load process. - enum class ResultStatus : u32 { - Success, ///< Succeeded - ErrorNotInitialized, ///< Error trying to use core prior to initialization - ErrorGetLoader, ///< Error finding the correct application loader - ErrorSystemFiles, ///< Error in finding system files - ErrorSharedFont, ///< Error in finding shared font - ErrorVideoCore, ///< Error in the video core - ErrorUnknown, ///< Any other error - ErrorLoader, ///< The base for loader errors (too many to repeat) - }; - /** * Run the OS and Application * This function will start emulation and run the relevant devices */ - [[nodiscard]] ResultStatus Run(); + [[nodiscard]] SystemResultStatus Run(); /** * Pause the OS and Application * This function will pause emulation and stop the relevant devices */ - [[nodiscard]] ResultStatus Pause(); + [[nodiscard]] SystemResultStatus Pause(); /** * Step the CPU one instruction * @return Result status, indicating whether or not the operation succeeded. */ - [[nodiscard]] ResultStatus SingleStep(); + [[nodiscard]] SystemResultStatus SingleStep(); /** * Invalidate the CPU instruction caches @@ -166,10 +166,11 @@ public: * input. * @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. - * @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, - u64 program_id = 0, std::size_t program_index = 0); + [[nodiscard]] SystemResultStatus Load(Frontend::EmuWindow& emu_window, + 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 @@ -295,7 +296,7 @@ public: /// Gets the name of the current game [[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; diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index c75f5e1ee..40fd47406 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -86,15 +86,15 @@ void EmuThread::run() { } running_guard = true; - Core::System::ResultStatus result = system.Run(); - if (result != Core::System::ResultStatus::Success) { + Core::SystemResultStatus result = system.Run(); + if (result != Core::SystemResultStatus::Success) { running_guard = false; this->SetRunning(false); emit ErrorThrown(result, system.GetStatusDetails()); } running_wait.Wait(); result = system.Pause(); - if (result != Core::System::ResultStatus::Success) { + if (result != Core::SystemResultStatus::Success) { running_guard = false; this->SetRunning(false); emit ErrorThrown(result, system.GetStatusDetails()); diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 8d7ab8c2e..9fc4116e6 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h @@ -123,7 +123,7 @@ signals: */ 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); }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 00e649fd2..a381eed34 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -406,7 +406,7 @@ void GMainWindow::RegisterMetaTypes() { qRegisterMetaType("Service::AM::Applets::WebExitReason"); // Register loader types - qRegisterMetaType("Core::System::ResultStatus"); + qRegisterMetaType("Core::SystemResultStatus"); } void GMainWindow::ControllerSelectorReconfigureControllers( @@ -1252,13 +1252,13 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p std::make_unique(*this), // Web Browser }); - const Core::System::ResultStatus result{ + const Core::SystemResultStatus result{ system.Load(*render_window, filename.toStdString(), program_id, program_index)}; const auto drd_callout = (UISettings::values.callout_flags.GetValue() & static_cast(CalloutFlag::DRDDeprecation)) == 0; - if (result == Core::System::ResultStatus::Success && + if (result == Core::SystemResultStatus::Success && system.GetAppLoader().GetFileType() == Loader::FileType::DeconstructedRomDirectory && drd_callout) { UISettings::values.callout_flags = UISettings::values.callout_flags.GetValue() | @@ -1273,14 +1273,14 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p "wiki. This message will not be shown again.")); } - if (result != Core::System::ResultStatus::Success) { + if (result != Core::SystemResultStatus::Success) { switch (result) { - case Core::System::ResultStatus::ErrorGetLoader: + case Core::SystemResultStatus::ErrorGetLoader: LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filename.toStdString()); QMessageBox::critical(this, tr("Error while loading ROM!"), tr("The ROM format is not supported.")); break; - case Core::System::ResultStatus::ErrorVideoCore: + case Core::SystemResultStatus::ErrorVideoCore: QMessageBox::critical( this, tr("An error occurred initializing the video core."), tr("yuzu has encountered an error while running the video core, please see the " @@ -1294,8 +1294,8 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p break; default: - if (result > Core::System::ResultStatus::ErrorLoader) { - const u16 loader_id = static_cast(Core::System::ResultStatus::ErrorLoader); + if (result > Core::SystemResultStatus::ErrorLoader) { + const u16 loader_id = static_cast(Core::SystemResultStatus::ErrorLoader); const u16 error_id = static_cast(result) - loader_id; const std::string error_code = fmt::format("({:04X}-{:04X})", loader_id, error_id); LOG_CRITICAL(Frontend, "Failed to load ROM! {}", error_code); @@ -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; QString status_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 " "data, or other bugs."); switch (result) { - case Core::System::ResultStatus::ErrorSystemFiles: { + case Core::SystemResultStatus::ErrorSystemFiles: { QString message; if (details.empty()) { message = @@ -3083,7 +3083,7 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string det break; } - case Core::System::ResultStatus::ErrorSharedFont: { + case Core::SystemResultStatus::ErrorSharedFont: { const QString 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, diff --git a/src/yuzu/main.h b/src/yuzu/main.h index f501cf400..b96ac8da3 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -280,7 +280,7 @@ private slots: void ResetWindowSize900(); void ResetWindowSize1080(); void OnCaptureScreenshot(); - void OnCoreError(Core::System::ResultStatus, std::string); + void OnCoreError(Core::SystemResultStatus, std::string); void OnReinitializeKeys(ReinitializeKeyBehavior behavior); void OnLanguageChanged(const QString& locale); void OnMouseActivity(); diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 5c36a21a2..67587cc54 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -166,27 +166,27 @@ int main(int argc, char** argv) { system.SetFilesystem(std::make_shared()); 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) { - case Core::System::ResultStatus::ErrorGetLoader: + case Core::SystemResultStatus::ErrorGetLoader: LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filepath); return -1; - case Core::System::ResultStatus::ErrorLoader: + case Core::SystemResultStatus::ErrorLoader: LOG_CRITICAL(Frontend, "Failed to load ROM!"); return -1; - case Core::System::ResultStatus::ErrorNotInitialized: + case Core::SystemResultStatus::ErrorNotInitialized: LOG_CRITICAL(Frontend, "CPUCore not initialized"); return -1; - case Core::System::ResultStatus::ErrorVideoCore: + case Core::SystemResultStatus::ErrorVideoCore: LOG_CRITICAL(Frontend, "Failed to initialize VideoCore!"); return -1; - case Core::System::ResultStatus::Success: + case Core::SystemResultStatus::Success: break; // Expected case default: if (static_cast(load_result) > - static_cast(Core::System::ResultStatus::ErrorLoader)) { - const u16 loader_id = static_cast(Core::System::ResultStatus::ErrorLoader); + static_cast(Core::SystemResultStatus::ErrorLoader)) { + const u16 loader_id = static_cast(Core::SystemResultStatus::ErrorLoader); const u16 error_id = static_cast(load_result) - loader_id; LOG_CRITICAL(Frontend, "While attempting to load the ROM requested, an error occurred. Please " -- cgit v1.2.3 From f0dc07dbac1fdddf75239ddbdaf643cd3a57f205 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 14 Oct 2021 14:32:19 -0400 Subject: yuzu: Construct system in GMainWindow --- src/yuzu/main.cpp | 153 +++++++++++++++++++++++++++--------------------------- src/yuzu/main.h | 11 ++-- 2 files changed, 83 insertions(+), 81 deletions(-) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index a381eed34..3155a5c19 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -172,7 +172,7 @@ void GMainWindow::ShowTelemetryCallout() { "

Would you like to share your usage data with us?"); if (QMessageBox::question(this, tr("Telemetry"), telemetry_message) != QMessageBox::Yes) { Settings::values.enable_telemetry = false; - system.ApplySettings(); + system->ApplySettings(); } } @@ -191,9 +191,10 @@ static void RemoveCachedContents() { Common::FS::RemoveDirRecursively(offline_system_data); } -GMainWindow::GMainWindow(Core::System& system_) - : input_subsystem{std::make_shared()}, system{system_}, - config{std::make_unique(system_)}, +GMainWindow::GMainWindow() + : system{std::make_unique()}, + input_subsystem{std::make_shared()}, + config{std::make_unique(*system)}, vfs{std::make_shared()}, provider{std::make_unique()} { Common::Log::Initialize(); @@ -257,10 +258,10 @@ GMainWindow::GMainWindow(Core::System& system_) show(); - system.SetContentProvider(std::make_unique()); - system.RegisterContentProvider(FileSys::ContentProviderUnionSlot::FrontendManual, - provider.get()); - system.GetFileSystemController().CreateFactories(*vfs); + system->SetContentProvider(std::make_unique()); + system->RegisterContentProvider(FileSys::ContentProviderUnionSlot::FrontendManual, + provider.get()); + system->GetFileSystemController().CreateFactories(*vfs); // Remove cached contents generated during the previous session RemoveCachedContents(); @@ -411,7 +412,7 @@ void GMainWindow::RegisterMetaTypes() { void GMainWindow::ControllerSelectorReconfigureControllers( 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 | Qt::WindowTitleHint | Qt::WindowSystemMenuHint); @@ -421,7 +422,7 @@ void GMainWindow::ControllerSelectorReconfigureControllers( emit ControllerSelectorReconfigureFinished(); // Don't forget to apply settings. - system.ApplySettings(); + system->ApplySettings(); config->Save(); UpdateStatusButtons(); @@ -455,7 +456,7 @@ void GMainWindow::SoftwareKeyboardInitialize( return; } - software_keyboard = new QtSoftwareKeyboardDialog(render_window, system, is_inline, + software_keyboard = new QtSoftwareKeyboardDialog(render_window, *system, is_inline, std::move(initialize_parameters)); if (is_inline) { @@ -567,7 +568,7 @@ void GMainWindow::WebBrowserOpenWebPage(const std::string& main_url, 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_Restart->setEnabled(false); @@ -699,10 +700,10 @@ void GMainWindow::InitializeWidgets() { #ifdef YUZU_ENABLE_COMPATIBILITY_REPORTING ui->action_Report_Compatibility->setVisible(true); #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(); - game_list = new GameList(vfs, provider.get(), system, this); + game_list = new GameList(vfs, provider.get(), *system, this); ui->horizontalLayout->addWidget(game_list); game_list_placeholder = new GameListPlaceholder(this); @@ -768,14 +769,14 @@ void GMainWindow::InitializeWidgets() { tr("Handheld controller can't be used on docked mode. Pro " "controller will be selected.")); 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(); controller_dialog->refreshConfiguration(); } Settings::values.use_docked_mode.SetValue(!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->setCheckable(true); @@ -799,7 +800,7 @@ void GMainWindow::InitializeWidgets() { } } - system.ApplySettings(); + system->ApplySettings(); UpdateGPUAccuracyButton(); }); UpdateGPUAccuracyButton(); @@ -827,7 +828,7 @@ void GMainWindow::InitializeWidgets() { Settings::values.renderer_backend.SetValue(Settings::RendererBackend::OpenGL); } - system.ApplySettings(); + system->ApplySettings(); }); statusBar()->insertPermanentWidget(0, renderer_status_button); @@ -844,7 +845,7 @@ void GMainWindow::InitializeDebugWidgets() { debug_menu->addAction(microProfileDialog->toggleViewAction()); #endif - waitTreeWidget = new WaitTreeWidget(system, this); + waitTreeWidget = new WaitTreeWidget(*system, this); addDockWidget(Qt::LeftDockWidgetArea, waitTreeWidget); waitTreeWidget->hide(); debug_menu->addAction(waitTreeWidget->toggleViewAction()); @@ -947,7 +948,7 @@ void GMainWindow::InitializeHotkeys() { }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Restart Emulation"), this), &QShortcut::activated, this, [this] { - if (!system.IsPoweredOn()) { + if (!system->IsPoweredOn()) { return; } BootGame(game_path); @@ -1003,7 +1004,7 @@ void GMainWindow::InitializeHotkeys() { Settings::values.use_docked_mode.SetValue( !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()); }); 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; } - system.SetFilesystem(vfs); + system->SetFilesystem(vfs); - system.SetAppletFrontendSet({ + system->SetAppletFrontendSet({ std::make_unique(*this), // Controller Selector std::make_unique(*this), // Error Display nullptr, // Parental Controls @@ -1253,13 +1254,13 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p }); 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() & static_cast(CalloutFlag::DRDDeprecation)) == 0; if (result == Core::SystemResultStatus::Success && - system.GetAppLoader().GetFileType() == Loader::FileType::DeconstructedRomDirectory && + system->GetAppLoader().GetFileType() == Loader::FileType::DeconstructedRomDirectory && drd_callout) { UISettings::values.callout_flags = UISettings::values.callout_flags.GetValue() | static_cast(CalloutFlag::DRDDeprecation); @@ -1323,7 +1324,7 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p } game_path = filename; - system.TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend", "Qt"); + system->TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend", "Qt"); return true; } @@ -1350,7 +1351,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t last_filename_booted = filename; 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 && 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 ? Common::FS::PathToUTF8String(file_path.filename()) : 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(); @@ -1382,16 +1383,16 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t return; // Create and start the emulation thread - emu_thread = std::make_unique(system); + emu_thread = std::make_unique(*system); emit EmulationStarting(emu_thread.get()); emu_thread->start(); // 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); }); // 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::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_version; - const auto res = system.GetGameName(title_name); + const auto res = system->GetGameName(title_name); const auto metadata = [this, title_id] { - const FileSys::PatchManager pm(title_id, system.GetFileSystemController(), - system.GetContentProvider()); + const FileSys::PatchManager pm(title_id, system->GetFileSystemController(), + system->GetContentProvider()); return pm.GetControlMetadata(); }(); 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( 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)"); 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) .toStdString(); 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); - loading_screen->Prepare(system.GetAppLoader()); + loading_screen->Prepare(system->GetAppLoader()); loading_screen->show(); emulation_running = true; @@ -1568,15 +1569,15 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target QString open_target; const auto [user_save_size, device_save_size] = [this, &game_path, &program_id] { - const FileSys::PatchManager pm{program_id, system.GetFileSystemController(), - system.GetContentProvider()}; + const FileSys::PatchManager pm{program_id, system->GetFileSystemController(), + system->GetContentProvider()}; const auto control = pm.GetControlMetadata().first; if (control != nullptr) { return std::make_pair(control->GetDefaultNormalSaveSize(), control->GetDeviceSaveDataSize()); } else { 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{}; loader->ReadControlData(nacp); @@ -1619,14 +1620,14 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target ASSERT(user_id); 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); path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path); } else { // Device save data 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); 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) { - const auto& fs_controller = system.GetFileSystemController(); + const auto& fs_controller = system->GetFileSystemController(); const auto res = fs_controller.GetUserNANDContents()->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) { 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) || 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) { u32 count{}; - const auto& fs_controller = system.GetFileSystemController(); - const auto dlc_entries = system.GetContentProvider().ListEntriesFilter( + const auto& fs_controller = system->GetFileSystemController(); + const auto dlc_entries = system->GetContentProvider().ListEntriesFilter( FileSys::TitleType::AOC, FileSys::ContentRecordType::Data); for (const auto& entry : dlc_entries) { @@ -1923,7 +1924,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa "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) { failed(); return; @@ -1935,7 +1936,7 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa return; } - const auto& installed = system.GetContentProvider(); + const auto& installed = system->GetContentProvider(); const auto romfs_title_id = SelectRomFSDumpTarget(installed, program_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) { 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 = pm.PatchRomFS(file, ivfc_offset, FileSys::ContentRecordType::Program, nullptr, false); } else { @@ -2090,7 +2091,7 @@ void GMainWindow::OnGameListShowList(bool show) { void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) { u64 title_id{}; 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) { QMessageBox::information(this, tr("Properties"), @@ -2304,7 +2305,7 @@ InstallResult GMainWindow::InstallNSPXCI(const QString& filename) { if (nsp->GetStatus() != Loader::ResultStatus::Success) { return InstallResult::Failure; } - const auto res = system.GetFileSystemController().GetUserNANDContents()->InstallEntry( + const auto res = system->GetFileSystemController().GetUserNANDContents()->InstallEntry( *nsp, true, qt_raw_copy); switch (res) { case FileSys::InstallResult::Success: @@ -2384,7 +2385,7 @@ InstallResult GMainWindow::InstallNCA(const QString& filename) { } const bool is_application = index >= static_cast(FileSys::TitleType::Application); - const auto& fs_controller = system.GetFileSystemController(); + const auto& fs_controller = system->GetFileSystemController(); auto* registered_cache = is_application ? fs_controller.GetUserNANDContents() : fs_controller.GetSystemNANDContents(); @@ -2449,13 +2450,13 @@ void GMainWindow::OnPauseGame() { } void GMainWindow::OnStopGame() { - if (system.GetExitLock() && !ConfirmForceLockedExit()) { + if (system->GetExitLock() && !ConfirmForceLockedExit()) { return; } ShutdownGame(); - Settings::RestoreGlobalState(system.IsPoweredOn()); + Settings::RestoreGlobalState(system->IsPoweredOn()); UpdateStatusButtons(); } @@ -2473,7 +2474,7 @@ void GMainWindow::OnExit() { } 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); dialog.exec(); @@ -2483,7 +2484,7 @@ void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_tex void GMainWindow::OnMenuReportCompatibility() { if (!Settings::values.yuzu_token.GetValue().empty() && !Settings::values.yuzu_username.GetValue().empty()) { - CompatDB compatdb{system.TelemetrySession(), this}; + CompatDB compatdb{system->TelemetrySession(), this}; compatdb.exec(); } else { QMessageBox::critical( @@ -2647,7 +2648,7 @@ void GMainWindow::OnConfigure() { const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue(); 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, &GMainWindow::OnLanguageChanged); @@ -2683,7 +2684,7 @@ void GMainWindow::OnConfigure() { Settings::values.disabled_addons.clear(); - config = std::make_unique(system); + config = std::make_unique(*system); UISettings::values.reset_to_defaults = false; UISettings::values.game_dirs = std::move(old_game_dirs); @@ -2732,12 +2733,11 @@ void GMainWindow::OnConfigure() { } void GMainWindow::OnConfigureTas() { - const auto& system = Core::System::GetInstance(); ConfigureTasDialog dialog(this); const auto result = dialog.exec(); if (result != QDialog::Accepted && !UISettings::values.configuration_applied) { - Settings::RestoreGlobalState(system.IsPoweredOn()); + Settings::RestoreGlobalState(system->IsPoweredOn()); return; } else if (result == QDialog::Accepted) { dialog.ApplyConfiguration(); @@ -2745,7 +2745,7 @@ void GMainWindow::OnConfigureTas() { } void GMainWindow::OnConfigurePerGame() { - const u64 title_id = system.CurrentProcess()->GetTitleID(); + const u64 title_id = system->CurrentProcess()->GetTitleID(); 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); Settings::SetConfiguringGlobal(false); - ConfigurePerGame dialog(this, title_id, file_name, system); + ConfigurePerGame dialog(this, title_id, file_name, *system); dialog.LoadFromFile(v_file); const auto result = dialog.exec(); if (result != QDialog::Accepted && !UISettings::values.configuration_applied) { - Settings::RestoreGlobalState(system.IsPoweredOn()); + Settings::RestoreGlobalState(system->IsPoweredOn()); return; } else if (result == QDialog::Accepted) { 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 - const bool is_powered_on = system.IsPoweredOn(); + const bool is_powered_on = system->IsPoweredOn(); Settings::RestoreGlobalState(is_powered_on); UISettings::values.configuration_applied = false; @@ -2793,7 +2793,7 @@ void GMainWindow::OnLoadAmiibo() { } void GMainWindow::LoadAmiibo(const QString& filename) { - Service::SM::ServiceManager& sm = system.ServiceManager(); + Service::SM::ServiceManager& sm = system->ServiceManager(); auto nfc = sm.GetService("nfp:user"); if (nfc == nullptr) { return; @@ -2844,7 +2844,7 @@ void GMainWindow::OnToggleFilterBar() { } void GMainWindow::OnCaptureScreenshot() { - const u64 title_id = system.CurrentProcess()->GetTitleID(); + const u64 title_id = system->CurrentProcess()->GetTitleID(); const auto screenshot_path = QString::fromStdString(Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir)); const auto date = @@ -2950,8 +2950,8 @@ void GMainWindow::UpdateStatusBar() { tas_label->clear(); } - auto results = system.GetAndResetPerfStats(); - auto& shader_notify = system.GPU().ShaderNotify(); + auto results = system->GetAndResetPerfStats(); + auto& shader_notify = system->GPU().ShaderNotify(); const int shaders_building = shader_notify.ShadersBuilding(); if (shaders_building > 0) { @@ -3112,7 +3112,7 @@ void GMainWindow::OnCoreError(Core::SystemResultStatus result, std::string detai if (emu_thread) { ShutdownGame(); - Settings::RestoreGlobalState(system.IsPoweredOn()); + Settings::RestoreGlobalState(system->IsPoweredOn()); UpdateStatusButtons(); } } else { @@ -3154,8 +3154,8 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) { const auto function = [this, &keys, &pdm] { keys.PopulateFromPartitionData(pdm); - system.GetFileSystemController().CreateFactories(*vfs); - keys.DeriveETicket(pdm, system.GetContentProvider()); + system->GetFileSystemController().CreateFactories(*vfs); + keys.DeriveETicket(pdm, system->GetContentProvider()); }; QString errors; @@ -3197,7 +3197,7 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) { prog.close(); } - system.GetFileSystemController().CreateFactories(*vfs); + system->GetFileSystemController().CreateFactories(*vfs); if (behavior == ReinitializeKeyBehavior::Warning) { game_list->PopulateAsync(UISettings::values.game_dirs); @@ -3265,7 +3265,7 @@ void GMainWindow::closeEvent(QCloseEvent* event) { if (emu_thread != nullptr) { ShutdownGame(); - Settings::RestoreGlobalState(system.IsPoweredOn()); + Settings::RestoreGlobalState(system->IsPoweredOn()); UpdateStatusButtons(); } @@ -3340,7 +3340,7 @@ bool GMainWindow::ConfirmForceLockedExit() { } void GMainWindow::RequestGameExit() { - auto& sm{system.ServiceManager()}; + auto& sm{system->ServiceManager()}; auto applet_oe = sm.GetService("appletOE"); auto applet_ae = sm.GetService("appletAE"); bool has_signalled = false; @@ -3434,7 +3434,7 @@ void GMainWindow::OnLanguageChanged(const QString& locale) { void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) { #ifdef USE_DISCORD_PRESENCE if (state) { - discord_rpc = std::make_unique(system); + discord_rpc = std::make_unique(*system); } else { discord_rpc = std::make_unique(); } @@ -3488,8 +3488,7 @@ int main(int argc, char* argv[]) { // generating shaders setlocale(LC_ALL, "C"); - Core::System::InitializeGlobalInstance(); - GMainWindow main_window{Core::System::GetInstance()}; + GMainWindow main_window{}; // After settings have been loaded by GMainWindow, apply the filter main_window.show(); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index b96ac8da3..aed15a0a0 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -13,7 +13,6 @@ #include #include "common/common_types.h" -#include "core/core.h" #include "core/hle/service/acc/profile_manager.h" #include "yuzu/compatibility_list.h" #include "yuzu/hotkeys.h" @@ -44,6 +43,11 @@ enum class StartGameType { Global, // Only uses global configuration }; +namespace Core { +enum class SystemResultStatus : u32; +class System; +} // namespace Core + namespace Core::Frontend { struct ControllerParameters; struct InlineAppearParameters; @@ -110,7 +114,7 @@ class GMainWindow : public QMainWindow { public: void filterBarSetChecked(bool state); void UpdateUITheme(); - GMainWindow(Core::System& system_); + explicit GMainWindow(); ~GMainWindow() override; bool DropAction(QDropEvent* event); @@ -311,11 +315,10 @@ private: std::unique_ptr ui; + std::unique_ptr system; std::unique_ptr discord_rpc; std::shared_ptr input_subsystem; - Core::System& system; - GRenderWindow* render_window; GameList* game_list; LoadingScreen* loading_screen; -- cgit v1.2.3 From 5c6ca597c5d0828fc76da7bc800d0e76a16ea5e9 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 14 Oct 2021 18:16:45 -0400 Subject: bootmanager: Forward declare System and SystemResultStatus --- src/yuzu/bootmanager.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 9fc4116e6..e6a0666e9 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h @@ -16,7 +16,6 @@ #include #include "common/thread.h" -#include "core/core.h" #include "core/frontend/emu_window.h" class GRenderWindow; @@ -24,6 +23,11 @@ class GMainWindow; class QKeyEvent; class QStringList; +namespace Core { +enum class SystemResultStatus : u32; +class System; +} // namespace Core + namespace InputCommon { class InputSubsystem; } -- cgit v1.2.3