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(-) (limited to 'src/core') 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 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 ++++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 43 deletions(-) (limited to 'src/core') 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; -- cgit v1.2.3