From 0098ecb6090b767f13683136c28fee97b8b127c7 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 13 Sep 2023 13:31:46 -0400 Subject: [PATCH] settings: Retro-port Citra Settings work This has yet to be PR'd on Citra, but regressions on yuzu that have been fixed in Citra needed to appear here. --- src/common/settings_common.h | 10 ++++++++++ src/common/settings_setting.h | 36 +++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/common/settings_common.h b/src/common/settings_common.h index 5b170dfd5..067234aab 100644 --- a/src/common/settings_common.h +++ b/src/common/settings_common.h @@ -225,6 +225,16 @@ public: */ [[nodiscard]] virtual constexpr u32 EnumIndex() const = 0; + /** + * @returns True if the underlying type is a floating point storage + */ + [[nodiscard]] virtual constexpr bool IsFloatingPoint() const = 0; + + /** + * @returns True if the underlying type is a integer storage + */ + [[nodiscard]] virtual constexpr bool IsIntegral() const = 0; + /* * Switchable settings */ diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h index e10843c73..79d2b715f 100644 --- a/src/common/settings_setting.h +++ b/src/common/settings_setting.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "common/common_types.h" #include "common/settings_common.h" #include "common/settings_enums.h" @@ -112,11 +113,12 @@ protected: return value_.has_value() ? std::to_string(*value_) : "none"; } else if constexpr (std::is_same_v) { return value_ ? "true" : "false"; - } else if constexpr (std::is_same_v) { - // Compatibility with old AudioEngine setting being a string - return CanonicalizeEnum(value_); + } else if constexpr (std::is_floating_point_v) { + return fmt::format("{:f}", value_); + } else if constexpr (std::is_enum_v) { + return std::to_string(static_cast(value_)); } else { - return std::to_string(static_cast(value_)); + return std::to_string(value_); } } @@ -180,13 +182,15 @@ public: this->SetValue(static_cast(std::stoul(input))); } else if constexpr (std::is_same_v) { this->SetValue(input == "true"); - } else if constexpr (std::is_same_v) { - this->SetValue(ToEnum(input)); + } else if constexpr (std::is_same_v) { + this->SetValue(std::stof(input)); } else { this->SetValue(static_cast(std::stoll(input))); } } catch (std::invalid_argument&) { this->SetValue(this->GetDefault()); + } catch (std::out_of_range&) { + this->SetValue(this->GetDefault()); } } @@ -215,11 +219,27 @@ public: } } + [[nodiscard]] constexpr bool IsFloatingPoint() const final { + return std::is_floating_point_v; + } + + [[nodiscard]] constexpr bool IsIntegral() const final { + return std::is_integral_v; + } + [[nodiscard]] std::string MinVal() const override final { - return this->ToString(minimum); + if constexpr (std::is_arithmetic_v && !ranged) { + return this->ToString(std::numeric_limits::min()); + } else { + return this->ToString(minimum); + } } [[nodiscard]] std::string MaxVal() const override final { - return this->ToString(maximum); + if constexpr (std::is_arithmetic_v && !ranged) { + return this->ToString(std::numeric_limits::max()); + } else { + return this->ToString(maximum); + } } [[nodiscard]] constexpr bool Ranged() const override {