summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mai M2021-10-15 17:57:58 -0400
committerGravatar GitHub2021-10-15 17:57:58 -0400
commitdc385b7392df2b2c301b6df908483beadbb5eb3b (patch)
treef03cf5293b06159cfc9325ee4527a4ea15685c25 /src/core
parentMerge pull request #7183 from FearlessTobi/translation-ci (diff)
parentbootmanager: Forward declare System and SystemResultStatus (diff)
downloadyuzu-dc385b7392df2b2c301b6df908483beadbb5eb3b.tar.gz
yuzu-dc385b7392df2b2c301b6df908483beadbb5eb3b.tar.xz
yuzu-dc385b7392df2b2c301b6df908483beadbb5eb3b.zip
Merge pull request #7182 from Morph1984/system
yuzu: Remove all remaining global system instances
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.cpp64
-rw-r--r--src/core/core.h57
2 files changed, 50 insertions, 71 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index bb268a319..3532839df 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -139,8 +139,8 @@ struct System::Impl {
139 : kernel{system}, fs_controller{system}, memory{system}, 139 : kernel{system}, fs_controller{system}, memory{system},
140 cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system} {} 140 cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system} {}
141 141
142 ResultStatus Run() { 142 SystemResultStatus Run() {
143 status = ResultStatus::Success; 143 status = SystemResultStatus::Success;
144 144
145 kernel.Suspend(false); 145 kernel.Suspend(false);
146 core_timing.SyncPause(false); 146 core_timing.SyncPause(false);
@@ -149,8 +149,8 @@ struct System::Impl {
149 return status; 149 return status;
150 } 150 }
151 151
152 ResultStatus Pause() { 152 SystemResultStatus Pause() {
153 status = ResultStatus::Success; 153 status = SystemResultStatus::Success;
154 154
155 core_timing.SyncPause(true); 155 core_timing.SyncPause(true);
156 kernel.Suspend(true); 156 kernel.Suspend(true);
@@ -159,7 +159,7 @@ struct System::Impl {
159 return status; 159 return status;
160 } 160 }
161 161
162 ResultStatus Init(System& system, Frontend::EmuWindow& emu_window) { 162 SystemResultStatus Init(System& system, Frontend::EmuWindow& emu_window) {
163 LOG_DEBUG(Core, "initialized OK"); 163 LOG_DEBUG(Core, "initialized OK");
164 164
165 device_memory = std::make_unique<Core::DeviceMemory>(); 165 device_memory = std::make_unique<Core::DeviceMemory>();
@@ -197,7 +197,7 @@ struct System::Impl {
197 197
198 gpu_core = VideoCore::CreateGPU(emu_window, system); 198 gpu_core = VideoCore::CreateGPU(emu_window, system);
199 if (!gpu_core) { 199 if (!gpu_core) {
200 return ResultStatus::ErrorVideoCore; 200 return SystemResultStatus::ErrorVideoCore;
201 } 201 }
202 202
203 service_manager = std::make_shared<Service::SM::ServiceManager>(kernel); 203 service_manager = std::make_shared<Service::SM::ServiceManager>(kernel);
@@ -217,21 +217,22 @@ struct System::Impl {
217 217
218 LOG_DEBUG(Core, "Initialized OK"); 218 LOG_DEBUG(Core, "Initialized OK");
219 219
220 return ResultStatus::Success; 220 return SystemResultStatus::Success;
221 } 221 }
222 222
223 ResultStatus Load(System& system, Frontend::EmuWindow& emu_window, const std::string& filepath, 223 SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window,
224 u64 program_id, std::size_t program_index) { 224 const std::string& filepath, u64 program_id,
225 std::size_t program_index) {
225 app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath), 226 app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath),
226 program_id, program_index); 227 program_id, program_index);
227 228
228 if (!app_loader) { 229 if (!app_loader) {
229 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); 230 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
230 return ResultStatus::ErrorGetLoader; 231 return SystemResultStatus::ErrorGetLoader;
231 } 232 }
232 233
233 ResultStatus init_result{Init(system, emu_window)}; 234 SystemResultStatus init_result{Init(system, emu_window)};
234 if (init_result != ResultStatus::Success) { 235 if (init_result != SystemResultStatus::Success) {
235 LOG_CRITICAL(Core, "Failed to initialize system (Error {})!", 236 LOG_CRITICAL(Core, "Failed to initialize system (Error {})!",
236 static_cast<int>(init_result)); 237 static_cast<int>(init_result));
237 Shutdown(); 238 Shutdown();
@@ -249,8 +250,8 @@ struct System::Impl {
249 LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result); 250 LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result);
250 Shutdown(); 251 Shutdown();
251 252
252 return static_cast<ResultStatus>(static_cast<u32>(ResultStatus::ErrorLoader) + 253 return static_cast<SystemResultStatus>(
253 static_cast<u32>(load_result)); 254 static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result));
254 } 255 }
255 AddGlueRegistrationForProcess(*app_loader, *main_process); 256 AddGlueRegistrationForProcess(*app_loader, *main_process);
256 kernel.MakeCurrentProcess(main_process.get()); 257 kernel.MakeCurrentProcess(main_process.get());
@@ -282,7 +283,7 @@ struct System::Impl {
282 GetAndResetPerfStats(); 283 GetAndResetPerfStats();
283 perf_stats->BeginSystemFrame(); 284 perf_stats->BeginSystemFrame();
284 285
285 status = ResultStatus::Success; 286 status = SystemResultStatus::Success;
286 return status; 287 return status;
287 } 288 }
288 289
@@ -355,7 +356,7 @@ struct System::Impl {
355 arp_manager.Register(launch.title_id, launch, std::move(nacp_data)); 356 arp_manager.Register(launch.title_id, launch, std::move(nacp_data));
356 } 357 }
357 358
358 void SetStatus(ResultStatus new_status, const char* details = nullptr) { 359 void SetStatus(SystemResultStatus new_status, const char* details = nullptr) {
359 status = new_status; 360 status = new_status;
360 if (details) { 361 if (details) {
361 status_details = details; 362 status_details = details;
@@ -411,7 +412,7 @@ struct System::Impl {
411 /// Network instance 412 /// Network instance
412 Network::NetworkInstance network_instance; 413 Network::NetworkInstance network_instance;
413 414
414 ResultStatus status = ResultStatus::Success; 415 SystemResultStatus status = SystemResultStatus::Success;
415 std::string status_details = ""; 416 std::string status_details = "";
416 417
417 std::unique_ptr<Core::PerfStats> perf_stats; 418 std::unique_ptr<Core::PerfStats> perf_stats;
@@ -428,21 +429,8 @@ struct System::Impl {
428}; 429};
429 430
430System::System() : impl{std::make_unique<Impl>(*this)} {} 431System::System() : impl{std::make_unique<Impl>(*this)} {}
431System::~System() = default;
432
433System& System::GetInstance() {
434 if (!s_instance) {
435 throw std::runtime_error("Using System instance before its initialization");
436 }
437 return *s_instance;
438}
439 432
440void System::InitializeGlobalInstance() { 433System::~System() = default;
441 if (s_instance) {
442 throw std::runtime_error("Reinitializing Global System instance.");
443 }
444 s_instance = std::unique_ptr<System>(new System);
445}
446 434
447CpuManager& System::GetCpuManager() { 435CpuManager& System::GetCpuManager() {
448 return impl->cpu_manager; 436 return impl->cpu_manager;
@@ -452,16 +440,16 @@ const CpuManager& System::GetCpuManager() const {
452 return impl->cpu_manager; 440 return impl->cpu_manager;
453} 441}
454 442
455System::ResultStatus System::Run() { 443SystemResultStatus System::Run() {
456 return impl->Run(); 444 return impl->Run();
457} 445}
458 446
459System::ResultStatus System::Pause() { 447SystemResultStatus System::Pause() {
460 return impl->Pause(); 448 return impl->Pause();
461} 449}
462 450
463System::ResultStatus System::SingleStep() { 451SystemResultStatus System::SingleStep() {
464 return ResultStatus::Success; 452 return SystemResultStatus::Success;
465} 453}
466 454
467void System::InvalidateCpuInstructionCaches() { 455void System::InvalidateCpuInstructionCaches() {
@@ -476,8 +464,8 @@ void System::Shutdown() {
476 impl->Shutdown(); 464 impl->Shutdown();
477} 465}
478 466
479System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath, 467SystemResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath,
480 u64 program_id, std::size_t program_index) { 468 u64 program_id, std::size_t program_index) {
481 return impl->Load(*this, emu_window, filepath, program_id, program_index); 469 return impl->Load(*this, emu_window, filepath, program_id, program_index);
482} 470}
483 471
@@ -637,7 +625,7 @@ Loader::ResultStatus System::GetGameName(std::string& out) const {
637 return impl->GetGameName(out); 625 return impl->GetGameName(out);
638} 626}
639 627
640void System::SetStatus(ResultStatus new_status, const char* details) { 628void System::SetStatus(SystemResultStatus new_status, const char* details) {
641 impl->SetStatus(new_status, details); 629 impl->SetStatus(new_status, details);
642} 630}
643 631
diff --git a/src/core/core.h b/src/core/core.h
index a796472b2..c1234ef77 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -104,55 +104,49 @@ struct PerfStatsResults;
104FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, 104FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
105 const std::string& path); 105 const std::string& path);
106 106
107/// Enumeration representing the return values of the System Initialize and Load process.
108enum class SystemResultStatus : u32 {
109 Success, ///< Succeeded
110 ErrorNotInitialized, ///< Error trying to use core prior to initialization
111 ErrorGetLoader, ///< Error finding the correct application loader
112 ErrorSystemFiles, ///< Error in finding system files
113 ErrorSharedFont, ///< Error in finding shared font
114 ErrorVideoCore, ///< Error in the video core
115 ErrorUnknown, ///< Any other error
116 ErrorLoader, ///< The base for loader errors (too many to repeat)
117};
118
107class System { 119class System {
108public: 120public:
109 using CurrentBuildProcessID = std::array<u8, 0x20>; 121 using CurrentBuildProcessID = std::array<u8, 0x20>;
110 122
123 explicit System();
124
125 ~System();
126
111 System(const System&) = delete; 127 System(const System&) = delete;
112 System& operator=(const System&) = delete; 128 System& operator=(const System&) = delete;
113 129
114 System(System&&) = delete; 130 System(System&&) = delete;
115 System& operator=(System&&) = delete; 131 System& operator=(System&&) = delete;
116 132
117 ~System();
118
119 /**
120 * Gets the instance of the System singleton class.
121 * @returns Reference to the instance of the System singleton class.
122 */
123 [[deprecated("Use of the global system instance is deprecated")]] static System& GetInstance();
124
125 static void InitializeGlobalInstance();
126
127 /// Enumeration representing the return values of the System Initialize and Load process.
128 enum class ResultStatus : u32 {
129 Success, ///< Succeeded
130 ErrorNotInitialized, ///< Error trying to use core prior to initialization
131 ErrorGetLoader, ///< Error finding the correct application loader
132 ErrorSystemFiles, ///< Error in finding system files
133 ErrorSharedFont, ///< Error in finding shared font
134 ErrorVideoCore, ///< Error in the video core
135 ErrorUnknown, ///< Any other error
136 ErrorLoader, ///< The base for loader errors (too many to repeat)
137 };
138
139 /** 133 /**
140 * Run the OS and Application 134 * Run the OS and Application
141 * This function will start emulation and run the relevant devices 135 * This function will start emulation and run the relevant devices
142 */ 136 */
143 [[nodiscard]] ResultStatus Run(); 137 [[nodiscard]] SystemResultStatus Run();
144 138
145 /** 139 /**
146 * Pause the OS and Application 140 * Pause the OS and Application
147 * This function will pause emulation and stop the relevant devices 141 * This function will pause emulation and stop the relevant devices
148 */ 142 */
149 [[nodiscard]] ResultStatus Pause(); 143 [[nodiscard]] SystemResultStatus Pause();
150 144
151 /** 145 /**
152 * Step the CPU one instruction 146 * Step the CPU one instruction
153 * @return Result status, indicating whether or not the operation succeeded. 147 * @return Result status, indicating whether or not the operation succeeded.
154 */ 148 */
155 [[nodiscard]] ResultStatus SingleStep(); 149 [[nodiscard]] SystemResultStatus SingleStep();
156 150
157 /** 151 /**
158 * Invalidate the CPU instruction caches 152 * Invalidate the CPU instruction caches
@@ -172,10 +166,11 @@ public:
172 * input. 166 * input.
173 * @param filepath String path to the executable application to load on the host file system. 167 * @param filepath String path to the executable application to load on the host file system.
174 * @param program_index Specifies the index within the container of the program to launch. 168 * @param program_index Specifies the index within the container of the program to launch.
175 * @returns ResultStatus code, indicating if the operation succeeded. 169 * @returns SystemResultStatus code, indicating if the operation succeeded.
176 */ 170 */
177 [[nodiscard]] ResultStatus Load(Frontend::EmuWindow& emu_window, const std::string& filepath, 171 [[nodiscard]] SystemResultStatus Load(Frontend::EmuWindow& emu_window,
178 u64 program_id = 0, std::size_t program_index = 0); 172 const std::string& filepath, u64 program_id = 0,
173 std::size_t program_index = 0);
179 174
180 /** 175 /**
181 * Indicates if the emulated system is powered on (all subsystems initialized and able to run an 176 * Indicates if the emulated system is powered on (all subsystems initialized and able to run an
@@ -301,7 +296,7 @@ public:
301 /// Gets the name of the current game 296 /// Gets the name of the current game
302 [[nodiscard]] Loader::ResultStatus GetGameName(std::string& out) const; 297 [[nodiscard]] Loader::ResultStatus GetGameName(std::string& out) const;
303 298
304 void SetStatus(ResultStatus new_status, const char* details); 299 void SetStatus(SystemResultStatus new_status, const char* details);
305 300
306 [[nodiscard]] const std::string& GetStatusDetails() const; 301 [[nodiscard]] const std::string& GetStatusDetails() const;
307 302
@@ -403,12 +398,8 @@ public:
403 void ApplySettings(); 398 void ApplySettings();
404 399
405private: 400private:
406 System();
407
408 struct Impl; 401 struct Impl;
409 std::unique_ptr<Impl> impl; 402 std::unique_ptr<Impl> impl;
410
411 inline static std::unique_ptr<System> s_instance{};
412}; 403};
413 404
414} // namespace Core 405} // namespace Core