settings: Define paired settings

settings_common: Remove unused optional
This commit is contained in:
lat9nq 2023-06-21 04:32:13 -04:00
parent d1de1c3bed
commit 7f708e8d77
4 changed files with 49 additions and 21 deletions

View file

@ -150,9 +150,16 @@ struct Values {
linkage, false, "use_unsafe_extended_memory_layout", Category::Core}; linkage, false, "use_unsafe_extended_memory_layout", Category::Core};
SwitchableSetting<bool> use_speed_limit{ SwitchableSetting<bool> use_speed_limit{
linkage, true, "use_speed_limit", Category::Core, Specialization::Paired, false, true}; linkage, true, "use_speed_limit", Category::Core, Specialization::Paired, false, true};
SwitchableSetting<u16, true> speed_limit{ SwitchableSetting<u16, true> speed_limit{linkage,
linkage, 100, 0, 9999, "speed_limit", Category::Core, Specialization::Countable, 100,
true, true}; 0,
9999,
"speed_limit",
Category::Core,
Specialization::Countable,
true,
true,
&use_speed_limit};
// Cpu // Cpu
SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto, SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto,
@ -339,13 +346,15 @@ struct Values {
SwitchableSetting<bool> custom_rtc_enabled{ SwitchableSetting<bool> custom_rtc_enabled{
linkage, false, "custom_rtc_enabled", Category::System, Specialization::Paired, true, true}; linkage, false, "custom_rtc_enabled", Category::System, Specialization::Paired, true, true};
SwitchableSetting<s64> custom_rtc{ SwitchableSetting<s64> custom_rtc{
linkage, 0, "custom_rtc", Category::System, Specialization::Time, true, true}; linkage, 0, "custom_rtc", Category::System, Specialization::Time,
true, true, &custom_rtc_enabled};
// Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
s64 custom_rtc_differential; s64 custom_rtc_differential;
SwitchableSetting<bool> rng_seed_enabled{ SwitchableSetting<bool> rng_seed_enabled{
linkage, false, "rng_seed_enabled", Category::System, Specialization::Paired, true, true}; linkage, false, "rng_seed_enabled", Category::System, Specialization::Paired, true, true};
SwitchableSetting<u32> rng_seed{linkage, 0, "rng_seed", Category::System, Specialization::Hex, SwitchableSetting<u32> rng_seed{
true, true}; linkage, 0, "rng_seed", Category::System, Specialization::Hex,
true, true, &rng_seed_enabled};
Setting<std::string> device_name{ Setting<std::string> device_name{
linkage, "yuzu", "device_name", Category::System, Specialization::Default, true, true}; linkage, "yuzu", "device_name", Category::System, Specialization::Default, true, true};

View file

@ -8,9 +8,10 @@ namespace Settings {
BasicSetting::BasicSetting(Linkage& linkage, const std::string& name, enum Category category_, BasicSetting::BasicSetting(Linkage& linkage, const std::string& name, enum Category category_,
bool save_, bool runtime_modifiable_, bool save_, bool runtime_modifiable_,
enum Specialization specialization_) enum Specialization specialization_, BasicSetting* other_setting_)
: label{name}, category{category_}, id{linkage.count}, save{save_}, : label{name}, category{category_}, id{linkage.count}, save{save_},
runtime_modifiable{runtime_modifiable_}, specialization{specialization_} { runtime_modifiable{runtime_modifiable_}, specialization{specialization_},
other_setting{other_setting_} {
linkage.by_category[category].push_front(this); linkage.by_category[category].push_front(this);
linkage.count++; linkage.count++;
} }
@ -43,6 +44,10 @@ Specialization BasicSetting::Specialization() const {
return specialization; return specialization;
} }
BasicSetting* BasicSetting::PairedSetting() const {
return other_setting;
}
const std::string& BasicSetting::GetLabel() const { const std::string& BasicSetting::GetLabel() const {
return label; return label;
} }

View file

@ -75,7 +75,8 @@ public:
class BasicSetting { class BasicSetting {
protected: protected:
explicit BasicSetting(Linkage& linkage, const std::string& name, enum Category category_, explicit BasicSetting(Linkage& linkage, const std::string& name, enum Category category_,
bool save_, bool runtime_modifiable_, Specialization spec); bool save_, bool runtime_modifiable_, Specialization spec,
BasicSetting* other_setting);
public: public:
virtual ~BasicSetting(); virtual ~BasicSetting();
@ -196,6 +197,11 @@ public:
*/ */
[[nodiscard]] enum Specialization Specialization() const; [[nodiscard]] enum Specialization Specialization() const;
/**
* @returns Another BasicSetting if one is paired, or nullptr otherwise.
*/
[[nodiscard]] BasicSetting* PairedSetting() const;
/** /**
* Returns the label this setting was created with. * Returns the label this setting was created with.
* *
@ -236,7 +242,8 @@ private:
const bool const bool
runtime_modifiable; ///< Suggests if the setting can be modified while a guest is running runtime_modifiable; ///< Suggests if the setting can be modified while a guest is running
const enum Specialization const enum Specialization
specialization; ///< Extra data to identify representation of a setting specialization; ///< Extra data to identify representation of a setting
BasicSetting* const other_setting; ///< A paired setting
}; };
} // namespace Settings } // namespace Settings

View file

@ -37,9 +37,11 @@ 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_,
enum Specialization specialization = Specialization::Default, enum Specialization specialization = Specialization::Default,
bool save_ = true, bool runtime_modifiable_ = false) bool save_ = true, bool runtime_modifiable_ = false,
BasicSetting* other_setting = nullptr)
requires(!ranged) requires(!ranged)
: BasicSetting(linkage, name, category_, save_, runtime_modifiable_, specialization), : BasicSetting(linkage, name, category_, save_, runtime_modifiable_, specialization,
other_setting),
value{default_val}, default_value{default_val} {} value{default_val}, default_value{default_val} {}
virtual ~Setting() = default; virtual ~Setting() = default;
@ -56,9 +58,11 @@ public:
explicit Setting(Linkage& linkage, const Type& default_val, const Type& min_val, explicit Setting(Linkage& linkage, const Type& default_val, const Type& min_val,
const Type& max_val, const std::string& name, enum Category category_, const Type& max_val, const std::string& name, enum Category category_,
enum Specialization specialization = Specialization::Default, enum Specialization specialization = Specialization::Default,
bool save_ = true, bool runtime_modifiable_ = false) bool save_ = true, bool runtime_modifiable_ = false,
BasicSetting* other_setting = nullptr)
requires(ranged) requires(ranged)
: BasicSetting(linkage, name, category_, save_, runtime_modifiable_, specialization), : BasicSetting(linkage, name, category_, save_, runtime_modifiable_, specialization,
other_setting),
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} {}
/** /**
@ -235,10 +239,12 @@ public:
explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name, explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name,
Category category_, Category category_,
enum Specialization specialization = Specialization::Default, enum Specialization specialization = Specialization::Default,
bool save_ = true, bool runtime_modifiable_ = false) bool save_ = true, bool runtime_modifiable_ = false,
BasicSetting* other_setting = nullptr)
requires(!ranged) requires(!ranged)
: Setting<Type, false>{linkage, default_val, name, category_, specialization, : Setting<Type, false>{
save_, runtime_modifiable_} { linkage, default_val, name, category_, specialization,
save_, runtime_modifiable_, other_setting} {
linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); });
} }
virtual ~SwitchableSetting() = default; virtual ~SwitchableSetting() = default;
@ -256,11 +262,12 @@ public:
explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val, explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val,
const Type& max_val, const std::string& name, Category category_, const Type& max_val, const std::string& name, Category category_,
enum Specialization specialization = Specialization::Default, enum Specialization specialization = Specialization::Default,
bool save_ = true, bool runtime_modifiable_ = false) bool save_ = true, bool runtime_modifiable_ = false,
BasicSetting* other_setting = nullptr)
requires(ranged) requires(ranged)
: Setting<Type, true>{linkage, default_val, min_val, : Setting<Type, true>{
max_val, name, category_, linkage, default_val, min_val, max_val, name, category_, specialization,
specialization, save_, runtime_modifiable_} { save_, runtime_modifiable_, other_setting} {
linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); }); linkage.restore_functions.emplace_back([this]() { this->SetGlobal(true); });
} }