settings.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <string_view>
  4. #include "common/assert.h"
  5. #include "common/fs/path_util.h"
  6. #include "common/logging/log.h"
  7. #include "common/settings.h"
  8. namespace Settings {
  9. Values values;
  10. static bool configuring_global = true;
  11. std::string GetTimeZoneString() {
  12. static constexpr std::array timezones{
  13. "auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire",
  14. "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0",
  15. "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan",
  16. "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT",
  17. "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey",
  18. "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu",
  19. };
  20. const auto time_zone_index = static_cast<std::size_t>(values.time_zone_index.GetValue());
  21. ASSERT(time_zone_index < timezones.size());
  22. return timezones[time_zone_index];
  23. }
  24. void LogSettings() {
  25. const auto log_setting = [](std::string_view name, const auto& value) {
  26. LOG_INFO(Config, "{}: {}", name, value);
  27. };
  28. const auto log_path = [](std::string_view name, const std::filesystem::path& path) {
  29. LOG_INFO(Config, "{}: {}", name, Common::FS::PathToUTF8String(path));
  30. };
  31. LOG_INFO(Config, "yuzu Configuration:");
  32. log_setting("Controls_UseDockedMode", values.use_docked_mode.GetValue());
  33. log_setting("System_RngSeed", values.rng_seed.GetValue().value_or(0));
  34. log_setting("System_CurrentUser", values.current_user.GetValue());
  35. log_setting("System_LanguageIndex", values.language_index.GetValue());
  36. log_setting("System_RegionIndex", values.region_index.GetValue());
  37. log_setting("System_TimeZoneIndex", values.time_zone_index.GetValue());
  38. log_setting("Core_UseMultiCore", values.use_multi_core.GetValue());
  39. log_setting("CPU_Accuracy", values.cpu_accuracy.GetValue());
  40. log_setting("Renderer_UseResolutionScaling", values.resolution_setup.GetValue());
  41. log_setting("Renderer_ScalingFilter", values.scaling_filter.GetValue());
  42. log_setting("Renderer_AntiAliasing", values.anti_aliasing.GetValue());
  43. log_setting("Renderer_UseSpeedLimit", values.use_speed_limit.GetValue());
  44. log_setting("Renderer_SpeedLimit", values.speed_limit.GetValue());
  45. log_setting("Renderer_UseDiskShaderCache", values.use_disk_shader_cache.GetValue());
  46. log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue());
  47. log_setting("Renderer_UseAsynchronousGpuEmulation",
  48. values.use_asynchronous_gpu_emulation.GetValue());
  49. log_setting("Renderer_NvdecEmulation", values.nvdec_emulation.GetValue());
  50. log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue());
  51. log_setting("Renderer_UseVsync", values.use_vsync.GetValue());
  52. log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue());
  53. log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
  54. log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
  55. log_setting("Audio_OutputEngine", values.sink_id.GetValue());
  56. log_setting("Audio_OutputDevice", values.audio_output_device_id.GetValue());
  57. log_setting("Audio_InputDevice", values.audio_input_device_id.GetValue());
  58. log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue());
  59. log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir));
  60. log_path("DataStorage_ConfigDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir));
  61. log_path("DataStorage_LoadDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::LoadDir));
  62. log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir));
  63. log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir));
  64. log_setting("Debugging_ProgramArgs", values.program_args.GetValue());
  65. log_setting("Debugging_GDBStub", values.use_gdbstub.GetValue());
  66. log_setting("Input_EnableMotion", values.motion_enabled.GetValue());
  67. log_setting("Input_EnableVibration", values.vibration_enabled.GetValue());
  68. log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue());
  69. }
  70. bool IsConfiguringGlobal() {
  71. return configuring_global;
  72. }
  73. void SetConfiguringGlobal(bool is_global) {
  74. configuring_global = is_global;
  75. }
  76. bool IsGPULevelExtreme() {
  77. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme;
  78. }
  79. bool IsGPULevelHigh() {
  80. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme ||
  81. values.gpu_accuracy.GetValue() == GPUAccuracy::High;
  82. }
  83. bool IsFastmemEnabled() {
  84. if (values.cpu_debug_mode) {
  85. return static_cast<bool>(values.cpuopt_fastmem);
  86. }
  87. return true;
  88. }
  89. float Volume() {
  90. if (values.audio_muted) {
  91. return 0.0f;
  92. }
  93. return values.volume.GetValue() / static_cast<f32>(values.volume.GetDefault());
  94. }
  95. void UpdateRescalingInfo() {
  96. const auto setup = values.resolution_setup.GetValue();
  97. auto& info = values.resolution_info;
  98. info.downscale = false;
  99. switch (setup) {
  100. case ResolutionSetup::Res1_2X:
  101. info.up_scale = 1;
  102. info.down_shift = 1;
  103. info.downscale = true;
  104. break;
  105. case ResolutionSetup::Res3_4X:
  106. info.up_scale = 3;
  107. info.down_shift = 2;
  108. info.downscale = true;
  109. break;
  110. case ResolutionSetup::Res1X:
  111. info.up_scale = 1;
  112. info.down_shift = 0;
  113. break;
  114. case ResolutionSetup::Res2X:
  115. info.up_scale = 2;
  116. info.down_shift = 0;
  117. break;
  118. case ResolutionSetup::Res3X:
  119. info.up_scale = 3;
  120. info.down_shift = 0;
  121. break;
  122. case ResolutionSetup::Res4X:
  123. info.up_scale = 4;
  124. info.down_shift = 0;
  125. break;
  126. case ResolutionSetup::Res5X:
  127. info.up_scale = 5;
  128. info.down_shift = 0;
  129. break;
  130. case ResolutionSetup::Res6X:
  131. info.up_scale = 6;
  132. info.down_shift = 0;
  133. break;
  134. default:
  135. ASSERT(false);
  136. info.up_scale = 1;
  137. info.down_shift = 0;
  138. }
  139. info.up_factor = static_cast<f32>(info.up_scale) / (1U << info.down_shift);
  140. info.down_factor = static_cast<f32>(1U << info.down_shift) / info.up_scale;
  141. info.active = info.up_scale != 1 || info.down_shift != 0;
  142. }
  143. void RestoreGlobalState(bool is_powered_on) {
  144. // If a game is running, DO NOT restore the global settings state
  145. if (is_powered_on) {
  146. return;
  147. }
  148. // Audio
  149. values.volume.SetGlobal(true);
  150. // Core
  151. values.use_multi_core.SetGlobal(true);
  152. values.use_extended_memory_layout.SetGlobal(true);
  153. // CPU
  154. values.cpu_accuracy.SetGlobal(true);
  155. values.cpuopt_unsafe_unfuse_fma.SetGlobal(true);
  156. values.cpuopt_unsafe_reduce_fp_error.SetGlobal(true);
  157. values.cpuopt_unsafe_ignore_standard_fpcr.SetGlobal(true);
  158. values.cpuopt_unsafe_inaccurate_nan.SetGlobal(true);
  159. values.cpuopt_unsafe_fastmem_check.SetGlobal(true);
  160. values.cpuopt_unsafe_ignore_global_monitor.SetGlobal(true);
  161. // Renderer
  162. values.renderer_backend.SetGlobal(true);
  163. values.vulkan_device.SetGlobal(true);
  164. values.aspect_ratio.SetGlobal(true);
  165. values.max_anisotropy.SetGlobal(true);
  166. values.use_speed_limit.SetGlobal(true);
  167. values.speed_limit.SetGlobal(true);
  168. values.use_disk_shader_cache.SetGlobal(true);
  169. values.gpu_accuracy.SetGlobal(true);
  170. values.use_asynchronous_gpu_emulation.SetGlobal(true);
  171. values.nvdec_emulation.SetGlobal(true);
  172. values.accelerate_astc.SetGlobal(true);
  173. values.use_vsync.SetGlobal(true);
  174. values.shader_backend.SetGlobal(true);
  175. values.use_asynchronous_shaders.SetGlobal(true);
  176. values.use_fast_gpu_time.SetGlobal(true);
  177. values.bg_red.SetGlobal(true);
  178. values.bg_green.SetGlobal(true);
  179. values.bg_blue.SetGlobal(true);
  180. // System
  181. values.language_index.SetGlobal(true);
  182. values.region_index.SetGlobal(true);
  183. values.time_zone_index.SetGlobal(true);
  184. values.rng_seed.SetGlobal(true);
  185. values.sound_index.SetGlobal(true);
  186. // Controls
  187. values.players.SetGlobal(true);
  188. values.use_docked_mode.SetGlobal(true);
  189. values.vibration_enabled.SetGlobal(true);
  190. values.motion_enabled.SetGlobal(true);
  191. }
  192. } // namespace Settings