diff options
Diffstat (limited to 'src/common/settings.h')
| -rw-r--r-- | src/common/settings.h | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/src/common/settings.h b/src/common/settings.h new file mode 100644 index 000000000..d39b4aa45 --- /dev/null +++ b/src/common/settings.h | |||
| @@ -0,0 +1,261 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <atomic> | ||
| 9 | #include <chrono> | ||
| 10 | #include <map> | ||
| 11 | #include <optional> | ||
| 12 | #include <string> | ||
| 13 | #include <vector> | ||
| 14 | |||
| 15 | #include "common/common_types.h" | ||
| 16 | #include "common/settings_input.h" | ||
| 17 | |||
| 18 | namespace Settings { | ||
| 19 | |||
| 20 | enum class RendererBackend : u32 { | ||
| 21 | OpenGL = 0, | ||
| 22 | Vulkan = 1, | ||
| 23 | }; | ||
| 24 | |||
| 25 | enum class GPUAccuracy : u32 { | ||
| 26 | Normal = 0, | ||
| 27 | High = 1, | ||
| 28 | Extreme = 2, | ||
| 29 | }; | ||
| 30 | |||
| 31 | enum class CPUAccuracy : u32 { | ||
| 32 | Accurate = 0, | ||
| 33 | Unsafe = 1, | ||
| 34 | DebugMode = 2, | ||
| 35 | }; | ||
| 36 | |||
| 37 | template <typename Type> | ||
| 38 | class Setting final { | ||
| 39 | public: | ||
| 40 | Setting() = default; | ||
| 41 | explicit Setting(Type val) : global{val} {} | ||
| 42 | ~Setting() = default; | ||
| 43 | void SetGlobal(bool to_global) { | ||
| 44 | use_global = to_global; | ||
| 45 | } | ||
| 46 | bool UsingGlobal() const { | ||
| 47 | return use_global; | ||
| 48 | } | ||
| 49 | Type GetValue(bool need_global = false) const { | ||
| 50 | if (use_global || need_global) { | ||
| 51 | return global; | ||
| 52 | } | ||
| 53 | return local; | ||
| 54 | } | ||
| 55 | void SetValue(const Type& value) { | ||
| 56 | if (use_global) { | ||
| 57 | global = value; | ||
| 58 | } else { | ||
| 59 | local = value; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | private: | ||
| 64 | bool use_global = true; | ||
| 65 | Type global{}; | ||
| 66 | Type local{}; | ||
| 67 | }; | ||
| 68 | |||
| 69 | /** | ||
| 70 | * The InputSetting class allows for getting a reference to either the global or local members. | ||
| 71 | * This is required as we cannot easily modify the values of user-defined types within containers | ||
| 72 | * using the SetValue() member function found in the Setting class. The primary purpose of this | ||
| 73 | * class is to store an array of 10 PlayerInput structs for both the global and local (per-game) | ||
| 74 | * setting and allows for easily accessing and modifying both settings. | ||
| 75 | */ | ||
| 76 | template <typename Type> | ||
| 77 | class InputSetting final { | ||
| 78 | public: | ||
| 79 | InputSetting() = default; | ||
| 80 | explicit InputSetting(Type val) : global{val} {} | ||
| 81 | ~InputSetting() = default; | ||
| 82 | void SetGlobal(bool to_global) { | ||
| 83 | use_global = to_global; | ||
| 84 | } | ||
| 85 | bool UsingGlobal() const { | ||
| 86 | return use_global; | ||
| 87 | } | ||
| 88 | Type& GetValue(bool need_global = false) { | ||
| 89 | if (use_global || need_global) { | ||
| 90 | return global; | ||
| 91 | } | ||
| 92 | return local; | ||
| 93 | } | ||
| 94 | |||
| 95 | private: | ||
| 96 | bool use_global = true; | ||
| 97 | Type global{}; | ||
| 98 | Type local{}; | ||
| 99 | }; | ||
| 100 | |||
| 101 | struct TouchFromButtonMap { | ||
| 102 | std::string name; | ||
| 103 | std::vector<std::string> buttons; | ||
| 104 | }; | ||
| 105 | |||
| 106 | struct Values { | ||
| 107 | // Audio | ||
| 108 | std::string audio_device_id; | ||
| 109 | std::string sink_id; | ||
| 110 | bool audio_muted; | ||
| 111 | Setting<bool> enable_audio_stretching; | ||
| 112 | Setting<float> volume; | ||
| 113 | |||
| 114 | // Core | ||
| 115 | Setting<bool> use_multi_core; | ||
| 116 | |||
| 117 | // Cpu | ||
| 118 | CPUAccuracy cpu_accuracy; | ||
| 119 | |||
| 120 | bool cpuopt_page_tables; | ||
| 121 | bool cpuopt_block_linking; | ||
| 122 | bool cpuopt_return_stack_buffer; | ||
| 123 | bool cpuopt_fast_dispatcher; | ||
| 124 | bool cpuopt_context_elimination; | ||
| 125 | bool cpuopt_const_prop; | ||
| 126 | bool cpuopt_misc_ir; | ||
| 127 | bool cpuopt_reduce_misalign_checks; | ||
| 128 | |||
| 129 | bool cpuopt_unsafe_unfuse_fma; | ||
| 130 | bool cpuopt_unsafe_reduce_fp_error; | ||
| 131 | bool cpuopt_unsafe_inaccurate_nan; | ||
| 132 | |||
| 133 | // Renderer | ||
| 134 | Setting<RendererBackend> renderer_backend; | ||
| 135 | bool renderer_debug; | ||
| 136 | Setting<int> vulkan_device; | ||
| 137 | |||
| 138 | Setting<u16> resolution_factor{1}; | ||
| 139 | Setting<int> fullscreen_mode; | ||
| 140 | Setting<int> aspect_ratio; | ||
| 141 | Setting<int> max_anisotropy; | ||
| 142 | Setting<bool> use_frame_limit; | ||
| 143 | Setting<u16> frame_limit; | ||
| 144 | Setting<bool> use_disk_shader_cache; | ||
| 145 | Setting<GPUAccuracy> gpu_accuracy; | ||
| 146 | Setting<bool> use_asynchronous_gpu_emulation; | ||
| 147 | Setting<bool> use_nvdec_emulation; | ||
| 148 | Setting<bool> use_vsync; | ||
| 149 | Setting<bool> use_assembly_shaders; | ||
| 150 | Setting<bool> use_asynchronous_shaders; | ||
| 151 | Setting<bool> use_fast_gpu_time; | ||
| 152 | |||
| 153 | Setting<float> bg_red; | ||
| 154 | Setting<float> bg_green; | ||
| 155 | Setting<float> bg_blue; | ||
| 156 | |||
| 157 | // System | ||
| 158 | Setting<std::optional<u32>> rng_seed; | ||
| 159 | // Measured in seconds since epoch | ||
| 160 | Setting<std::optional<std::chrono::seconds>> custom_rtc; | ||
| 161 | // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` | ||
| 162 | std::chrono::seconds custom_rtc_differential; | ||
| 163 | |||
| 164 | s32 current_user; | ||
| 165 | Setting<s32> language_index; | ||
| 166 | Setting<s32> region_index; | ||
| 167 | Setting<s32> time_zone_index; | ||
| 168 | Setting<s32> sound_index; | ||
| 169 | |||
| 170 | // Controls | ||
| 171 | InputSetting<std::array<PlayerInput, 10>> players; | ||
| 172 | |||
| 173 | Setting<bool> use_docked_mode; | ||
| 174 | |||
| 175 | Setting<bool> vibration_enabled; | ||
| 176 | Setting<bool> enable_accurate_vibrations; | ||
| 177 | |||
| 178 | Setting<bool> motion_enabled; | ||
| 179 | std::string motion_device; | ||
| 180 | std::string udp_input_servers; | ||
| 181 | |||
| 182 | bool mouse_panning; | ||
| 183 | float mouse_panning_sensitivity; | ||
| 184 | bool mouse_enabled; | ||
| 185 | std::string mouse_device; | ||
| 186 | MouseButtonsRaw mouse_buttons; | ||
| 187 | |||
| 188 | bool emulate_analog_keyboard; | ||
| 189 | bool keyboard_enabled; | ||
| 190 | KeyboardKeysRaw keyboard_keys; | ||
| 191 | KeyboardModsRaw keyboard_mods; | ||
| 192 | |||
| 193 | bool debug_pad_enabled; | ||
| 194 | ButtonsRaw debug_pad_buttons; | ||
| 195 | AnalogsRaw debug_pad_analogs; | ||
| 196 | |||
| 197 | TouchscreenInput touchscreen; | ||
| 198 | |||
| 199 | bool use_touch_from_button; | ||
| 200 | std::string touch_device; | ||
| 201 | int touch_from_button_map_index; | ||
| 202 | std::vector<TouchFromButtonMap> touch_from_button_maps; | ||
| 203 | |||
| 204 | std::atomic_bool is_device_reload_pending{true}; | ||
| 205 | |||
| 206 | // Data Storage | ||
| 207 | bool use_virtual_sd; | ||
| 208 | bool gamecard_inserted; | ||
| 209 | bool gamecard_current_game; | ||
| 210 | std::string gamecard_path; | ||
| 211 | |||
| 212 | // Debugging | ||
| 213 | bool record_frame_times; | ||
| 214 | bool use_gdbstub; | ||
| 215 | u16 gdbstub_port; | ||
| 216 | std::string program_args; | ||
| 217 | bool dump_exefs; | ||
| 218 | bool dump_nso; | ||
| 219 | bool reporting_services; | ||
| 220 | bool quest_flag; | ||
| 221 | bool disable_macro_jit; | ||
| 222 | bool extended_logging; | ||
| 223 | bool use_debug_asserts; | ||
| 224 | bool use_auto_stub; | ||
| 225 | |||
| 226 | // Miscellaneous | ||
| 227 | std::string log_filter; | ||
| 228 | bool use_dev_keys; | ||
| 229 | |||
| 230 | // Services | ||
| 231 | std::string bcat_backend; | ||
| 232 | bool bcat_boxcat_local; | ||
| 233 | |||
| 234 | // WebService | ||
| 235 | bool enable_telemetry; | ||
| 236 | std::string web_api_url; | ||
| 237 | std::string yuzu_username; | ||
| 238 | std::string yuzu_token; | ||
| 239 | |||
| 240 | // Add-Ons | ||
| 241 | std::map<u64, std::vector<std::string>> disabled_addons; | ||
| 242 | }; | ||
| 243 | |||
| 244 | extern Values values; | ||
| 245 | |||
| 246 | bool IsConfiguringGlobal(); | ||
| 247 | void SetConfiguringGlobal(bool is_global); | ||
| 248 | |||
| 249 | bool IsGPULevelExtreme(); | ||
| 250 | bool IsGPULevelHigh(); | ||
| 251 | |||
| 252 | float Volume(); | ||
| 253 | |||
| 254 | std::string GetTimeZoneString(); | ||
| 255 | |||
| 256 | void LogSettings(); | ||
| 257 | |||
| 258 | // Restore the global state of all applicable settings in the Values struct | ||
| 259 | void RestoreGlobalState(bool is_powered_on); | ||
| 260 | |||
| 261 | } // namespace Settings | ||