summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar lat9nq2023-06-12 17:05:30 -0400
committerGravatar lat9nq2023-07-21 10:56:54 -0400
commit11e7e1b8cec5a665bdc6c9e702f83ad6ea35dd6b (patch)
treec308cfcddc0ffd20561114559329411242e31bb5 /src
parentsettings_setting: Fix errors (diff)
downloadyuzu-11e7e1b8cec5a665bdc6c9e702f83ad6ea35dd6b.tar.gz
yuzu-11e7e1b8cec5a665bdc6c9e702f83ad6ea35dd6b.tar.xz
yuzu-11e7e1b8cec5a665bdc6c9e702f83ad6ea35dd6b.zip
settings: Move some simple data to BasicSetting
Reduces the need for the compiler to duplicate this code, by about 100KB executable size.
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/settings.cpp8
-rw-r--r--src/common/settings_common.cpp45
-rw-r--r--src/common/settings_common.h96
-rw-r--r--src/common/settings_setting.h86
5 files changed, 129 insertions, 108 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 3c8368bb2..09e7e673e 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -110,6 +110,7 @@ add_library(common STATIC
110 scratch_buffer.h 110 scratch_buffer.h
111 settings.cpp 111 settings.cpp
112 settings.h 112 settings.h
113 settings_common.cpp
113 settings_common.h 114 settings_common.h
114 settings_enums.h 115 settings_enums.h
115 settings_input.cpp 116 settings_input.cpp
@@ -199,6 +200,7 @@ if (MSVC)
199else() 200else()
200 target_compile_options(common PRIVATE 201 target_compile_options(common PRIVATE
201 $<$<CXX_COMPILER_ID:Clang>:-fsized-deallocation> 202 $<$<CXX_COMPILER_ID:Clang>:-fsized-deallocation>
203 $<$<CXX_COMPILER_ID:Clang>:-Werror=unreachable-code-aggressive>
202 ) 204 )
203endif() 205endif()
204 206
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 10cdea844..d98dd2925 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -282,14 +282,6 @@ void UpdateRescalingInfo() {
282 info.active = info.up_scale != 1 || info.down_shift != 0; 282 info.active = info.up_scale != 1 || info.down_shift != 0;
283} 283}
284 284
285std::string BasicSetting::ToStringGlobal() const {
286 return {};
287}
288
289bool BasicSetting::UsingGlobal() const {
290 return true;
291}
292
293void RestoreGlobalState(bool is_powered_on) { 285void RestoreGlobalState(bool is_powered_on) {
294 // If a game is running, DO NOT restore the global settings state 286 // If a game is running, DO NOT restore the global settings state
295 if (is_powered_on) { 287 if (is_powered_on) {
diff --git a/src/common/settings_common.cpp b/src/common/settings_common.cpp
new file mode 100644
index 000000000..a7ce99515
--- /dev/null
+++ b/src/common/settings_common.cpp
@@ -0,0 +1,45 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include <string>
5#include "common/settings_common.h"
6
7namespace Settings {
8
9BasicSetting::BasicSetting(Linkage& linkage, const std::string& name, enum Category category_,
10 bool save_, bool runtime_modifiable_)
11 : label{name}, category{category_}, id{linkage.count}, save{save_}, runtime_modifiable{
12 runtime_modifiable_} {
13 linkage.by_category[category].push_front(this);
14 linkage.count++;
15}
16
17BasicSetting::~BasicSetting() = default;
18
19std::string BasicSetting::ToStringGlobal() const {
20 return this->ToString();
21}
22
23bool BasicSetting::UsingGlobal() const {
24 return true;
25}
26
27void BasicSetting::SetGlobal(bool global) {}
28
29bool BasicSetting::Save() const {
30 return save;
31}
32
33bool BasicSetting::RuntimeModfiable() const {
34 return runtime_modifiable;
35}
36
37Category BasicSetting::Category() const {
38 return category;
39}
40
41const std::string& BasicSetting::GetLabel() const {
42 return label;
43}
44
45} // namespace Settings
diff --git a/src/common/settings_common.h b/src/common/settings_common.h
index 93fddeba6..81d59115d 100644
--- a/src/common/settings_common.h
+++ b/src/common/settings_common.h
@@ -1,3 +1,6 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
1#pragma once 4#pragma once
2 5
3#include <forward_list> 6#include <forward_list>
@@ -40,31 +43,7 @@ enum class Category : u32 {
40 MaxEnum, 43 MaxEnum,
41}; 44};
42 45
43class BasicSetting { 46class BasicSetting;
44protected:
45 explicit BasicSetting() = default;
46
47public:
48 virtual ~BasicSetting() = default;
49
50 virtual Category Category() const = 0;
51 virtual constexpr bool Switchable() const = 0;
52 virtual std::string ToString() const = 0;
53 virtual std::string ToStringGlobal() const;
54 virtual void LoadString(const std::string& load) = 0;
55 virtual std::string Canonicalize() const = 0;
56 virtual const std::string& GetLabel() const = 0;
57 virtual std::string DefaultToString() const = 0;
58 virtual bool Save() const = 0;
59 virtual std::type_index TypeId() const = 0;
60 virtual constexpr bool IsEnum() const = 0;
61 virtual bool RuntimeModfiable() const = 0;
62 virtual void SetGlobal(bool global) {}
63 virtual constexpr u32 Id() const = 0;
64 virtual std::string MinVal() const = 0;
65 virtual std::string MaxVal() const = 0;
66 virtual bool UsingGlobal() const;
67};
68 47
69class Linkage { 48class Linkage {
70public: 49public:
@@ -75,4 +54,71 @@ public:
75 u32 count; 54 u32 count;
76}; 55};
77 56
57class BasicSetting {
58protected:
59 explicit BasicSetting(Linkage& linkage, const std::string& name, enum Category category_,
60 bool save_, bool runtime_modifiable_);
61
62public:
63 virtual ~BasicSetting();
64
65 /* Data retrieval */
66
67 [[nodiscard]] virtual std::string ToString() const = 0;
68 [[nodiscard]] virtual std::string ToStringGlobal() const;
69 [[nodiscard]] virtual std::string DefaultToString() const = 0;
70 [[nodiscard]] virtual std::string MinVal() const = 0;
71 [[nodiscard]] virtual std::string MaxVal() const = 0;
72 virtual void LoadString(const std::string& load) = 0;
73 [[nodiscard]] virtual std::string Canonicalize() const = 0;
74
75 /* Identification */
76
77 [[nodiscard]] virtual std::type_index TypeId() const = 0;
78 [[nodiscard]] virtual constexpr bool IsEnum() const = 0;
79 /**
80 * Returns whether the current setting is Switchable.
81 *
82 * @returns If the setting is a SwitchableSetting
83 */
84 [[nodiscard]] virtual constexpr bool Switchable() const {
85 return false;
86 }
87 /**
88 * Returns the save preference of the setting i.e. when saving or reading the setting from a
89 * frontend, whether this setting should be skipped.
90 *
91 * @returns The save preference
92 */
93 [[nodiscard]] bool Save() const;
94 [[nodiscard]] bool RuntimeModfiable() const;
95 [[nodiscard]] constexpr u32 Id() const {
96 return id;
97 }
98 /**
99 * Returns the setting's category AKA INI group.
100 *
101 * @returns The setting's category
102 */
103 [[nodiscard]] Category Category() const;
104 /**
105 * Returns the label this setting was created with.
106 *
107 * @returns A reference to the label
108 */
109 [[nodiscard]] const std::string& GetLabel() const;
110
111 /* Switchable settings */
112
113 virtual void SetGlobal(bool global);
114 [[nodiscard]] virtual bool UsingGlobal() const;
115
116private:
117 const std::string label; ///< The setting's label
118 const enum Category category; ///< The setting's category AKA INI group
119 const u32 id;
120 const bool save;
121 const bool runtime_modifiable;
122};
123
78} // namespace Settings 124} // namespace Settings
diff --git a/src/common/settings_setting.h b/src/common/settings_setting.h
index 99a4bad01..1ca3acf18 100644
--- a/src/common/settings_setting.h
+++ b/src/common/settings_setting.h
@@ -1,3 +1,6 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
1#pragma once 4#pragma once
2 5
3#include <map> 6#include <map>
@@ -21,16 +24,6 @@ class Setting : public BasicSetting {
21protected: 24protected:
22 Setting() = default; 25 Setting() = default;
23 26
24 /**
25 * Only sets the setting to the given initializer, leaving the other members to their default
26 * initializers.
27 *
28 * @param global_val Initial value of the setting
29 */
30 explicit Setting(const Type& val)
31 : value{val},
32 default_value{}, maximum{}, minimum{}, label{}, category{Category::Miscellaneous}, id{} {}
33
34public: 27public:
35 /** 28 /**
36 * Sets a default value, label, and setting value. 29 * Sets a default value, label, and setting value.
@@ -43,11 +36,8 @@ public:
43 explicit Setting(Linkage& linkage, const Type& default_val, const std::string& name, 36 explicit Setting(Linkage& linkage, const Type& default_val, const std::string& name,
44 enum Category category_, bool save_ = true, bool runtime_modifiable_ = false) 37 enum Category category_, bool save_ = true, bool runtime_modifiable_ = false)
45 requires(!ranged) 38 requires(!ranged)
46 : value{default_val}, default_value{default_val}, label{name}, category{category_}, 39 : BasicSetting(linkage, name, category_, save_, runtime_modifiable_), value{default_val},
47 id{linkage.count}, save{save_}, runtime_modifiable{runtime_modifiable_} { 40 default_value{default_val} {}
48 linkage.by_category[category].push_front(this);
49 linkage.count++;
50 }
51 virtual ~Setting() = default; 41 virtual ~Setting() = default;
52 42
53 /** 43 /**
@@ -64,12 +54,8 @@ public:
64 const Type& max_val, const std::string& name, enum Category category_, 54 const Type& max_val, const std::string& name, enum Category category_,
65 bool save_ = true, bool runtime_modifiable_ = false) 55 bool save_ = true, bool runtime_modifiable_ = false)
66 requires(ranged) 56 requires(ranged)
67 : value{default_val}, default_value{default_val}, maximum{max_val}, minimum{min_val}, 57 : BasicSetting(linkage, name, category_, save_, runtime_modifiable_), value{default_val},
68 label{name}, category{category_}, id{linkage.count}, save{save_}, 58 default_value{default_val}, maximum{max_val}, minimum{min_val} {}
69 runtime_modifiable{runtime_modifiable_} {
70 linkage.by_category[category].push_front(this);
71 linkage.count++;
72 }
73 59
74 /** 60 /**
75 * Returns a reference to the setting's value. 61 * Returns a reference to the setting's value.
@@ -99,41 +85,10 @@ public:
99 return default_value; 85 return default_value;
100 } 86 }
101 87
102 /**
103 * Returns the label this setting was created with.
104 *
105 * @returns A reference to the label
106 */
107 [[nodiscard]] const std::string& GetLabel() const override {
108 return label;
109 }
110
111 /**
112 * Returns the setting's category AKA INI group.
113 *
114 * @returns The setting's category
115 */
116 [[nodiscard]] enum Category Category() const override {
117 return category;
118 }
119
120 [[nodiscard]] bool RuntimeModfiable() const override {
121 return runtime_modifiable;
122 }
123
124 [[nodiscard]] constexpr bool IsEnum() const override { 88 [[nodiscard]] constexpr bool IsEnum() const override {
125 return std::is_enum<Type>::value; 89 return std::is_enum<Type>::value;
126 } 90 }
127 91
128 /**
129 * Returns whether the current setting is Switchable.
130 *
131 * @returns If the setting is a SwitchableSetting
132 */
133 [[nodiscard]] virtual constexpr bool Switchable() const override {
134 return false;
135 }
136
137protected: 92protected:
138 std::string ToString(const Type& value_) const { 93 std::string ToString(const Type& value_) const {
139 if constexpr (std::is_same<Type, std::string>()) { 94 if constexpr (std::is_same<Type, std::string>()) {
@@ -228,16 +183,6 @@ public:
228 } 183 }
229 184
230 /** 185 /**
231 * Returns the save preference of the setting i.e. when saving or reading the setting from a
232 * frontend, whether this setting should be skipped.
233 *
234 * @returns The save preference
235 */
236 virtual bool Save() const override {
237 return save;
238 }
239
240 /**
241 * Gives us another way to identify the setting without having to go through a string. 186 * Gives us another way to identify the setting without having to go through a string.
242 * 187 *
243 * @returns the type_index of the setting's type 188 * @returns the type_index of the setting's type
@@ -246,10 +191,6 @@ public:
246 return std::type_index(typeid(Type)); 191 return std::type_index(typeid(Type));
247 } 192 }
248 193
249 virtual constexpr u32 Id() const override {
250 return id;
251 }
252
253 virtual std::string MinVal() const override { 194 virtual std::string MinVal() const override {
254 return this->ToString(minimum); 195 return this->ToString(minimum);
255 } 196 }
@@ -258,15 +199,10 @@ public:
258 } 199 }
259 200
260protected: 201protected:
261 Type value{}; ///< The setting 202 Type value{}; ///< The setting
262 const Type default_value{}; ///< The default value 203 const Type default_value{}; ///< The default value
263 const Type maximum{}; ///< Maximum allowed value of the setting 204 const Type maximum{}; ///< Maximum allowed value of the setting
264 const Type minimum{}; ///< Minimum allowed value of the setting 205 const Type minimum{}; ///< Minimum allowed value of the setting
265 const std::string label{}; ///< The setting's label
266 const enum Category category; ///< The setting's category AKA INI group
267 const u32 id;
268 bool save;
269 bool runtime_modifiable;
270}; 206};
271 207
272/** 208/**