diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/settings_common.cpp | 2 | ||||
| -rw-r--r-- | src/common/settings_enums.h | 16 | ||||
| -rw-r--r-- | src/common/settings_setting.h | 10 |
3 files changed, 15 insertions, 13 deletions
diff --git a/src/common/settings_common.cpp b/src/common/settings_common.cpp index dedf5ef90..137b65d5f 100644 --- a/src/common/settings_common.cpp +++ b/src/common/settings_common.cpp | |||
| @@ -1,7 +1,9 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #include <functional> | ||
| 4 | #include <string> | 5 | #include <string> |
| 6 | #include <vector> | ||
| 5 | #include "common/settings_common.h" | 7 | #include "common/settings_common.h" |
| 6 | 8 | ||
| 7 | namespace Settings { | 9 | namespace Settings { |
diff --git a/src/common/settings_enums.h b/src/common/settings_enums.h index a1a29ebf6..e7cb59ea5 100644 --- a/src/common/settings_enums.h +++ b/src/common/settings_enums.h | |||
| @@ -12,8 +12,8 @@ namespace Settings { | |||
| 12 | 12 | ||
| 13 | template <typename T> | 13 | template <typename T> |
| 14 | struct EnumMetadata { | 14 | struct EnumMetadata { |
| 15 | static constexpr std::vector<std::pair<std::string, T>> Canonicalizations(); | 15 | static std::vector<std::pair<std::string, T>> Canonicalizations(); |
| 16 | static constexpr u32 Index(); | 16 | static u32 Index(); |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | #define PAIR_45(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_46(N, __VA_ARGS__)) | 19 | #define PAIR_45(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_46(N, __VA_ARGS__)) |
| @@ -66,11 +66,11 @@ struct EnumMetadata { | |||
| 66 | #define ENUM(NAME, ...) \ | 66 | #define ENUM(NAME, ...) \ |
| 67 | enum class NAME : u32 { __VA_ARGS__ }; \ | 67 | enum class NAME : u32 { __VA_ARGS__ }; \ |
| 68 | template <> \ | 68 | template <> \ |
| 69 | constexpr std::vector<std::pair<std::string, NAME>> EnumMetadata<NAME>::Canonicalizations() { \ | 69 | inline std::vector<std::pair<std::string, NAME>> EnumMetadata<NAME>::Canonicalizations() { \ |
| 70 | return {PAIR(NAME, __VA_ARGS__)}; \ | 70 | return {PAIR(NAME, __VA_ARGS__)}; \ |
| 71 | } \ | 71 | } \ |
| 72 | template <> \ | 72 | template <> \ |
| 73 | constexpr u32 EnumMetadata<NAME>::Index() { \ | 73 | inline u32 EnumMetadata<NAME>::Index() { \ |
| 74 | return __COUNTER__; \ | 74 | return __COUNTER__; \ |
| 75 | } | 75 | } |
| 76 | 76 | ||
| @@ -85,7 +85,7 @@ enum class AudioEngine : u32 { | |||
| 85 | }; | 85 | }; |
| 86 | 86 | ||
| 87 | template <> | 87 | template <> |
| 88 | constexpr std::vector<std::pair<std::string, AudioEngine>> | 88 | inline std::vector<std::pair<std::string, AudioEngine>> |
| 89 | EnumMetadata<AudioEngine>::Canonicalizations() { | 89 | EnumMetadata<AudioEngine>::Canonicalizations() { |
| 90 | return { | 90 | return { |
| 91 | {"auto", AudioEngine::Auto}, | 91 | {"auto", AudioEngine::Auto}, |
| @@ -96,7 +96,7 @@ EnumMetadata<AudioEngine>::Canonicalizations() { | |||
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | template <> | 98 | template <> |
| 99 | constexpr u32 EnumMetadata<AudioEngine>::Index() { | 99 | inline u32 EnumMetadata<AudioEngine>::Index() { |
| 100 | // This is just a sufficiently large number that is more than the number of other enums declared | 100 | // This is just a sufficiently large number that is more than the number of other enums declared |
| 101 | // here | 101 | // here |
| 102 | return 100; | 102 | return 100; |
| @@ -147,7 +147,7 @@ ENUM(AntiAliasing, None, Fxaa, Smaa, MaxEnum); | |||
| 147 | ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch); | 147 | ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch); |
| 148 | 148 | ||
| 149 | template <typename Type> | 149 | template <typename Type> |
| 150 | constexpr std::string CanonicalizeEnum(Type id) { | 150 | inline std::string CanonicalizeEnum(Type id) { |
| 151 | const auto group = EnumMetadata<Type>::Canonicalizations(); | 151 | const auto group = EnumMetadata<Type>::Canonicalizations(); |
| 152 | for (auto& [name, value] : group) { | 152 | for (auto& [name, value] : group) { |
| 153 | if (value == id) { | 153 | if (value == id) { |
| @@ -158,7 +158,7 @@ constexpr std::string CanonicalizeEnum(Type id) { | |||
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | template <typename Type> | 160 | template <typename Type> |
| 161 | constexpr Type ToEnum(const std::string& canonicalization) { | 161 | inline Type ToEnum(const std::string& canonicalization) { |
| 162 | const auto group = EnumMetadata<Type>::Canonicalizations(); | 162 | const auto group = EnumMetadata<Type>::Canonicalizations(); |
| 163 | for (auto& [name, value] : group) { | 163 | for (auto& [name, value] : group) { |
| 164 | if (name == canonicalization) { | 164 | if (name == canonicalization) { |
diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h index a8beb06e9..e10843c73 100644 --- a/src/common/settings_setting.h +++ b/src/common/settings_setting.h | |||
| @@ -190,7 +190,7 @@ public: | |||
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | [[nodiscard]] std::string constexpr Canonicalize() const override final { | 193 | [[nodiscard]] std::string Canonicalize() const override final { |
| 194 | if constexpr (std::is_enum_v<Type>) { | 194 | if constexpr (std::is_enum_v<Type>) { |
| 195 | return CanonicalizeEnum(this->GetValue()); | 195 | return CanonicalizeEnum(this->GetValue()); |
| 196 | } else { | 196 | } else { |
| @@ -256,11 +256,11 @@ public: | |||
| 256 | * @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded | 256 | * @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded |
| 257 | * @param other_setting_ A second Setting to associate to this one in metadata | 257 | * @param other_setting_ A second Setting to associate to this one in metadata |
| 258 | */ | 258 | */ |
| 259 | template <typename T = BasicSetting> | ||
| 259 | explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name, | 260 | explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const std::string& name, |
| 260 | Category category_, u32 specialization_ = Specialization::Default, | 261 | Category category_, u32 specialization_ = Specialization::Default, |
| 261 | bool save_ = true, bool runtime_modifiable_ = false, | 262 | bool save_ = true, bool runtime_modifiable_ = false, |
| 262 | BasicSetting* other_setting_ = nullptr) | 263 | typename std::enable_if<!ranged, T*>::type other_setting_ = nullptr) |
| 263 | requires(!ranged) | ||
| 264 | : Setting<Type, false>{ | 264 | : Setting<Type, false>{ |
| 265 | linkage, default_val, name, category_, specialization_, | 265 | linkage, default_val, name, category_, specialization_, |
| 266 | save_, runtime_modifiable_, other_setting_} { | 266 | save_, runtime_modifiable_, other_setting_} { |
| @@ -282,12 +282,12 @@ public: | |||
| 282 | * @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded | 282 | * @param runtime_modifiable_ Suggests whether this is modifiable while a guest is loaded |
| 283 | * @param other_setting_ A second Setting to associate to this one in metadata | 283 | * @param other_setting_ A second Setting to associate to this one in metadata |
| 284 | */ | 284 | */ |
| 285 | template <typename T = BasicSetting> | ||
| 285 | explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val, | 286 | explicit SwitchableSetting(Linkage& linkage, const Type& default_val, const Type& min_val, |
| 286 | const Type& max_val, const std::string& name, Category category_, | 287 | const Type& max_val, const std::string& name, Category category_, |
| 287 | u32 specialization_ = Specialization::Default, bool save_ = true, | 288 | u32 specialization_ = Specialization::Default, bool save_ = true, |
| 288 | bool runtime_modifiable_ = false, | 289 | bool runtime_modifiable_ = false, |
| 289 | BasicSetting* other_setting_ = nullptr) | 290 | typename std::enable_if<ranged, T*>::type other_setting_ = nullptr) |
| 290 | requires(ranged) | ||
| 291 | : Setting<Type, true>{linkage, default_val, min_val, | 291 | : Setting<Type, true>{linkage, default_val, min_val, |
| 292 | max_val, name, category_, | 292 | max_val, name, category_, |
| 293 | specialization_, save_, runtime_modifiable_, | 293 | specialization_, save_, runtime_modifiable_, |