diff options
Diffstat (limited to 'src/common/settings.cpp')
| -rw-r--r-- | src/common/settings.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/common/settings.cpp b/src/common/settings.cpp new file mode 100644 index 000000000..702b6598d --- /dev/null +++ b/src/common/settings.cpp | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <string_view> | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/file_util.h" | ||
| 9 | #include "common/logging/log.h" | ||
| 10 | #include "common/settings.h" | ||
| 11 | |||
| 12 | namespace Settings { | ||
| 13 | |||
| 14 | Values values = {}; | ||
| 15 | static bool configuring_global = true; | ||
| 16 | |||
| 17 | std::string GetTimeZoneString() { | ||
| 18 | static constexpr std::array timezones{ | ||
| 19 | "auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire", | ||
| 20 | "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0", | ||
| 21 | "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan", | ||
| 22 | "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT", | ||
| 23 | "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey", | ||
| 24 | "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu", | ||
| 25 | }; | ||
| 26 | |||
| 27 | const auto time_zone_index = static_cast<std::size_t>(values.time_zone_index.GetValue()); | ||
| 28 | ASSERT(time_zone_index < timezones.size()); | ||
| 29 | return timezones[time_zone_index]; | ||
| 30 | } | ||
| 31 | |||
| 32 | void LogSettings() { | ||
| 33 | const auto log_setting = [](std::string_view name, const auto& value) { | ||
| 34 | LOG_INFO(Config, "{}: {}", name, value); | ||
| 35 | }; | ||
| 36 | |||
| 37 | LOG_INFO(Config, "yuzu Configuration:"); | ||
| 38 | log_setting("Controls_UseDockedMode", values.use_docked_mode.GetValue()); | ||
| 39 | log_setting("System_RngSeed", values.rng_seed.GetValue().value_or(0)); | ||
| 40 | log_setting("System_CurrentUser", values.current_user); | ||
| 41 | log_setting("System_LanguageIndex", values.language_index.GetValue()); | ||
| 42 | log_setting("System_RegionIndex", values.region_index.GetValue()); | ||
| 43 | log_setting("System_TimeZoneIndex", values.time_zone_index.GetValue()); | ||
| 44 | log_setting("Core_UseMultiCore", values.use_multi_core.GetValue()); | ||
| 45 | log_setting("CPU_Accuracy", values.cpu_accuracy); | ||
| 46 | log_setting("Renderer_UseResolutionFactor", values.resolution_factor.GetValue()); | ||
| 47 | log_setting("Renderer_UseFrameLimit", values.use_frame_limit.GetValue()); | ||
| 48 | log_setting("Renderer_FrameLimit", values.frame_limit.GetValue()); | ||
| 49 | log_setting("Renderer_UseDiskShaderCache", values.use_disk_shader_cache.GetValue()); | ||
| 50 | log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue()); | ||
| 51 | log_setting("Renderer_UseAsynchronousGpuEmulation", | ||
| 52 | values.use_asynchronous_gpu_emulation.GetValue()); | ||
| 53 | log_setting("Renderer_UseNvdecEmulation", values.use_nvdec_emulation.GetValue()); | ||
| 54 | log_setting("Renderer_UseVsync", values.use_vsync.GetValue()); | ||
| 55 | log_setting("Renderer_UseAssemblyShaders", values.use_assembly_shaders.GetValue()); | ||
| 56 | log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); | ||
| 57 | log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); | ||
| 58 | log_setting("Audio_OutputEngine", values.sink_id); | ||
| 59 | log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue()); | ||
| 60 | log_setting("Audio_OutputDevice", values.audio_device_id); | ||
| 61 | log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd); | ||
| 62 | log_setting("DataStorage_CacheDir", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)); | ||
| 63 | log_setting("DataStorage_ConfigDir", Common::FS::GetUserPath(Common::FS::UserPath::ConfigDir)); | ||
| 64 | log_setting("DataStorage_LoadDir", Common::FS::GetUserPath(Common::FS::UserPath::LoadDir)); | ||
| 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_ProgramArgs", values.program_args); | ||
| 68 | log_setting("Services_BCATBackend", values.bcat_backend); | ||
| 69 | log_setting("Services_BCATBoxcatLocal", values.bcat_boxcat_local); | ||
| 70 | } | ||
| 71 | |||
| 72 | bool IsConfiguringGlobal() { | ||
| 73 | return configuring_global; | ||
| 74 | } | ||
| 75 | |||
| 76 | void SetConfiguringGlobal(bool is_global) { | ||
| 77 | configuring_global = is_global; | ||
| 78 | } | ||
| 79 | |||
| 80 | bool IsGPULevelExtreme() { | ||
| 81 | return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme; | ||
| 82 | } | ||
| 83 | |||
| 84 | bool IsGPULevelHigh() { | ||
| 85 | return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme || | ||
| 86 | values.gpu_accuracy.GetValue() == GPUAccuracy::High; | ||
| 87 | } | ||
| 88 | |||
| 89 | float Volume() { | ||
| 90 | if (values.audio_muted) { | ||
| 91 | return 0.0f; | ||
| 92 | } | ||
| 93 | return values.volume.GetValue(); | ||
| 94 | } | ||
| 95 | |||
| 96 | void RestoreGlobalState(bool is_powered_on) { | ||
| 97 | // If a game is running, DO NOT restore the global settings state | ||
| 98 | if (is_powered_on) { | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | // Audio | ||
| 103 | values.enable_audio_stretching.SetGlobal(true); | ||
| 104 | values.volume.SetGlobal(true); | ||
| 105 | |||
| 106 | // Core | ||
| 107 | values.use_multi_core.SetGlobal(true); | ||
| 108 | |||
| 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_frame_limit.SetGlobal(true); | ||
| 115 | values.frame_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.use_nvdec_emulation.SetGlobal(true); | ||
| 120 | values.use_vsync.SetGlobal(true); | ||
| 121 | values.use_assembly_shaders.SetGlobal(true); | ||
| 122 | values.use_asynchronous_shaders.SetGlobal(true); | ||
| 123 | values.use_fast_gpu_time.SetGlobal(true); | ||
| 124 | values.bg_red.SetGlobal(true); | ||
| 125 | values.bg_green.SetGlobal(true); | ||
| 126 | values.bg_blue.SetGlobal(true); | ||
| 127 | |||
| 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.custom_rtc.SetGlobal(true); | ||
| 134 | values.sound_index.SetGlobal(true); | ||
| 135 | |||
| 136 | // Controls | ||
| 137 | values.players.SetGlobal(true); | ||
| 138 | values.use_docked_mode.SetGlobal(true); | ||
| 139 | values.vibration_enabled.SetGlobal(true); | ||
| 140 | values.motion_enabled.SetGlobal(true); | ||
| 141 | } | ||
| 142 | |||
| 143 | } // namespace Settings | ||