settings.cpp 7.6 KB

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