settings,uisettings: Add IDs to settings

This commit is contained in:
lat9nq 2023-05-07 12:51:12 -04:00
parent f8435d676f
commit bafd569b47
1 changed files with 13 additions and 3 deletions

View File

@ -191,6 +191,7 @@ public:
virtual bool IsEnum() const = 0; virtual bool IsEnum() const = 0;
virtual bool RuntimeModfiable() const = 0; virtual bool RuntimeModfiable() const = 0;
virtual void SetGlobal(bool global) {} virtual void SetGlobal(bool global) {}
virtual u32 Id() const = 0;
virtual bool UsingGlobal() const { virtual bool UsingGlobal() const {
return false; return false;
} }
@ -200,6 +201,7 @@ class Linkage {
public: public:
std::map<Category, std::forward_list<BasicSetting*>> by_category; std::map<Category, std::forward_list<BasicSetting*>> by_category;
std::vector<std::function<void()>> restore_functions; std::vector<std::function<void()>> restore_functions;
u32 count;
}; };
/** The Setting class is a simple resource manager. It defines a label and default value /** The Setting class is a simple resource manager. It defines a label and default value
@ -232,8 +234,10 @@ public:
explicit Setting(Linkage& linkage, const Type& default_val, const std::string& name, explicit Setting(Linkage& linkage, const Type& default_val, const std::string& name,
enum Category category_) enum Category category_)
requires(!ranged) requires(!ranged)
: value{default_val}, default_value{default_val}, label{name}, category{category_} { : value{default_val},
default_value{default_val}, label{name}, category{category_}, id{linkage.count} {
linkage.by_category[category].push_front(this); linkage.by_category[category].push_front(this);
linkage.count++;
} }
virtual ~Setting() = default; virtual ~Setting() = default;
@ -251,8 +255,9 @@ public:
const Type& max_val, const std::string& name, enum Category category_) const Type& max_val, const std::string& name, enum Category category_)
requires(ranged) requires(ranged)
: value{default_val}, default_value{default_val}, maximum{max_val}, minimum{min_val}, : value{default_val}, default_value{default_val}, maximum{max_val}, minimum{min_val},
label{name}, category{category_} { label{name}, category{category_}, id{linkage.count} {
linkage.by_category[category].push_front(this); linkage.by_category[category].push_front(this);
linkage.count++;
} }
/** /**
@ -418,6 +423,10 @@ public:
return std::type_index(typeid(Type)); return std::type_index(typeid(Type));
} }
virtual u32 Id() const override {
return id;
}
protected: protected:
Type value{}; ///< The setting Type value{}; ///< The setting
const Type default_value{}; ///< The default value const Type default_value{}; ///< The default value
@ -425,6 +434,7 @@ protected:
const Type minimum{}; ///< Minimum allowed value of the setting const Type minimum{}; ///< Minimum allowed value of the setting
const std::string label{}; ///< The setting's label const std::string label{}; ///< The setting's label
const enum Category category; ///< The setting's category AKA INI group const enum Category category; ///< The setting's category AKA INI group
const u32 id;
}; };
/** /**
@ -728,7 +738,7 @@ struct Values {
linkage, VSyncMode::FIFO, VSyncMode::Immediate, VSyncMode::FIFORelaxed, linkage, VSyncMode::FIFO, VSyncMode::Immediate, VSyncMode::FIFORelaxed,
"use_vsync", Category::Renderer}; "use_vsync", Category::Renderer};
SwitchableSetting<bool> use_reactive_flushing{linkage, true, "use_reactive_flushing", SwitchableSetting<bool> use_reactive_flushing{linkage, true, "use_reactive_flushing",
Category::Renderer}; Category::RendererAdvanced};
SwitchableSetting<ShaderBackend, true> shader_backend{ SwitchableSetting<ShaderBackend, true> shader_backend{
linkage, ShaderBackend::GLSL, ShaderBackend::GLSL, ShaderBackend::SPIRV, linkage, ShaderBackend::GLSL, ShaderBackend::GLSL, ShaderBackend::SPIRV,
"shader_backend", Category::Renderer}; "shader_backend", Category::Renderer};