settings.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_UseResolutionFactor", values.resolution_factor.GetValue());
  42. log_setting("Renderer_UseSpeedLimit", values.use_speed_limit.GetValue());
  43. log_setting("Renderer_SpeedLimit", values.speed_limit.GetValue());
  44. log_setting("Renderer_UseDiskShaderCache", values.use_disk_shader_cache.GetValue());
  45. log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue());
  46. log_setting("Renderer_UseAsynchronousGpuEmulation",
  47. values.use_asynchronous_gpu_emulation.GetValue());
  48. log_setting("Renderer_NvdecEmulation", values.nvdec_emulation.GetValue());
  49. log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue());
  50. log_setting("Renderer_UseVsync", values.use_vsync.GetValue());
  51. log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue());
  52. log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
  53. log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
  54. log_setting("Audio_OutputEngine", values.sink_id.GetValue());
  55. log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.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("Services_BCATBackend", values.bcat_backend.GetValue());
  65. log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local.GetValue());
  66. }
  67. bool IsConfiguringGlobal() {
  68. return configuring_global;
  69. }
  70. void SetConfiguringGlobal(bool is_global) {
  71. configuring_global = is_global;
  72. }
  73. bool IsGPULevelExtreme() {
  74. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme;
  75. }
  76. bool IsGPULevelHigh() {
  77. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme ||
  78. values.gpu_accuracy.GetValue() == GPUAccuracy::High;
  79. }
  80. bool IsFastmemEnabled() {
  81. if (values.cpu_debug_mode) {
  82. return static_cast<bool>(values.cpuopt_fastmem);
  83. }
  84. return true;
  85. }
  86. float Volume() {
  87. if (values.audio_muted) {
  88. return 0.0f;
  89. }
  90. return values.volume.GetValue() / 100.0f;
  91. }
  92. void RestoreGlobalState(bool is_powered_on) {
  93. // If a game is running, DO NOT restore the global settings state
  94. if (is_powered_on) {
  95. return;
  96. }
  97. // Audio
  98. values.enable_audio_stretching.SetGlobal(true);
  99. values.volume.SetGlobal(true);
  100. // Core
  101. values.use_multi_core.SetGlobal(true);
  102. // CPU
  103. values.cpu_accuracy.SetGlobal(true);
  104. values.cpuopt_unsafe_unfuse_fma.SetGlobal(true);
  105. values.cpuopt_unsafe_reduce_fp_error.SetGlobal(true);
  106. values.cpuopt_unsafe_ignore_standard_fpcr.SetGlobal(true);
  107. values.cpuopt_unsafe_inaccurate_nan.SetGlobal(true);
  108. values.cpuopt_unsafe_fastmem_check.SetGlobal(true);
  109. // Renderer
  110. values.renderer_backend.SetGlobal(true);
  111. values.vulkan_device.SetGlobal(true);
  112. values.aspect_ratio.SetGlobal(true);
  113. values.max_anisotropy.SetGlobal(true);
  114. values.use_speed_limit.SetGlobal(true);
  115. values.speed_limit.SetGlobal(true);
  116. values.use_disk_shader_cache.SetGlobal(true);
  117. values.gpu_accuracy.SetGlobal(true);
  118. values.use_asynchronous_gpu_emulation.SetGlobal(true);
  119. values.nvdec_emulation.SetGlobal(true);
  120. values.accelerate_astc.SetGlobal(true);
  121. values.use_vsync.SetGlobal(true);
  122. values.shader_backend.SetGlobal(true);
  123. values.use_asynchronous_shaders.SetGlobal(true);
  124. values.use_fast_gpu_time.SetGlobal(true);
  125. values.bg_red.SetGlobal(true);
  126. values.bg_green.SetGlobal(true);
  127. values.bg_blue.SetGlobal(true);
  128. // System
  129. values.language_index.SetGlobal(true);
  130. values.region_index.SetGlobal(true);
  131. values.time_zone_index.SetGlobal(true);
  132. values.rng_seed.SetGlobal(true);
  133. values.sound_index.SetGlobal(true);
  134. // Controls
  135. values.players.SetGlobal(true);
  136. values.use_docked_mode.SetGlobal(true);
  137. values.vibration_enabled.SetGlobal(true);
  138. values.motion_enabled.SetGlobal(true);
  139. }
  140. } // namespace Settings