settings.h 9.6 KB

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