diff options
| author | 2023-05-07 09:48:26 -0400 | |
|---|---|---|
| committer | 2023-07-21 10:56:07 -0400 | |
| commit | a007ac6b9ccc23861f5a5c6967d535220ed794b0 (patch) | |
| tree | 934c66c124dd77a17fae07ae919335efb1107255 /src/common | |
| parent | configure_per_game: Rename group to tab_group (diff) | |
| download | yuzu-a007ac6b9ccc23861f5a5c6967d535220ed794b0.tar.gz yuzu-a007ac6b9ccc23861f5a5c6967d535220ed794b0.tar.xz yuzu-a007ac6b9ccc23861f5a5c6967d535220ed794b0.zip | |
configure_graphics_advance: Generate UI at runtime
We can iterate through the AdvancedGraphics settings and generate the UI
during runtime. This doesn't help runtime efficiency, but it helps a ton
in reducing the amount of work a developer needs in order to add a new
setting.
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/settings.h | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/src/common/settings.h b/src/common/settings.h index df4bcb053..48f86d0aa 100644 --- a/src/common/settings.h +++ b/src/common/settings.h | |||
| @@ -20,6 +20,15 @@ | |||
| 20 | 20 | ||
| 21 | namespace Settings { | 21 | namespace Settings { |
| 22 | 22 | ||
| 23 | enum class AnisotropyMode : u32 { | ||
| 24 | Automatic = 0, | ||
| 25 | Default = 1, | ||
| 26 | X2 = 2, | ||
| 27 | X4 = 3, | ||
| 28 | X8 = 4, | ||
| 29 | X16 = 5, | ||
| 30 | }; | ||
| 31 | |||
| 23 | enum class AstcDecodeMode : u32 { | 32 | enum class AstcDecodeMode : u32 { |
| 24 | CPU = 0, | 33 | CPU = 0, |
| 25 | GPU = 1, | 34 | GPU = 1, |
| @@ -49,6 +58,7 @@ enum class GPUAccuracy : u32 { | |||
| 49 | Normal = 0, | 58 | Normal = 0, |
| 50 | High = 1, | 59 | High = 1, |
| 51 | Extreme = 2, | 60 | Extreme = 2, |
| 61 | MaxEnum = 3, | ||
| 52 | }; | 62 | }; |
| 53 | 63 | ||
| 54 | enum class CPUAccuracy : u32 { | 64 | enum class CPUAccuracy : u32 { |
| @@ -166,11 +176,16 @@ public: | |||
| 166 | virtual Category Category() const = 0; | 176 | virtual Category Category() const = 0; |
| 167 | virtual constexpr bool Switchable() const = 0; | 177 | virtual constexpr bool Switchable() const = 0; |
| 168 | virtual std::string ToString() const = 0; | 178 | virtual std::string ToString() const = 0; |
| 179 | virtual std::string ToStringGlobal() const { | ||
| 180 | return {}; | ||
| 181 | } | ||
| 169 | virtual void LoadString(const std::string& load) = 0; | 182 | virtual void LoadString(const std::string& load) = 0; |
| 170 | virtual const std::string& GetLabel() const = 0; | 183 | virtual const std::string& GetLabel() const = 0; |
| 171 | virtual std::string DefaultToString() const = 0; | 184 | virtual std::string DefaultToString() const = 0; |
| 172 | virtual bool Save() const = 0; | 185 | virtual bool Save() const = 0; |
| 173 | virtual std::type_index TypeId() const = 0; | 186 | virtual std::type_index TypeId() const = 0; |
| 187 | virtual bool IsEnum() const = 0; | ||
| 188 | virtual bool RuntimeModfiable() const = 0; | ||
| 174 | virtual void SetGlobal(bool global) {} | 189 | virtual void SetGlobal(bool global) {} |
| 175 | virtual bool UsingGlobal() const { | 190 | virtual bool UsingGlobal() const { |
| 176 | return false; | 191 | return false; |
| @@ -188,7 +203,7 @@ public: | |||
| 188 | * configurations. Specifying a default value and label is required. A minimum and maximum range | 203 | * configurations. Specifying a default value and label is required. A minimum and maximum range |
| 189 | * can be specified for sanitization. | 204 | * can be specified for sanitization. |
| 190 | */ | 205 | */ |
| 191 | template <typename Type, bool ranged = false, bool save = true> | 206 | template <typename Type, bool ranged = false, bool save = true, bool runtime_modifiable = false> |
| 192 | class Setting : public BasicSetting { | 207 | class Setting : public BasicSetting { |
| 193 | protected: | 208 | protected: |
| 194 | Setting() = default; | 209 | Setting() = default; |
| @@ -282,6 +297,14 @@ public: | |||
| 282 | return category; | 297 | return category; |
| 283 | } | 298 | } |
| 284 | 299 | ||
| 300 | [[nodiscard]] bool RuntimeModfiable() const override { | ||
| 301 | return runtime_modifiable; | ||
| 302 | } | ||
| 303 | |||
| 304 | [[nodiscard]] bool IsEnum() const override { | ||
| 305 | return std::is_enum<Type>::value; | ||
| 306 | } | ||
| 307 | |||
| 285 | /** | 308 | /** |
| 286 | * Returns whether the current setting is Switchable. | 309 | * Returns whether the current setting is Switchable. |
| 287 | * | 310 | * |
| @@ -291,7 +314,7 @@ public: | |||
| 291 | return false; | 314 | return false; |
| 292 | } | 315 | } |
| 293 | 316 | ||
| 294 | private: | 317 | protected: |
| 295 | std::string ToString(const Type& value_) const { | 318 | std::string ToString(const Type& value_) const { |
| 296 | if constexpr (std::is_same<Type, std::string>()) { | 319 | if constexpr (std::is_same<Type, std::string>()) { |
| 297 | return value_; | 320 | return value_; |
| @@ -408,8 +431,8 @@ protected: | |||
| 408 | * | 431 | * |
| 409 | * By default, the global setting is used. | 432 | * By default, the global setting is used. |
| 410 | */ | 433 | */ |
| 411 | template <typename Type, bool ranged = false, bool save = true> | 434 | template <typename Type, bool ranged = false, bool save = true, bool runtime_modifiable = false> |
| 412 | class SwitchableSetting : virtual public Setting<Type, ranged, save> { | 435 | class SwitchableSetting : virtual public Setting<Type, ranged, save, runtime_modifiable> { |
| 413 | public: | 436 | public: |
| 414 | /** | 437 | /** |
| 415 | * Sets a default value, label, and setting value. | 438 | * Sets a default value, label, and setting value. |
| @@ -422,7 +445,7 @@ public: | |||
| 422 | explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name, | 445 | explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name, |
| 423 | Category category) | 446 | Category category) |
| 424 | requires(!ranged) | 447 | requires(!ranged) |
| 425 | : Setting<Type, false, save>{linkage, default_val, name, category} { | 448 | : Setting<Type, false, save, runtime_modifiable>{linkage, default_val, name, category} { |
| 426 | linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); | 449 | linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); |
| 427 | } | 450 | } |
| 428 | virtual ~SwitchableSetting() = default; | 451 | virtual ~SwitchableSetting() = default; |
| @@ -440,7 +463,8 @@ public: | |||
| 440 | explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val, | 463 | explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val, |
| 441 | const Type& max_val, const std::string& name, Category category) | 464 | const Type& max_val, const std::string& name, Category category) |
| 442 | requires(ranged) | 465 | requires(ranged) |
| 443 | : Setting<Type, true, save>{linkage, default_val, min_val, max_val, name, category} { | 466 | : Setting<Type, true, save, runtime_modifiable>{linkage, default_val, min_val, |
| 467 | max_val, name, category} { | ||
| 444 | linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); | 468 | linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); |
| 445 | } | 469 | } |
| 446 | 470 | ||
| @@ -502,6 +526,10 @@ public: | |||
| 502 | return true; | 526 | return true; |
| 503 | } | 527 | } |
| 504 | 528 | ||
| 529 | [[nodiscard]] virtual std::string ToStringGlobal() const override { | ||
| 530 | return this->ToString(this->value); | ||
| 531 | } | ||
| 532 | |||
| 505 | /** | 533 | /** |
| 506 | * Assigns the current setting value depending on the global state. | 534 | * Assigns the current setting value depending on the global state. |
| 507 | * | 535 | * |
| @@ -667,15 +695,16 @@ struct Values { | |||
| 667 | "fullscreen_mode", | 695 | "fullscreen_mode", |
| 668 | Category::Renderer}; | 696 | Category::Renderer}; |
| 669 | SwitchableSetting<int, true> aspect_ratio{linkage, 0, 0, 4, "aspect_ratio", Category::Renderer}; | 697 | SwitchableSetting<int, true> aspect_ratio{linkage, 0, 0, 4, "aspect_ratio", Category::Renderer}; |
| 670 | SwitchableSetting<int, true> max_anisotropy{ | 698 | SwitchableSetting<AnisotropyMode, true> max_anisotropy{ |
| 671 | linkage, 0, 0, 5, "max_anisotropy", Category::AdvancedGraphics}; | 699 | linkage, AnisotropyMode::Automatic, AnisotropyMode::Automatic, AnisotropyMode::X16, |
| 700 | "max_anisotropy", Category::AdvancedGraphics}; | ||
| 672 | SwitchableSetting<bool, false, false> use_speed_limit{linkage, true, "use_speed_limit", | 701 | SwitchableSetting<bool, false, false> use_speed_limit{linkage, true, "use_speed_limit", |
| 673 | Category::Renderer}; | 702 | Category::Renderer}; |
| 674 | SwitchableSetting<u16, true> speed_limit{linkage, 100, 0, | 703 | SwitchableSetting<u16, true> speed_limit{linkage, 100, 0, |
| 675 | 9999, "speed_limit", Category::Renderer}; | 704 | 9999, "speed_limit", Category::Renderer}; |
| 676 | SwitchableSetting<bool> use_disk_shader_cache{linkage, true, "use_disk_shader_cache", | 705 | SwitchableSetting<bool> use_disk_shader_cache{linkage, true, "use_disk_shader_cache", |
| 677 | Category::Renderer}; | 706 | Category::Renderer}; |
| 678 | SwitchableSetting<GPUAccuracy, true> gpu_accuracy{ | 707 | SwitchableSetting<GPUAccuracy, true, true, true> gpu_accuracy{ |
| 679 | linkage, GPUAccuracy::High, GPUAccuracy::Normal, GPUAccuracy::Extreme, | 708 | linkage, GPUAccuracy::High, GPUAccuracy::Normal, GPUAccuracy::Extreme, |
| 680 | "gpu_accuracy", Category::AdvancedGraphics}; | 709 | "gpu_accuracy", Category::AdvancedGraphics}; |
| 681 | SwitchableSetting<bool> use_asynchronous_gpu_emulation{ | 710 | SwitchableSetting<bool> use_asynchronous_gpu_emulation{ |
| @@ -698,9 +727,9 @@ struct Values { | |||
| 698 | "shader_backend", Category::Renderer}; | 727 | "shader_backend", Category::Renderer}; |
| 699 | SwitchableSetting<bool> use_asynchronous_shaders{linkage, false, "use_asynchronous_shaders", | 728 | SwitchableSetting<bool> use_asynchronous_shaders{linkage, false, "use_asynchronous_shaders", |
| 700 | Category::Renderer}; | 729 | Category::Renderer}; |
| 701 | SwitchableSetting<bool> use_fast_gpu_time{linkage, true, "use_fast_gpu_time", | 730 | SwitchableSetting<bool, false, true, true> use_fast_gpu_time{linkage, true, "use_fast_gpu_time", |
| 702 | Category::AdvancedGraphics}; | 731 | Category::AdvancedGraphics}; |
| 703 | SwitchableSetting<bool> use_vulkan_driver_pipeline_cache{ | 732 | SwitchableSetting<bool, false, true, true> use_vulkan_driver_pipeline_cache{ |
| 704 | linkage, true, "use_vulkan_driver_pipeline_cache", Category::AdvancedGraphics}; | 733 | linkage, true, "use_vulkan_driver_pipeline_cache", Category::AdvancedGraphics}; |
| 705 | SwitchableSetting<bool> enable_compute_pipelines{linkage, false, "enable_compute_pipelines", | 734 | SwitchableSetting<bool> enable_compute_pipelines{linkage, false, "enable_compute_pipelines", |
| 706 | Category::AdvancedGraphics}; | 735 | Category::AdvancedGraphics}; |