From a007ac6b9ccc23861f5a5c6967d535220ed794b0 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Sun, 7 May 2023 09:48:26 -0400 Subject: 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. --- src/common/settings.h | 53 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'src/common/settings.h') 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 @@ namespace Settings { +enum class AnisotropyMode : u32 { + Automatic = 0, + Default = 1, + X2 = 2, + X4 = 3, + X8 = 4, + X16 = 5, +}; + enum class AstcDecodeMode : u32 { CPU = 0, GPU = 1, @@ -49,6 +58,7 @@ enum class GPUAccuracy : u32 { Normal = 0, High = 1, Extreme = 2, + MaxEnum = 3, }; enum class CPUAccuracy : u32 { @@ -166,11 +176,16 @@ public: virtual Category Category() const = 0; virtual constexpr bool Switchable() const = 0; virtual std::string ToString() const = 0; + virtual std::string ToStringGlobal() const { + return {}; + } virtual void LoadString(const std::string& load) = 0; virtual const std::string& GetLabel() const = 0; virtual std::string DefaultToString() const = 0; virtual bool Save() const = 0; virtual std::type_index TypeId() const = 0; + virtual bool IsEnum() const = 0; + virtual bool RuntimeModfiable() const = 0; virtual void SetGlobal(bool global) {} virtual bool UsingGlobal() const { return false; @@ -188,7 +203,7 @@ public: * configurations. Specifying a default value and label is required. A minimum and maximum range * can be specified for sanitization. */ -template +template class Setting : public BasicSetting { protected: Setting() = default; @@ -282,6 +297,14 @@ public: return category; } + [[nodiscard]] bool RuntimeModfiable() const override { + return runtime_modifiable; + } + + [[nodiscard]] bool IsEnum() const override { + return std::is_enum::value; + } + /** * Returns whether the current setting is Switchable. * @@ -291,7 +314,7 @@ public: return false; } -private: +protected: std::string ToString(const Type& value_) const { if constexpr (std::is_same()) { return value_; @@ -408,8 +431,8 @@ protected: * * By default, the global setting is used. */ -template -class SwitchableSetting : virtual public Setting { +template +class SwitchableSetting : virtual public Setting { public: /** * Sets a default value, label, and setting value. @@ -422,7 +445,7 @@ public: explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name, Category category) requires(!ranged) - : Setting{linkage, default_val, name, category} { + : Setting{linkage, default_val, name, category} { linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); } virtual ~SwitchableSetting() = default; @@ -440,7 +463,8 @@ public: explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val, const Type& max_val, const std::string& name, Category category) requires(ranged) - : Setting{linkage, default_val, min_val, max_val, name, category} { + : Setting{linkage, default_val, min_val, + max_val, name, category} { linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); } @@ -502,6 +526,10 @@ public: return true; } + [[nodiscard]] virtual std::string ToStringGlobal() const override { + return this->ToString(this->value); + } + /** * Assigns the current setting value depending on the global state. * @@ -667,15 +695,16 @@ struct Values { "fullscreen_mode", Category::Renderer}; SwitchableSetting aspect_ratio{linkage, 0, 0, 4, "aspect_ratio", Category::Renderer}; - SwitchableSetting max_anisotropy{ - linkage, 0, 0, 5, "max_anisotropy", Category::AdvancedGraphics}; + SwitchableSetting max_anisotropy{ + linkage, AnisotropyMode::Automatic, AnisotropyMode::Automatic, AnisotropyMode::X16, + "max_anisotropy", Category::AdvancedGraphics}; SwitchableSetting use_speed_limit{linkage, true, "use_speed_limit", Category::Renderer}; SwitchableSetting speed_limit{linkage, 100, 0, 9999, "speed_limit", Category::Renderer}; SwitchableSetting use_disk_shader_cache{linkage, true, "use_disk_shader_cache", Category::Renderer}; - SwitchableSetting gpu_accuracy{ + SwitchableSetting gpu_accuracy{ linkage, GPUAccuracy::High, GPUAccuracy::Normal, GPUAccuracy::Extreme, "gpu_accuracy", Category::AdvancedGraphics}; SwitchableSetting use_asynchronous_gpu_emulation{ @@ -698,9 +727,9 @@ struct Values { "shader_backend", Category::Renderer}; SwitchableSetting use_asynchronous_shaders{linkage, false, "use_asynchronous_shaders", Category::Renderer}; - SwitchableSetting use_fast_gpu_time{linkage, true, "use_fast_gpu_time", - Category::AdvancedGraphics}; - SwitchableSetting use_vulkan_driver_pipeline_cache{ + SwitchableSetting use_fast_gpu_time{linkage, true, "use_fast_gpu_time", + Category::AdvancedGraphics}; + SwitchableSetting use_vulkan_driver_pipeline_cache{ linkage, true, "use_vulkan_driver_pipeline_cache", Category::AdvancedGraphics}; SwitchableSetting enable_compute_pipelines{linkage, false, "enable_compute_pipelines", Category::AdvancedGraphics}; -- cgit v1.2.3