summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar lat9nq2023-09-13 13:31:46 -0400
committerGravatar lat9nq2023-09-13 13:36:25 -0400
commit0098ecb6090b767f13683136c28fee97b8b127c7 (patch)
tree33545276b9a19d2e503ae5effd49cdfa737ecc80 /src
parentandroid/config: Remove uncaught usage of stoul (diff)
downloadyuzu-0098ecb6090b767f13683136c28fee97b8b127c7.tar.gz
yuzu-0098ecb6090b767f13683136c28fee97b8b127c7.tar.xz
yuzu-0098ecb6090b767f13683136c28fee97b8b127c7.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/common/settings_common.h10
-rw-r--r--src/common/settings_setting.h36
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:
225 */ 225 */
226 [[nodiscard]] virtual constexpr u32 EnumIndex() const = 0; 226 [[nodiscard]] virtual constexpr u32 EnumIndex() const = 0;
227 227
228 /**
229 * @returns True if the underlying type is a floating point storage
230 */
231 [[nodiscard]] virtual constexpr bool IsFloatingPoint() const = 0;
232
233 /**
234 * @returns True if the underlying type is a integer storage
235 */
236 [[nodiscard]] virtual constexpr bool IsIntegral() const = 0;
237
228 /* 238 /*
229 * Switchable settings 239 * Switchable settings
230 */ 240 */
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 @@
10#include <string> 10#include <string>
11#include <typeindex> 11#include <typeindex>
12#include <typeinfo> 12#include <typeinfo>
13#include <fmt/core.h>
13#include "common/common_types.h" 14#include "common/common_types.h"
14#include "common/settings_common.h" 15#include "common/settings_common.h"
15#include "common/settings_enums.h" 16#include "common/settings_enums.h"
@@ -112,11 +113,12 @@ protected:
112 return value_.has_value() ? std::to_string(*value_) : "none"; 113 return value_.has_value() ? std::to_string(*value_) : "none";
113 } else if constexpr (std::is_same_v<Type, bool>) { 114 } else if constexpr (std::is_same_v<Type, bool>) {
114 return value_ ? "true" : "false"; 115 return value_ ? "true" : "false";
115 } else if constexpr (std::is_same_v<Type, AudioEngine>) { 116 } else if constexpr (std::is_floating_point_v<Type>) {
116 // Compatibility with old AudioEngine setting being a string 117 return fmt::format("{:f}", value_);
117 return CanonicalizeEnum(value_); 118 } else if constexpr (std::is_enum_v<Type>) {
119 return std::to_string(static_cast<u32>(value_));
118 } else { 120 } else {
119 return std::to_string(static_cast<u64>(value_)); 121 return std::to_string(value_);
120 } 122 }
121 } 123 }
122 124
@@ -180,13 +182,15 @@ public:
180 this->SetValue(static_cast<u32>(std::stoul(input))); 182 this->SetValue(static_cast<u32>(std::stoul(input)));
181 } else if constexpr (std::is_same_v<Type, bool>) { 183 } else if constexpr (std::is_same_v<Type, bool>) {
182 this->SetValue(input == "true"); 184 this->SetValue(input == "true");
183 } else if constexpr (std::is_same_v<Type, AudioEngine>) { 185 } else if constexpr (std::is_same_v<Type, float>) {
184 this->SetValue(ToEnum<Type>(input)); 186 this->SetValue(std::stof(input));
185 } else { 187 } else {
186 this->SetValue(static_cast<Type>(std::stoll(input))); 188 this->SetValue(static_cast<Type>(std::stoll(input)));
187 } 189 }
188 } catch (std::invalid_argument&) { 190 } catch (std::invalid_argument&) {
189 this->SetValue(this->GetDefault()); 191 this->SetValue(this->GetDefault());
192 } catch (std::out_of_range&) {
193 this->SetValue(this->GetDefault());
190 } 194 }
191 } 195 }
192 196
@@ -215,11 +219,27 @@ public:
215 } 219 }
216 } 220 }
217 221
222 [[nodiscard]] constexpr bool IsFloatingPoint() const final {
223 return std::is_floating_point_v<Type>;
224 }
225
226 [[nodiscard]] constexpr bool IsIntegral() const final {
227 return std::is_integral_v<Type>;
228 }
229
218 [[nodiscard]] std::string MinVal() const override final { 230 [[nodiscard]] std::string MinVal() const override final {
219 return this->ToString(minimum); 231 if constexpr (std::is_arithmetic_v<Type> && !ranged) {
232 return this->ToString(std::numeric_limits<Type>::min());
233 } else {
234 return this->ToString(minimum);
235 }
220 } 236 }
221 [[nodiscard]] std::string MaxVal() const override final { 237 [[nodiscard]] std::string MaxVal() const override final {
222 return this->ToString(maximum); 238 if constexpr (std::is_arithmetic_v<Type> && !ranged) {
239 return this->ToString(std::numeric_limits<Type>::max());
240 } else {
241 return this->ToString(maximum);
242 }
223 } 243 }
224 244
225 [[nodiscard]] constexpr bool Ranged() const override { 245 [[nodiscard]] constexpr bool Ranged() const override {