settings.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. #include "input_common/settings.h"
  14. namespace Core {
  15. class System;
  16. }
  17. namespace Settings {
  18. enum class RendererBackend {
  19. OpenGL = 0,
  20. Vulkan = 1,
  21. };
  22. enum class GPUAccuracy : u32 {
  23. Normal = 0,
  24. High = 1,
  25. Extreme = 2,
  26. };
  27. enum class CPUAccuracy {
  28. Accurate = 0,
  29. Unsafe = 1,
  30. DebugMode = 2,
  31. };
  32. template <typename Type>
  33. class Setting final {
  34. public:
  35. Setting() = default;
  36. explicit Setting(Type val) : global{val} {}
  37. ~Setting() = default;
  38. void SetGlobal(bool to_global) {
  39. use_global = to_global;
  40. }
  41. bool UsingGlobal() const {
  42. return use_global;
  43. }
  44. Type GetValue(bool need_global = false) const {
  45. if (use_global || need_global) {
  46. return global;
  47. }
  48. return local;
  49. }
  50. void SetValue(const Type& value) {
  51. if (use_global) {
  52. global = value;
  53. } else {
  54. local = value;
  55. }
  56. }
  57. private:
  58. bool use_global = true;
  59. Type global{};
  60. Type local{};
  61. };
  62. /**
  63. * The InputSetting class allows for getting a reference to either the global or local members.
  64. * This is required as we cannot easily modify the values of user-defined types within containers
  65. * using the SetValue() member function found in the Setting class. The primary purpose of this
  66. * class is to store an array of 10 PlayerInput structs for both the global and local (per-game)
  67. * setting and allows for easily accessing and modifying both settings.
  68. */
  69. template <typename Type>
  70. class InputSetting final {
  71. public:
  72. InputSetting() = default;
  73. explicit InputSetting(Type val) : global{val} {}
  74. ~InputSetting() = default;
  75. void SetGlobal(bool to_global) {
  76. use_global = to_global;
  77. }
  78. bool UsingGlobal() const {
  79. return use_global;
  80. }
  81. Type& GetValue(bool need_global = false) {
  82. if (use_global || need_global) {
  83. return global;
  84. }
  85. return local;
  86. }
  87. private:
  88. bool use_global = true;
  89. Type global{};
  90. Type local{};
  91. };
  92. struct TouchFromButtonMap {
  93. std::string name;
  94. std::vector<std::string> buttons;
  95. };
  96. struct Values {
  97. // Audio
  98. std::string audio_device_id;
  99. std::string sink_id;
  100. bool audio_muted;
  101. Setting<bool> enable_audio_stretching;
  102. Setting<float> volume;
  103. // Core
  104. Setting<bool> use_multi_core;
  105. // Cpu
  106. CPUAccuracy cpu_accuracy;
  107. bool cpuopt_page_tables;
  108. bool cpuopt_block_linking;
  109. bool cpuopt_return_stack_buffer;
  110. bool cpuopt_fast_dispatcher;
  111. bool cpuopt_context_elimination;
  112. bool cpuopt_const_prop;
  113. bool cpuopt_misc_ir;
  114. bool cpuopt_reduce_misalign_checks;
  115. bool cpuopt_unsafe_unfuse_fma;
  116. bool cpuopt_unsafe_reduce_fp_error;
  117. bool cpuopt_unsafe_inaccurate_nan;
  118. // Renderer
  119. Setting<RendererBackend> renderer_backend;
  120. bool renderer_debug;
  121. Setting<int> vulkan_device;
  122. Setting<u16> resolution_factor{1};
  123. Setting<int> aspect_ratio;
  124. Setting<int> max_anisotropy;
  125. Setting<bool> use_frame_limit;
  126. Setting<u16> frame_limit;
  127. Setting<bool> use_disk_shader_cache;
  128. Setting<GPUAccuracy> gpu_accuracy;
  129. Setting<bool> use_asynchronous_gpu_emulation;
  130. Setting<bool> use_nvdec_emulation;
  131. Setting<bool> use_vsync;
  132. Setting<bool> use_assembly_shaders;
  133. Setting<bool> use_asynchronous_shaders;
  134. Setting<bool> use_fast_gpu_time;
  135. Setting<float> bg_red;
  136. Setting<float> bg_green;
  137. Setting<float> bg_blue;
  138. // System
  139. Setting<std::optional<u32>> rng_seed;
  140. // Measured in seconds since epoch
  141. Setting<std::optional<std::chrono::seconds>> custom_rtc;
  142. // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
  143. std::chrono::seconds custom_rtc_differential;
  144. s32 current_user;
  145. Setting<s32> language_index;
  146. Setting<s32> region_index;
  147. Setting<s32> time_zone_index;
  148. Setting<s32> sound_index;
  149. // Controls
  150. InputSetting<std::array<PlayerInput, 10>> players;
  151. Setting<bool> use_docked_mode;
  152. Setting<bool> vibration_enabled;
  153. Setting<bool> enable_accurate_vibrations;
  154. Setting<bool> motion_enabled;
  155. std::string motion_device;
  156. std::string udp_input_servers;
  157. bool emulate_analog_keyboard;
  158. bool mouse_enabled;
  159. std::string mouse_device;
  160. MouseButtonsRaw mouse_buttons;
  161. bool keyboard_enabled;
  162. KeyboardKeysRaw keyboard_keys;
  163. KeyboardModsRaw keyboard_mods;
  164. bool debug_pad_enabled;
  165. ButtonsRaw debug_pad_buttons;
  166. AnalogsRaw debug_pad_analogs;
  167. TouchscreenInput touchscreen;
  168. bool use_touch_from_button;
  169. std::string touch_device;
  170. int touch_from_button_map_index;
  171. std::vector<TouchFromButtonMap> touch_from_button_maps;
  172. std::atomic_bool is_device_reload_pending{true};
  173. // Data Storage
  174. bool use_virtual_sd;
  175. bool gamecard_inserted;
  176. bool gamecard_current_game;
  177. std::string gamecard_path;
  178. // Debugging
  179. bool record_frame_times;
  180. bool use_gdbstub;
  181. u16 gdbstub_port;
  182. std::string program_args;
  183. bool dump_exefs;
  184. bool dump_nso;
  185. bool reporting_services;
  186. bool quest_flag;
  187. bool disable_macro_jit;
  188. bool extended_logging;
  189. // Miscellaneous
  190. std::string log_filter;
  191. bool use_dev_keys;
  192. // Services
  193. std::string bcat_backend;
  194. bool bcat_boxcat_local;
  195. // WebService
  196. bool enable_telemetry;
  197. std::string web_api_url;
  198. std::string yuzu_username;
  199. std::string yuzu_token;
  200. // Add-Ons
  201. std::map<u64, std::vector<std::string>> disabled_addons;
  202. };
  203. extern Values values;
  204. bool IsConfiguringGlobal();
  205. void SetConfiguringGlobal(bool is_global);
  206. bool IsGPULevelExtreme();
  207. bool IsGPULevelHigh();
  208. float Volume();
  209. std::string GetTimeZoneString();
  210. void Apply(Core::System& system);
  211. void LogSettings();
  212. // Restore the global state of all applicable settings in the Values struct
  213. void RestoreGlobalState(bool is_powered_on);
  214. } // namespace Settings