settings.cpp 6.0 KB

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