summaryrefslogtreecommitdiff
path: root/src/common/settings_enums.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/settings_enums.h')
-rw-r--r--src/common/settings_enums.h214
1 files changed, 214 insertions, 0 deletions
diff --git a/src/common/settings_enums.h b/src/common/settings_enums.h
new file mode 100644
index 000000000..a1a29ebf6
--- /dev/null
+++ b/src/common/settings_enums.h
@@ -0,0 +1,214 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <string>
7#include <utility>
8#include <vector>
9#include "common/common_types.h"
10
11namespace Settings {
12
13template <typename T>
14struct EnumMetadata {
15 static constexpr std::vector<std::pair<std::string, T>> Canonicalizations();
16 static constexpr u32 Index();
17};
18
19#define PAIR_45(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_46(N, __VA_ARGS__))
20#define PAIR_44(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_45(N, __VA_ARGS__))
21#define PAIR_43(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_44(N, __VA_ARGS__))
22#define PAIR_42(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_43(N, __VA_ARGS__))
23#define PAIR_41(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_42(N, __VA_ARGS__))
24#define PAIR_40(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_41(N, __VA_ARGS__))
25#define PAIR_39(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_40(N, __VA_ARGS__))
26#define PAIR_38(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_39(N, __VA_ARGS__))
27#define PAIR_37(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_38(N, __VA_ARGS__))
28#define PAIR_36(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_37(N, __VA_ARGS__))
29#define PAIR_35(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_36(N, __VA_ARGS__))
30#define PAIR_34(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_35(N, __VA_ARGS__))
31#define PAIR_33(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_34(N, __VA_ARGS__))
32#define PAIR_32(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_33(N, __VA_ARGS__))
33#define PAIR_31(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_32(N, __VA_ARGS__))
34#define PAIR_30(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_31(N, __VA_ARGS__))
35#define PAIR_29(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_30(N, __VA_ARGS__))
36#define PAIR_28(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_29(N, __VA_ARGS__))
37#define PAIR_27(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_28(N, __VA_ARGS__))
38#define PAIR_26(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_27(N, __VA_ARGS__))
39#define PAIR_25(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_26(N, __VA_ARGS__))
40#define PAIR_24(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_25(N, __VA_ARGS__))
41#define PAIR_23(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_24(N, __VA_ARGS__))
42#define PAIR_22(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_23(N, __VA_ARGS__))
43#define PAIR_21(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_22(N, __VA_ARGS__))
44#define PAIR_20(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_21(N, __VA_ARGS__))
45#define PAIR_19(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_20(N, __VA_ARGS__))
46#define PAIR_18(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_19(N, __VA_ARGS__))
47#define PAIR_17(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_18(N, __VA_ARGS__))
48#define PAIR_16(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_17(N, __VA_ARGS__))
49#define PAIR_15(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_16(N, __VA_ARGS__))
50#define PAIR_14(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_15(N, __VA_ARGS__))
51#define PAIR_13(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_14(N, __VA_ARGS__))
52#define PAIR_12(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_13(N, __VA_ARGS__))
53#define PAIR_11(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_12(N, __VA_ARGS__))
54#define PAIR_10(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_11(N, __VA_ARGS__))
55#define PAIR_9(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_10(N, __VA_ARGS__))
56#define PAIR_8(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_9(N, __VA_ARGS__))
57#define PAIR_7(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_8(N, __VA_ARGS__))
58#define PAIR_6(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_7(N, __VA_ARGS__))
59#define PAIR_5(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_6(N, __VA_ARGS__))
60#define PAIR_4(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_5(N, __VA_ARGS__))
61#define PAIR_3(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_4(N, __VA_ARGS__))
62#define PAIR_2(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_3(N, __VA_ARGS__))
63#define PAIR_1(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_2(N, __VA_ARGS__))
64#define PAIR(N, X, ...) {#X, N::X} __VA_OPT__(, PAIR_1(N, __VA_ARGS__))
65
66#define ENUM(NAME, ...) \
67 enum class NAME : u32 { __VA_ARGS__ }; \
68 template <> \
69 constexpr std::vector<std::pair<std::string, NAME>> EnumMetadata<NAME>::Canonicalizations() { \
70 return {PAIR(NAME, __VA_ARGS__)}; \
71 } \
72 template <> \
73 constexpr u32 EnumMetadata<NAME>::Index() { \
74 return __COUNTER__; \
75 }
76
77// AudioEngine must be specified discretely due to having existing but slightly different
78// canonicalizations
79// TODO (lat9nq): Remove explicit definition of AudioEngine/sink_id
80enum class AudioEngine : u32 {
81 Auto,
82 Cubeb,
83 Sdl2,
84 Null,
85};
86
87template <>
88constexpr std::vector<std::pair<std::string, AudioEngine>>
89EnumMetadata<AudioEngine>::Canonicalizations() {
90 return {
91 {"auto", AudioEngine::Auto},
92 {"cubeb", AudioEngine::Cubeb},
93 {"sdl2", AudioEngine::Sdl2},
94 {"null", AudioEngine::Null},
95 };
96}
97
98template <>
99constexpr u32 EnumMetadata<AudioEngine>::Index() {
100 // This is just a sufficiently large number that is more than the number of other enums declared
101 // here
102 return 100;
103}
104
105ENUM(AudioMode, Mono, Stereo, Surround);
106
107ENUM(Language, Japanese, EnglishAmerican, French, German, Italian, Spanish, Chinese, Korean, Dutch,
108 Portuguese, Russian, Taiwanese, EnglishBritish, FrenchCanadian, SpanishLatin,
109 ChineseSimplified, ChineseTraditional, PortugueseBrazilian);
110
111ENUM(Region, Japan, Usa, Europe, Australia, China, Korea, Taiwan);
112
113ENUM(TimeZone, Auto, Default, Cet, Cst6Cdt, Cuba, Eet, Egypt, Eire, Est, Est5Edt, Gb, GbEire, Gmt,
114 GmtPlusZero, GmtMinusZero, GmtZero, Greenwich, Hongkong, Hst, Iceland, Iran, Israel, Jamaica,
115 Japan, Kwajalein, Libya, Met, Mst, Mst7Mdt, Navajo, Nz, NzChat, Poland, Portugal, Prc, Pst8Pdt,
116 Roc, Rok, Singapore, Turkey, Uct, Universal, Utc, WSu, Wet, Zulu);
117
118ENUM(AnisotropyMode, Automatic, Default, X2, X4, X8, X16);
119
120ENUM(AstcDecodeMode, Cpu, Gpu, CpuAsynchronous);
121
122ENUM(AstcRecompression, Uncompressed, Bc1, Bc3);
123
124ENUM(VSyncMode, Immediate, Mailbox, Fifo, FifoRelaxed);
125
126ENUM(RendererBackend, OpenGL, Vulkan, Null);
127
128ENUM(ShaderBackend, Glsl, Glasm, SpirV);
129
130ENUM(GpuAccuracy, Normal, High, Extreme);
131
132ENUM(CpuAccuracy, Auto, Accurate, Unsafe, Paranoid);
133
134ENUM(MemoryLayout, Memory_4Gb, Memory_6Gb, Memory_8Gb);
135
136ENUM(FullscreenMode, Borderless, Exclusive);
137
138ENUM(NvdecEmulation, Off, Cpu, Gpu);
139
140ENUM(ResolutionSetup, Res1_2X, Res3_4X, Res1X, Res3_2X, Res2X, Res3X, Res4X, Res5X, Res6X, Res7X,
141 Res8X);
142
143ENUM(ScalingFilter, NearestNeighbor, Bilinear, Bicubic, Gaussian, ScaleForce, Fsr, MaxEnum);
144
145ENUM(AntiAliasing, None, Fxaa, Smaa, MaxEnum);
146
147ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch);
148
149template <typename Type>
150constexpr std::string CanonicalizeEnum(Type id) {
151 const auto group = EnumMetadata<Type>::Canonicalizations();
152 for (auto& [name, value] : group) {
153 if (value == id) {
154 return name;
155 }
156 }
157 return "unknown";
158}
159
160template <typename Type>
161constexpr Type ToEnum(const std::string& canonicalization) {
162 const auto group = EnumMetadata<Type>::Canonicalizations();
163 for (auto& [name, value] : group) {
164 if (name == canonicalization) {
165 return value;
166 }
167 }
168 return {};
169}
170} // namespace Settings
171
172#undef ENUM
173#undef PAIR
174#undef PAIR_1
175#undef PAIR_2
176#undef PAIR_3
177#undef PAIR_4
178#undef PAIR_5
179#undef PAIR_6
180#undef PAIR_7
181#undef PAIR_8
182#undef PAIR_9
183#undef PAIR_10
184#undef PAIR_12
185#undef PAIR_13
186#undef PAIR_14
187#undef PAIR_15
188#undef PAIR_16
189#undef PAIR_17
190#undef PAIR_18
191#undef PAIR_19
192#undef PAIR_20
193#undef PAIR_22
194#undef PAIR_23
195#undef PAIR_24
196#undef PAIR_25
197#undef PAIR_26
198#undef PAIR_27
199#undef PAIR_28
200#undef PAIR_29
201#undef PAIR_30
202#undef PAIR_32
203#undef PAIR_33
204#undef PAIR_34
205#undef PAIR_35
206#undef PAIR_36
207#undef PAIR_37
208#undef PAIR_38
209#undef PAIR_39
210#undef PAIR_40
211#undef PAIR_42
212#undef PAIR_43
213#undef PAIR_44
214#undef PAIR_45