settings.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright 2014 Citra 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/file_util.h"
  7. #include "common/logging/log.h"
  8. #include "core/core.h"
  9. #include "core/hle/service/hid/hid.h"
  10. #include "core/settings.h"
  11. #include "video_core/renderer_base.h"
  12. namespace Settings {
  13. Values values = {};
  14. static bool configuring_global = true;
  15. std::string GetTimeZoneString() {
  16. static constexpr std::array timezones{
  17. "auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire",
  18. "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0",
  19. "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan",
  20. "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT",
  21. "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey",
  22. "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu",
  23. };
  24. const auto time_zone_index = static_cast<std::size_t>(values.time_zone_index.GetValue());
  25. ASSERT(time_zone_index < timezones.size());
  26. return timezones[time_zone_index];
  27. }
  28. void Apply(Core::System& system) {
  29. if (system.IsPoweredOn()) {
  30. system.Renderer().RefreshBaseSettings();
  31. }
  32. Service::HID::ReloadInputDevices();
  33. }
  34. void LogSettings() {
  35. const auto log_setting = [](std::string_view name, const auto& value) {
  36. LOG_INFO(Config, "{}: {}", name, value);
  37. };
  38. LOG_INFO(Config, "yuzu Configuration:");
  39. log_setting("Controls_UseDockedMode", values.use_docked_mode.GetValue());
  40. log_setting("System_RngSeed", values.rng_seed.GetValue().value_or(0));
  41. log_setting("System_CurrentUser", values.current_user);
  42. log_setting("System_LanguageIndex", values.language_index.GetValue());
  43. log_setting("System_RegionIndex", values.region_index.GetValue());
  44. log_setting("System_TimeZoneIndex", values.time_zone_index.GetValue());
  45. log_setting("Core_UseMultiCore", values.use_multi_core.GetValue());
  46. log_setting("CPU_Accuracy", values.cpu_accuracy);
  47. log_setting("Renderer_UseResolutionFactor", values.resolution_factor.GetValue());
  48. log_setting("Renderer_UseFrameLimit", values.use_frame_limit.GetValue());
  49. log_setting("Renderer_FrameLimit", values.frame_limit.GetValue());
  50. log_setting("Renderer_UseDiskShaderCache", values.use_disk_shader_cache.GetValue());
  51. log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue());
  52. log_setting("Renderer_UseAsynchronousGpuEmulation",
  53. values.use_asynchronous_gpu_emulation.GetValue());
  54. log_setting("Renderer_UseNvdecEmulation", values.use_nvdec_emulation.GetValue());
  55. log_setting("Renderer_UseVsync", values.use_vsync.GetValue());
  56. log_setting("Renderer_UseAssemblyShaders", values.use_assembly_shaders.GetValue());
  57. log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
  58. log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
  59. log_setting("Audio_OutputEngine", values.sink_id);
  60. log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue());
  61. log_setting("Audio_OutputDevice", values.audio_device_id);
  62. log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd);
  63. log_setting("DataStorage_CacheDir", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir));
  64. log_setting("DataStorage_ConfigDir", Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir));
  65. log_setting("DataStorage_LoadDir", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir));
  66. log_setting("DataStorage_NandDir", Common::FS::GetUserPath(Common::FS::UserPath::NANDDir));
  67. log_setting("DataStorage_SdmcDir", Common::FS::GetUserPath(Common::FS::UserPath::SDMCDir));
  68. log_setting("Debugging_ProgramArgs", values.program_args);
  69. log_setting("Services_BCATBackend", values.bcat_backend);
  70. log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local);
  71. }
  72. bool IsConfiguringGlobal() {
  73. return configuring_global;
  74. }
  75. void SetConfiguringGlobal(bool is_global) {
  76. configuring_global = is_global;
  77. }
  78. bool IsGPULevelExtreme() {
  79. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme;
  80. }
  81. bool IsGPULevelHigh() {
  82. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme ||
  83. values.gpu_accuracy.GetValue() == GPUAccuracy::High;
  84. }
  85. float Volume() {
  86. if (values.audio_muted) {
  87. return 0.0f;
  88. }
  89. return values.volume.GetValue();
  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
  97. values.enable_audio_stretching.SetGlobal(true);
  98. values.volume.SetGlobal(true);
  99. // Core
  100. values.use_multi_core.SetGlobal(true);
  101. // Renderer
  102. values.renderer_backend.SetGlobal(true);
  103. values.vulkan_device.SetGlobal(true);
  104. values.aspect_ratio.SetGlobal(true);
  105. values.max_anisotropy.SetGlobal(true);
  106. values.use_frame_limit.SetGlobal(true);
  107. values.frame_limit.SetGlobal(true);
  108. values.use_disk_shader_cache.SetGlobal(true);
  109. values.gpu_accuracy.SetGlobal(true);
  110. values.use_asynchronous_gpu_emulation.SetGlobal(true);
  111. values.use_nvdec_emulation.SetGlobal(true);
  112. values.use_vsync.SetGlobal(true);
  113. values.use_assembly_shaders.SetGlobal(true);
  114. values.use_asynchronous_shaders.SetGlobal(true);
  115. values.use_fast_gpu_time.SetGlobal(true);
  116. values.bg_red.SetGlobal(true);
  117. values.bg_green.SetGlobal(true);
  118. values.bg_blue.SetGlobal(true);
  119. // System
  120. values.language_index.SetGlobal(true);
  121. values.region_index.SetGlobal(true);
  122. values.time_zone_index.SetGlobal(true);
  123. values.rng_seed.SetGlobal(true);
  124. values.custom_rtc.SetGlobal(true);
  125. values.sound_index.SetGlobal(true);
  126. // Controls
  127. values.players.SetGlobal(true);
  128. values.use_docked_mode.SetGlobal(true);
  129. values.vibration_enabled.SetGlobal(true);
  130. values.motion_enabled.SetGlobal(true);
  131. }
  132. } // namespace Settings