settings.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_OutputDevice", values.audio_device_id.GetValue());
  56. log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue());
  57. log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir));
  58. log_path("DataStorage_ConfigDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir));
  59. log_path("DataStorage_LoadDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::LoadDir));
  60. log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir));
  61. log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir));
  62. log_setting("Debugging_ProgramArgs", values.program_args.GetValue());
  63. log_setting("Services_BCATBackend", values.bcat_backend.GetValue());
  64. log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local.GetValue());
  65. }
  66. bool IsConfiguringGlobal() {
  67. return configuring_global;
  68. }
  69. void SetConfiguringGlobal(bool is_global) {
  70. configuring_global = is_global;
  71. }
  72. bool IsGPULevelExtreme() {
  73. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme;
  74. }
  75. bool IsGPULevelHigh() {
  76. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme ||
  77. values.gpu_accuracy.GetValue() == GPUAccuracy::High;
  78. }
  79. bool IsFastmemEnabled() {
  80. if (values.cpu_debug_mode) {
  81. return static_cast<bool>(values.cpuopt_fastmem);
  82. }
  83. return true;
  84. }
  85. float Volume() {
  86. if (values.audio_muted) {
  87. return 0.0f;
  88. }
  89. return values.volume.GetValue() / 100.0f;
  90. }
  91. void RestoreGlobalState(bool is_powered_on) {
  92. // If a game is running, DO NOT restore the global settings state
  93. if (is_powered_on) {
  94. return;
  95. }
  96. // Audio: None
  97. // Core
  98. values.use_multi_core.SetGlobal(true);
  99. // CPU
  100. values.cpu_accuracy.SetGlobal(true);
  101. values.cpuopt_unsafe_unfuse_fma.SetGlobal(true);
  102. values.cpuopt_unsafe_reduce_fp_error.SetGlobal(true);
  103. values.cpuopt_unsafe_ignore_standard_fpcr.SetGlobal(true);
  104. values.cpuopt_unsafe_inaccurate_nan.SetGlobal(true);
  105. values.cpuopt_unsafe_fastmem_check.SetGlobal(true);
  106. // Renderer
  107. values.renderer_backend.SetGlobal(true);
  108. values.vulkan_device.SetGlobal(true);
  109. values.aspect_ratio.SetGlobal(true);
  110. values.max_anisotropy.SetGlobal(true);
  111. values.use_speed_limit.SetGlobal(true);
  112. values.speed_limit.SetGlobal(true);
  113. values.use_disk_shader_cache.SetGlobal(true);
  114. values.gpu_accuracy.SetGlobal(true);
  115. values.use_asynchronous_gpu_emulation.SetGlobal(true);
  116. values.nvdec_emulation.SetGlobal(true);
  117. values.accelerate_astc.SetGlobal(true);
  118. values.use_vsync.SetGlobal(true);
  119. values.shader_backend.SetGlobal(true);
  120. values.use_asynchronous_shaders.SetGlobal(true);
  121. values.use_fast_gpu_time.SetGlobal(true);
  122. values.bg_red.SetGlobal(true);
  123. values.bg_green.SetGlobal(true);
  124. values.bg_blue.SetGlobal(true);
  125. // System
  126. values.language_index.SetGlobal(true);
  127. values.region_index.SetGlobal(true);
  128. values.time_zone_index.SetGlobal(true);
  129. values.rng_seed.SetGlobal(true);
  130. values.sound_index.SetGlobal(true);
  131. // Controls
  132. values.players.SetGlobal(true);
  133. values.use_docked_mode.SetGlobal(true);
  134. values.vibration_enabled.SetGlobal(true);
  135. values.motion_enabled.SetGlobal(true);
  136. }
  137. } // namespace Settings