summaryrefslogtreecommitdiff
path: root/src/common/settings.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/settings.h')
-rw-r--r--src/common/settings.h67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/common/settings.h b/src/common/settings.h
index 3583a2e70..2bccb8642 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -106,7 +106,7 @@ struct ResolutionScalingInfo {
106 * configurations. Specifying a default value and label is required. A minimum and maximum range can 106 * configurations. Specifying a default value and label is required. A minimum and maximum range can
107 * be specified for sanitization. 107 * be specified for sanitization.
108 */ 108 */
109template <typename Type> 109template <typename Type, bool ranged = false>
110class Setting { 110class Setting {
111protected: 111protected:
112 Setting() = default; 112 Setting() = default;
@@ -126,8 +126,8 @@ public:
126 * @param default_val Intial value of the setting, and default value of the setting 126 * @param default_val Intial value of the setting, and default value of the setting
127 * @param name Label for the setting 127 * @param name Label for the setting
128 */ 128 */
129 explicit Setting(const Type& default_val, const std::string& name) 129 explicit Setting(const Type& default_val, const std::string& name) requires(!ranged)
130 : value{default_val}, default_value{default_val}, ranged{false}, label{name} {} 130 : value{default_val}, default_value{default_val}, label{name} {}
131 virtual ~Setting() = default; 131 virtual ~Setting() = default;
132 132
133 /** 133 /**
@@ -139,9 +139,9 @@ public:
139 * @param name Label for the setting 139 * @param name Label for the setting
140 */ 140 */
141 explicit Setting(const Type& default_val, const Type& min_val, const Type& max_val, 141 explicit Setting(const Type& default_val, const Type& min_val, const Type& max_val,
142 const std::string& name) 142 const std::string& name) requires(ranged)
143 : value{default_val}, default_value{default_val}, maximum{max_val}, minimum{min_val}, 143 : value{default_val},
144 ranged{true}, label{name} {} 144 default_value{default_val}, maximum{max_val}, minimum{min_val}, label{name} {}
145 145
146 /** 146 /**
147 * Returns a reference to the setting's value. 147 * Returns a reference to the setting's value.
@@ -158,7 +158,7 @@ public:
158 * @param val The desired value 158 * @param val The desired value
159 */ 159 */
160 virtual void SetValue(const Type& val) { 160 virtual void SetValue(const Type& val) {
161 Type temp{(ranged) ? std::clamp(val, minimum, maximum) : val}; 161 Type temp{ranged ? std::clamp(val, minimum, maximum) : val};
162 std::swap(value, temp); 162 std::swap(value, temp);
163 } 163 }
164 164
@@ -188,7 +188,7 @@ public:
188 * @returns A reference to the setting 188 * @returns A reference to the setting
189 */ 189 */
190 virtual const Type& operator=(const Type& val) { 190 virtual const Type& operator=(const Type& val) {
191 Type temp{(ranged) ? std::clamp(val, minimum, maximum) : val}; 191 Type temp{ranged ? std::clamp(val, minimum, maximum) : val};
192 std::swap(value, temp); 192 std::swap(value, temp);
193 return value; 193 return value;
194 } 194 }
@@ -207,7 +207,6 @@ protected:
207 const Type default_value{}; ///< The default value 207 const Type default_value{}; ///< The default value
208 const Type maximum{}; ///< Maximum allowed value of the setting 208 const Type maximum{}; ///< Maximum allowed value of the setting
209 const Type minimum{}; ///< Minimum allowed value of the setting 209 const Type minimum{}; ///< Minimum allowed value of the setting
210 const bool ranged; ///< The setting has sanitization ranges
211 const std::string label{}; ///< The setting's label 210 const std::string label{}; ///< The setting's label
212}; 211};
213 212
@@ -219,8 +218,8 @@ protected:
219 * 218 *
220 * By default, the global setting is used. 219 * By default, the global setting is used.
221 */ 220 */
222template <typename Type> 221template <typename Type, bool ranged = false>
223class SwitchableSetting : virtual public Setting<Type> { 222class SwitchableSetting : virtual public Setting<Type, ranged> {
224public: 223public:
225 /** 224 /**
226 * Sets a default value, label, and setting value. 225 * Sets a default value, label, and setting value.
@@ -228,7 +227,7 @@ public:
228 * @param default_val Intial value of the setting, and default value of the setting 227 * @param default_val Intial value of the setting, and default value of the setting
229 * @param name Label for the setting 228 * @param name Label for the setting
230 */ 229 */
231 explicit SwitchableSetting(const Type& default_val, const std::string& name) 230 explicit SwitchableSetting(const Type& default_val, const std::string& name) requires(!ranged)
232 : Setting<Type>{default_val, name} {} 231 : Setting<Type>{default_val, name} {}
233 virtual ~SwitchableSetting() = default; 232 virtual ~SwitchableSetting() = default;
234 233
@@ -241,8 +240,8 @@ public:
241 * @param name Label for the setting 240 * @param name Label for the setting
242 */ 241 */
243 explicit SwitchableSetting(const Type& default_val, const Type& min_val, const Type& max_val, 242 explicit SwitchableSetting(const Type& default_val, const Type& min_val, const Type& max_val,
244 const std::string& name) 243 const std::string& name) requires(ranged)
245 : Setting<Type>{default_val, min_val, max_val, name} {} 244 : Setting<Type, true>{default_val, min_val, max_val, name} {}
246 245
247 /** 246 /**
248 * Tells this setting to represent either the global or custom setting when other member 247 * Tells this setting to represent either the global or custom setting when other member
@@ -290,7 +289,7 @@ public:
290 * @param val The new value 289 * @param val The new value
291 */ 290 */
292 void SetValue(const Type& val) override { 291 void SetValue(const Type& val) override {
293 Type temp{(this->ranged) ? std::clamp(val, this->minimum, this->maximum) : val}; 292 Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val};
294 if (use_global) { 293 if (use_global) {
295 std::swap(this->value, temp); 294 std::swap(this->value, temp);
296 } else { 295 } else {
@@ -306,7 +305,7 @@ public:
306 * @returns A reference to the current setting value 305 * @returns A reference to the current setting value
307 */ 306 */
308 const Type& operator=(const Type& val) override { 307 const Type& operator=(const Type& val) override {
309 Type temp{(this->ranged) ? std::clamp(val, this->minimum, this->maximum) : val}; 308 Type temp{ranged ? std::clamp(val, this->minimum, this->maximum) : val};
310 if (use_global) { 309 if (use_global) {
311 std::swap(this->value, temp); 310 std::swap(this->value, temp);
312 return this->value; 311 return this->value;
@@ -374,15 +373,15 @@ struct Values {
374 Setting<std::string> audio_device_id{"auto", "output_device"}; 373 Setting<std::string> audio_device_id{"auto", "output_device"};
375 Setting<std::string> sink_id{"auto", "output_engine"}; 374 Setting<std::string> sink_id{"auto", "output_engine"};
376 Setting<bool> audio_muted{false, "audio_muted"}; 375 Setting<bool> audio_muted{false, "audio_muted"};
377 SwitchableSetting<u8> volume{100, 0, 100, "volume"}; 376 SwitchableSetting<u8, true> volume{100, 0, 100, "volume"};
378 377
379 // Core 378 // Core
380 SwitchableSetting<bool> use_multi_core{true, "use_multi_core"}; 379 SwitchableSetting<bool> use_multi_core{true, "use_multi_core"};
381 SwitchableSetting<bool> use_extended_memory_layout{false, "use_extended_memory_layout"}; 380 SwitchableSetting<bool> use_extended_memory_layout{false, "use_extended_memory_layout"};
382 381
383 // Cpu 382 // Cpu
384 SwitchableSetting<CPUAccuracy> cpu_accuracy{CPUAccuracy::Auto, CPUAccuracy::Auto, 383 SwitchableSetting<CPUAccuracy, true> cpu_accuracy{CPUAccuracy::Auto, CPUAccuracy::Auto,
385 CPUAccuracy::Paranoid, "cpu_accuracy"}; 384 CPUAccuracy::Paranoid, "cpu_accuracy"};
386 // TODO: remove cpu_accuracy_first_time, migration setting added 8 July 2021 385 // TODO: remove cpu_accuracy_first_time, migration setting added 8 July 2021
387 Setting<bool> cpu_accuracy_first_time{true, "cpu_accuracy_first_time"}; 386 Setting<bool> cpu_accuracy_first_time{true, "cpu_accuracy_first_time"};
388 Setting<bool> cpu_debug_mode{false, "cpu_debug_mode"}; 387 Setting<bool> cpu_debug_mode{false, "cpu_debug_mode"};
@@ -409,7 +408,7 @@ struct Values {
409 true, "cpuopt_unsafe_ignore_global_monitor"}; 408 true, "cpuopt_unsafe_ignore_global_monitor"};
410 409
411 // Renderer 410 // Renderer
412 SwitchableSetting<RendererBackend> renderer_backend{ 411 SwitchableSetting<RendererBackend, true> renderer_backend{
413 RendererBackend::Vulkan, RendererBackend::OpenGL, RendererBackend::Vulkan, "backend"}; 412 RendererBackend::Vulkan, RendererBackend::OpenGL, RendererBackend::Vulkan, "backend"};
414 Setting<bool> renderer_debug{false, "debug"}; 413 Setting<bool> renderer_debug{false, "debug"};
415 Setting<bool> renderer_shader_feedback{false, "shader_feedback"}; 414 Setting<bool> renderer_shader_feedback{false, "shader_feedback"};
@@ -423,28 +422,26 @@ struct Values {
423 SwitchableSetting<AntiAliasing> anti_aliasing{AntiAliasing::None, "anti_aliasing"}; 422 SwitchableSetting<AntiAliasing> anti_aliasing{AntiAliasing::None, "anti_aliasing"};
424 // *nix platforms may have issues with the borderless windowed fullscreen mode. 423 // *nix platforms may have issues with the borderless windowed fullscreen mode.
425 // Default to exclusive fullscreen on these platforms for now. 424 // Default to exclusive fullscreen on these platforms for now.
426 SwitchableSetting<FullscreenMode> fullscreen_mode{ 425 SwitchableSetting<FullscreenMode, true> fullscreen_mode{
427#ifdef _WIN32 426#ifdef _WIN32
428 FullscreenMode::Borderless, 427 FullscreenMode::Borderless,
429#else 428#else
430 FullscreenMode::Exclusive, 429 FullscreenMode::Exclusive,
431#endif 430#endif
432 FullscreenMode::Borderless, FullscreenMode::Exclusive, "fullscreen_mode"}; 431 FullscreenMode::Borderless, FullscreenMode::Exclusive, "fullscreen_mode"};
433 SwitchableSetting<int> aspect_ratio{0, 0, 3, "aspect_ratio"}; 432 SwitchableSetting<int, true> aspect_ratio{0, 0, 3, "aspect_ratio"};
434 SwitchableSetting<int> max_anisotropy{0, 0, 5, "max_anisotropy"}; 433 SwitchableSetting<int, true> max_anisotropy{0, 0, 5, "max_anisotropy"};
435 SwitchableSetting<bool> use_speed_limit{true, "use_speed_limit"}; 434 SwitchableSetting<bool> use_speed_limit{true, "use_speed_limit"};
436 SwitchableSetting<u16> speed_limit{100, 0, 9999, "speed_limit"}; 435 SwitchableSetting<u16, true> speed_limit{100, 0, 9999, "speed_limit"};
437 SwitchableSetting<bool> use_disk_shader_cache{true, "use_disk_shader_cache"}; 436 SwitchableSetting<bool> use_disk_shader_cache{true, "use_disk_shader_cache"};
438 SwitchableSetting<GPUAccuracy> gpu_accuracy{GPUAccuracy::High, GPUAccuracy::Normal, 437 SwitchableSetting<GPUAccuracy, true> gpu_accuracy{GPUAccuracy::High, GPUAccuracy::Normal,
439 GPUAccuracy::Extreme, "gpu_accuracy"}; 438 GPUAccuracy::Extreme, "gpu_accuracy"};
440 SwitchableSetting<bool> use_asynchronous_gpu_emulation{true, "use_asynchronous_gpu_emulation"}; 439 SwitchableSetting<bool> use_asynchronous_gpu_emulation{true, "use_asynchronous_gpu_emulation"};
441 SwitchableSetting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"}; 440 SwitchableSetting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"};
442 SwitchableSetting<bool> accelerate_astc{true, "accelerate_astc"}; 441 SwitchableSetting<bool> accelerate_astc{true, "accelerate_astc"};
443 SwitchableSetting<bool> use_vsync{true, "use_vsync"}; 442 SwitchableSetting<bool> use_vsync{true, "use_vsync"};
444 SwitchableSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"}; 443 SwitchableSetting<ShaderBackend, true> shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL,
445 Setting<bool> disable_fps_limit{false, "disable_fps_limit"}; 444 ShaderBackend::SPIRV, "shader_backend"};
446 SwitchableSetting<ShaderBackend> shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL,
447 ShaderBackend::SPIRV, "shader_backend"};
448 SwitchableSetting<bool> use_asynchronous_shaders{false, "use_asynchronous_shaders"}; 445 SwitchableSetting<bool> use_asynchronous_shaders{false, "use_asynchronous_shaders"};
449 SwitchableSetting<bool> use_fast_gpu_time{true, "use_fast_gpu_time"}; 446 SwitchableSetting<bool> use_fast_gpu_time{true, "use_fast_gpu_time"};
450 447
@@ -460,10 +457,10 @@ struct Values {
460 s64 custom_rtc_differential; 457 s64 custom_rtc_differential;
461 458
462 Setting<s32> current_user{0, "current_user"}; 459 Setting<s32> current_user{0, "current_user"};
463 SwitchableSetting<s32> language_index{1, 0, 17, "language_index"}; 460 SwitchableSetting<s32, true> language_index{1, 0, 17, "language_index"};
464 SwitchableSetting<s32> region_index{1, 0, 6, "region_index"}; 461 SwitchableSetting<s32, true> region_index{1, 0, 6, "region_index"};
465 SwitchableSetting<s32> time_zone_index{0, 0, 45, "time_zone_index"}; 462 SwitchableSetting<s32, true> time_zone_index{0, 0, 45, "time_zone_index"};
466 SwitchableSetting<s32> sound_index{1, 0, 2, "sound_index"}; 463 SwitchableSetting<s32, true> sound_index{1, 0, 2, "sound_index"};
467 464
468 // Controls 465 // Controls
469 InputSetting<std::array<PlayerInput, 10>> players; 466 InputSetting<std::array<PlayerInput, 10>> players;
@@ -485,7 +482,7 @@ struct Values {
485 Setting<bool> tas_loop{false, "tas_loop"}; 482 Setting<bool> tas_loop{false, "tas_loop"};
486 483
487 Setting<bool> mouse_panning{false, "mouse_panning"}; 484 Setting<bool> mouse_panning{false, "mouse_panning"};
488 Setting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; 485 Setting<u8, true> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"};
489 Setting<bool> mouse_enabled{false, "mouse_enabled"}; 486 Setting<bool> mouse_enabled{false, "mouse_enabled"};
490 487
491 Setting<bool> emulate_analog_keyboard{false, "emulate_analog_keyboard"}; 488 Setting<bool> emulate_analog_keyboard{false, "emulate_analog_keyboard"};