summaryrefslogtreecommitdiff
path: root/src/core/settings.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/settings.h')
-rw-r--r--src/core/settings.h563
1 files changed, 169 insertions, 394 deletions
diff --git a/src/core/settings.h b/src/core/settings.h
index 79ec01731..1143aba5d 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -12,386 +12,171 @@
12#include <string> 12#include <string>
13#include <vector> 13#include <vector>
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "input_common/settings.h"
15 16
16namespace Settings { 17namespace Settings {
17 18
18namespace NativeButton { 19enum class RendererBackend {
19enum Values { 20 OpenGL = 0,
20 A, 21 Vulkan = 1,
21 B,
22 X,
23 Y,
24 LStick,
25 RStick,
26 L,
27 R,
28 ZL,
29 ZR,
30 Plus,
31 Minus,
32
33 DLeft,
34 DUp,
35 DRight,
36 DDown,
37
38 LStick_Left,
39 LStick_Up,
40 LStick_Right,
41 LStick_Down,
42
43 RStick_Left,
44 RStick_Up,
45 RStick_Right,
46 RStick_Down,
47
48 SL,
49 SR,
50
51 Home,
52 Screenshot,
53
54 NumButtons,
55};
56
57constexpr int BUTTON_HID_BEGIN = A;
58constexpr int BUTTON_NS_BEGIN = Home;
59
60constexpr int BUTTON_HID_END = BUTTON_NS_BEGIN;
61constexpr int BUTTON_NS_END = NumButtons;
62
63constexpr int NUM_BUTTONS_HID = BUTTON_HID_END - BUTTON_HID_BEGIN;
64constexpr int NUM_BUTTONS_NS = BUTTON_NS_END - BUTTON_NS_BEGIN;
65
66extern const std::array<const char*, NumButtons> mapping;
67
68} // namespace NativeButton
69
70namespace NativeAnalog {
71enum Values {
72 LStick,
73 RStick,
74
75 NumAnalogs,
76}; 22};
77 23
78constexpr int STICK_HID_BEGIN = LStick; 24enum class GPUAccuracy : u32 {
79constexpr int STICK_HID_END = NumAnalogs; 25 Normal = 0,
80constexpr int NUM_STICKS_HID = NumAnalogs; 26 High = 1,
81 27 Extreme = 2,
82extern const std::array<const char*, NumAnalogs> mapping;
83} // namespace NativeAnalog
84
85namespace NativeMouseButton {
86enum Values {
87 Left,
88 Right,
89 Middle,
90 Forward,
91 Back,
92
93 NumMouseButtons,
94}; 28};
95 29
96constexpr int MOUSE_HID_BEGIN = Left; 30enum class CPUAccuracy {
97constexpr int MOUSE_HID_END = NumMouseButtons; 31 Accurate = 0,
98constexpr int NUM_MOUSE_HID = NumMouseButtons; 32 Unsafe = 1,
99 33 DebugMode = 2,
100extern const std::array<const char*, NumMouseButtons> mapping;
101} // namespace NativeMouseButton
102
103namespace NativeKeyboard {
104enum Keys {
105 None,
106 Error,
107
108 A = 4,
109 B,
110 C,
111 D,
112 E,
113 F,
114 G,
115 H,
116 I,
117 J,
118 K,
119 L,
120 M,
121 N,
122 O,
123 P,
124 Q,
125 R,
126 S,
127 T,
128 U,
129 V,
130 W,
131 X,
132 Y,
133 Z,
134 N1,
135 N2,
136 N3,
137 N4,
138 N5,
139 N6,
140 N7,
141 N8,
142 N9,
143 N0,
144 Enter,
145 Escape,
146 Backspace,
147 Tab,
148 Space,
149 Minus,
150 Equal,
151 LeftBrace,
152 RightBrace,
153 Backslash,
154 Tilde,
155 Semicolon,
156 Apostrophe,
157 Grave,
158 Comma,
159 Dot,
160 Slash,
161 CapsLockKey,
162
163 F1,
164 F2,
165 F3,
166 F4,
167 F5,
168 F6,
169 F7,
170 F8,
171 F9,
172 F10,
173 F11,
174 F12,
175
176 SystemRequest,
177 ScrollLockKey,
178 Pause,
179 Insert,
180 Home,
181 PageUp,
182 Delete,
183 End,
184 PageDown,
185 Right,
186 Left,
187 Down,
188 Up,
189
190 NumLockKey,
191 KPSlash,
192 KPAsterisk,
193 KPMinus,
194 KPPlus,
195 KPEnter,
196 KP1,
197 KP2,
198 KP3,
199 KP4,
200 KP5,
201 KP6,
202 KP7,
203 KP8,
204 KP9,
205 KP0,
206 KPDot,
207
208 Key102,
209 Compose,
210 Power,
211 KPEqual,
212
213 F13,
214 F14,
215 F15,
216 F16,
217 F17,
218 F18,
219 F19,
220 F20,
221 F21,
222 F22,
223 F23,
224 F24,
225
226 Open,
227 Help,
228 Properties,
229 Front,
230 Stop,
231 Repeat,
232 Undo,
233 Cut,
234 Copy,
235 Paste,
236 Find,
237 Mute,
238 VolumeUp,
239 VolumeDown,
240 CapsLockActive,
241 NumLockActive,
242 ScrollLockActive,
243 KPComma,
244
245 KPLeftParenthesis,
246 KPRightParenthesis,
247
248 LeftControlKey = 0xE0,
249 LeftShiftKey,
250 LeftAltKey,
251 LeftMetaKey,
252 RightControlKey,
253 RightShiftKey,
254 RightAltKey,
255 RightMetaKey,
256
257 MediaPlayPause,
258 MediaStopCD,
259 MediaPrevious,
260 MediaNext,
261 MediaEject,
262 MediaVolumeUp,
263 MediaVolumeDown,
264 MediaMute,
265 MediaWebsite,
266 MediaBack,
267 MediaForward,
268 MediaStop,
269 MediaFind,
270 MediaScrollUp,
271 MediaScrollDown,
272 MediaEdit,
273 MediaSleep,
274 MediaCoffee,
275 MediaRefresh,
276 MediaCalculator,
277
278 NumKeyboardKeys,
279}; 34};
280 35
281static_assert(NumKeyboardKeys == 0xFC, "Incorrect number of keyboard keys."); 36template <typename Type>
282 37class Setting final {
283enum Modifiers { 38public:
284 LeftControl, 39 Setting() = default;
285 LeftShift, 40 explicit Setting(Type val) : global{val} {}
286 LeftAlt, 41 ~Setting() = default;
287 LeftMeta, 42 void SetGlobal(bool to_global) {
288 RightControl, 43 use_global = to_global;
289 RightShift, 44 }
290 RightAlt, 45 bool UsingGlobal() const {
291 RightMeta, 46 return use_global;
292 CapsLock, 47 }
293 ScrollLock, 48 Type GetValue(bool need_global = false) const {
294 NumLock, 49 if (use_global || need_global) {
295 50 return global;
296 NumKeyboardMods, 51 }
52 return local;
53 }
54 void SetValue(const Type& value) {
55 if (use_global) {
56 global = value;
57 } else {
58 local = value;
59 }
60 }
61
62private:
63 bool use_global = true;
64 Type global{};
65 Type local{};
297}; 66};
298 67
299constexpr int KEYBOARD_KEYS_HID_BEGIN = None; 68/**
300constexpr int KEYBOARD_KEYS_HID_END = NumKeyboardKeys; 69 * The InputSetting class allows for getting a reference to either the global or local members.
301constexpr int NUM_KEYBOARD_KEYS_HID = NumKeyboardKeys; 70 * This is required as we cannot easily modify the values of user-defined types within containers
302 71 * using the SetValue() member function found in the Setting class. The primary purpose of this
303constexpr int KEYBOARD_MODS_HID_BEGIN = LeftControl; 72 * class is to store an array of 10 PlayerInput structs for both the global and local (per-game)
304constexpr int KEYBOARD_MODS_HID_END = NumKeyboardMods; 73 * setting and allows for easily accessing and modifying both settings.
305constexpr int NUM_KEYBOARD_MODS_HID = NumKeyboardMods; 74 */
306 75template <typename Type>
307} // namespace NativeKeyboard 76class InputSetting final {
308 77public:
309using ButtonsRaw = std::array<std::string, NativeButton::NumButtons>; 78 InputSetting() = default;
310using AnalogsRaw = std::array<std::string, NativeAnalog::NumAnalogs>; 79 explicit InputSetting(Type val) : global{val} {}
311using MouseButtonsRaw = std::array<std::string, NativeMouseButton::NumMouseButtons>; 80 ~InputSetting() = default;
312using KeyboardKeysRaw = std::array<std::string, NativeKeyboard::NumKeyboardKeys>; 81 void SetGlobal(bool to_global) {
313using KeyboardModsRaw = std::array<std::string, NativeKeyboard::NumKeyboardMods>; 82 use_global = to_global;
314 83 }
315constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28; 84 bool UsingGlobal() const {
316constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A; 85 return use_global;
317constexpr u32 JOYCON_BODY_NEON_BLUE = 0x0AB9E6; 86 }
318constexpr u32 JOYCON_BUTTONS_NEON_BLUE = 0x001E1E; 87 Type& GetValue(bool need_global = false) {
319 88 if (use_global || need_global) {
320enum class ControllerType { 89 return global;
321 ProController, 90 }
322 DualJoycon, 91 return local;
323 RightJoycon, 92 }
324 LeftJoycon, 93
94private:
95 bool use_global = true;
96 Type global{};
97 Type local{};
325}; 98};
326 99
327struct PlayerInput { 100struct TouchFromButtonMap {
328 bool connected; 101 std::string name;
329 ControllerType type; 102 std::vector<std::string> buttons;
330 ButtonsRaw buttons;
331 AnalogsRaw analogs;
332
333 u32 body_color_right;
334 u32 button_color_right;
335 u32 body_color_left;
336 u32 button_color_left;
337}; 103};
338 104
339struct TouchscreenInput { 105struct Values {
340 bool enabled; 106 // Audio
341 std::string device; 107 std::string audio_device_id;
108 std::string sink_id;
109 bool audio_muted;
110 Setting<bool> enable_audio_stretching;
111 Setting<float> volume;
342 112
343 u32 finger; 113 // Core
344 u32 diameter_x; 114 Setting<bool> use_multi_core;
345 u32 diameter_y;
346 u32 rotation_angle;
347};
348 115
349enum class NANDTotalSize : u64 { 116 // Cpu
350 S29_1GB = 0x747C00000ULL, 117 CPUAccuracy cpu_accuracy;
351};
352 118
353enum class NANDUserSize : u64 { 119 bool cpuopt_page_tables;
354 S26GB = 0x680000000ULL, 120 bool cpuopt_block_linking;
355}; 121 bool cpuopt_return_stack_buffer;
122 bool cpuopt_fast_dispatcher;
123 bool cpuopt_context_elimination;
124 bool cpuopt_const_prop;
125 bool cpuopt_misc_ir;
126 bool cpuopt_reduce_misalign_checks;
356 127
357enum class NANDSystemSize : u64 { 128 bool cpuopt_unsafe_unfuse_fma;
358 S2_5GB = 0xA0000000, 129 bool cpuopt_unsafe_reduce_fp_error;
359};
360 130
361enum class SDMCSize : u64 { 131 // Renderer
362 S1GB = 0x40000000, 132 Setting<RendererBackend> renderer_backend;
363 S2GB = 0x80000000, 133 bool renderer_debug;
364 S4GB = 0x100000000ULL, 134 Setting<int> vulkan_device;
365 S8GB = 0x200000000ULL, 135
366 S16GB = 0x400000000ULL, 136 Setting<u16> resolution_factor{1};
367 S32GB = 0x800000000ULL, 137 Setting<int> aspect_ratio;
368 S64GB = 0x1000000000ULL, 138 Setting<int> max_anisotropy;
369 S128GB = 0x2000000000ULL, 139 Setting<bool> use_frame_limit;
370 S256GB = 0x4000000000ULL, 140 Setting<u16> frame_limit;
371 S1TB = 0x10000000000ULL, 141 Setting<bool> use_disk_shader_cache;
372}; 142 Setting<GPUAccuracy> gpu_accuracy;
373 143 Setting<bool> use_asynchronous_gpu_emulation;
374enum class RendererBackend { 144 Setting<bool> use_nvdec_emulation;
375 OpenGL = 0, 145 Setting<bool> use_vsync;
376 Vulkan = 1, 146 Setting<bool> use_assembly_shaders;
377}; 147 Setting<bool> use_asynchronous_shaders;
148 Setting<bool> use_fast_gpu_time;
149
150 Setting<float> bg_red;
151 Setting<float> bg_green;
152 Setting<float> bg_blue;
378 153
379struct Values {
380 // System 154 // System
381 bool use_docked_mode; 155 Setting<std::optional<u32>> rng_seed;
382 std::optional<u32> rng_seed;
383 // Measured in seconds since epoch 156 // Measured in seconds since epoch
384 std::optional<std::chrono::seconds> custom_rtc; 157 Setting<std::optional<std::chrono::seconds>> custom_rtc;
385 // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` 158 // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
386 std::chrono::seconds custom_rtc_differential; 159 std::chrono::seconds custom_rtc_differential;
387 160
388 s32 current_user; 161 s32 current_user;
389 s32 language_index; 162 Setting<s32> language_index;
390 s32 region_index; 163 Setting<s32> region_index;
391 s32 sound_index; 164 Setting<s32> time_zone_index;
165 Setting<s32> sound_index;
392 166
393 // Controls 167 // Controls
394 std::array<PlayerInput, 10> players; 168 InputSetting<std::array<PlayerInput, 10>> players;
169
170 Setting<bool> use_docked_mode;
171
172 Setting<bool> vibration_enabled;
173 Setting<bool> enable_accurate_vibrations;
174
175 Setting<bool> motion_enabled;
176 std::string motion_device;
177 std::string udp_input_address;
178 u16 udp_input_port;
179 u8 udp_pad_index;
395 180
396 bool mouse_enabled; 181 bool mouse_enabled;
397 std::string mouse_device; 182 std::string mouse_device;
@@ -405,55 +190,20 @@ struct Values {
405 ButtonsRaw debug_pad_buttons; 190 ButtonsRaw debug_pad_buttons;
406 AnalogsRaw debug_pad_analogs; 191 AnalogsRaw debug_pad_analogs;
407 192
408 std::string motion_device;
409 TouchscreenInput touchscreen; 193 TouchscreenInput touchscreen;
410 std::atomic_bool is_device_reload_pending{true};
411 std::string udp_input_address;
412 u16 udp_input_port;
413 u8 udp_pad_index;
414 194
415 // Core 195 bool use_touch_from_button;
416 bool use_multi_core; 196 std::string touch_device;
197 int touch_from_button_map_index;
198 std::vector<TouchFromButtonMap> touch_from_button_maps;
199
200 std::atomic_bool is_device_reload_pending{true};
417 201
418 // Data Storage 202 // Data Storage
419 bool use_virtual_sd; 203 bool use_virtual_sd;
420 bool gamecard_inserted; 204 bool gamecard_inserted;
421 bool gamecard_current_game; 205 bool gamecard_current_game;
422 std::string gamecard_path; 206 std::string gamecard_path;
423 NANDTotalSize nand_total_size;
424 NANDSystemSize nand_system_size;
425 NANDUserSize nand_user_size;
426 SDMCSize sdmc_size;
427
428 // Renderer
429 RendererBackend renderer_backend;
430 bool renderer_debug;
431 int vulkan_device;
432
433 float resolution_factor;
434 int aspect_ratio;
435 int max_anisotropy;
436 bool use_frame_limit;
437 u16 frame_limit;
438 bool use_disk_shader_cache;
439 bool use_accurate_gpu_emulation;
440 bool use_asynchronous_gpu_emulation;
441 bool use_vsync;
442 bool force_30fps_mode;
443
444 float bg_red;
445 float bg_green;
446 float bg_blue;
447
448 std::string log_filter;
449
450 bool use_dev_keys;
451
452 // Audio
453 std::string sink_id;
454 bool enable_audio_stretching;
455 std::string audio_device_id;
456 float volume;
457 207
458 // Debugging 208 // Debugging
459 bool record_frame_times; 209 bool record_frame_times;
@@ -464,8 +214,14 @@ struct Values {
464 bool dump_nso; 214 bool dump_nso;
465 bool reporting_services; 215 bool reporting_services;
466 bool quest_flag; 216 bool quest_flag;
217 bool disable_macro_jit;
218 bool extended_logging;
219
220 // Misceallaneous
221 std::string log_filter;
222 bool use_dev_keys;
467 223
468 // BCAT 224 // Services
469 std::string bcat_backend; 225 std::string bcat_backend;
470 bool bcat_boxcat_local; 226 bool bcat_boxcat_local;
471 227
@@ -477,8 +233,27 @@ struct Values {
477 233
478 // Add-Ons 234 // Add-Ons
479 std::map<u64, std::vector<std::string>> disabled_addons; 235 std::map<u64, std::vector<std::string>> disabled_addons;
480} extern values; 236};
237
238extern Values values;
239
240bool IsConfiguringGlobal();
241void SetConfiguringGlobal(bool is_global);
242
243bool IsGPULevelExtreme();
244bool IsGPULevelHigh();
245
246float Volume();
247
248std::string GetTimeZoneString();
481 249
482void Apply(); 250void Apply();
483void LogSettings(); 251void LogSettings();
252
253// Restore the global state of all applicable settings in the Values struct
254void RestoreGlobalState();
255
256// Fixes settings that are known to cause issues with the emulator
257void Sanitize();
258
484} // namespace Settings 259} // namespace Settings