settings.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. // Copyright 2021 yuzu 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 "common/settings_input.h"
  14. namespace Settings {
  15. enum class RendererBackend : u32 {
  16. OpenGL = 0,
  17. Vulkan = 1,
  18. };
  19. enum class GPUAccuracy : u32 {
  20. Normal = 0,
  21. High = 1,
  22. Extreme = 2,
  23. };
  24. enum class CPUAccuracy : u32 {
  25. Accurate = 0,
  26. Unsafe = 1,
  27. DebugMode = 2,
  28. };
  29. template <typename Type>
  30. class Setting final {
  31. public:
  32. Setting() = default;
  33. explicit Setting(Type val) : global{val} {}
  34. ~Setting() = default;
  35. void SetGlobal(bool to_global) {
  36. use_global = to_global;
  37. }
  38. bool UsingGlobal() const {
  39. return use_global;
  40. }
  41. Type GetValue(bool need_global = false) const {
  42. if (use_global || need_global) {
  43. return global;
  44. }
  45. return local;
  46. }
  47. void SetValue(const Type& value) {
  48. if (use_global) {
  49. global = value;
  50. } else {
  51. local = value;
  52. }
  53. }
  54. private:
  55. bool use_global = true;
  56. Type global{};
  57. Type local{};
  58. };
  59. /**
  60. * The InputSetting class allows for getting a reference to either the global or local members.
  61. * This is required as we cannot easily modify the values of user-defined types within containers
  62. * using the SetValue() member function found in the Setting class. The primary purpose of this
  63. * class is to store an array of 10 PlayerInput structs for both the global and local (per-game)
  64. * setting and allows for easily accessing and modifying both settings.
  65. */
  66. template <typename Type>
  67. class InputSetting final {
  68. public:
  69. InputSetting() = default;
  70. explicit InputSetting(Type val) : global{val} {}
  71. ~InputSetting() = default;
  72. void SetGlobal(bool to_global) {
  73. use_global = to_global;
  74. }
  75. bool UsingGlobal() const {
  76. return use_global;
  77. }
  78. Type& GetValue(bool need_global = false) {
  79. if (use_global || need_global) {
  80. return global;
  81. }
  82. return local;
  83. }
  84. private:
  85. bool use_global = true;
  86. Type global{};
  87. Type local{};
  88. };
  89. struct TouchFromButtonMap {
  90. std::string name;
  91. std::vector<std::string> buttons;
  92. };
  93. struct Values {
  94. // Audio
  95. std::string audio_device_id;
  96. std::string sink_id;
  97. bool audio_muted;
  98. Setting<bool> enable_audio_stretching;
  99. Setting<float> volume;
  100. // Core
  101. Setting<bool> use_multi_core;
  102. // Cpu
  103. Setting<CPUAccuracy> cpu_accuracy;
  104. bool cpuopt_page_tables;
  105. bool cpuopt_block_linking;
  106. bool cpuopt_return_stack_buffer;
  107. bool cpuopt_fast_dispatcher;
  108. bool cpuopt_context_elimination;
  109. bool cpuopt_const_prop;
  110. bool cpuopt_misc_ir;
  111. bool cpuopt_reduce_misalign_checks;
  112. bool cpuopt_fastmem;
  113. Setting<bool> cpuopt_unsafe_unfuse_fma;
  114. Setting<bool> cpuopt_unsafe_reduce_fp_error;
  115. Setting<bool> cpuopt_unsafe_inaccurate_nan;
  116. Setting<bool> cpuopt_unsafe_fastmem_check;
  117. // Renderer
  118. Setting<RendererBackend> renderer_backend;
  119. bool renderer_debug;
  120. Setting<int> vulkan_device;
  121. Setting<u16> resolution_factor{1};
  122. Setting<int> fullscreen_mode;
  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. 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 mouse_panning;
  158. float mouse_panning_sensitivity;
  159. bool mouse_enabled;
  160. std::string mouse_device;
  161. MouseButtonsRaw mouse_buttons;
  162. bool emulate_analog_keyboard;
  163. bool keyboard_enabled;
  164. KeyboardKeysRaw keyboard_keys;
  165. KeyboardModsRaw keyboard_mods;
  166. bool debug_pad_enabled;
  167. ButtonsRaw debug_pad_buttons;
  168. AnalogsRaw debug_pad_analogs;
  169. TouchscreenInput touchscreen;
  170. bool use_touch_from_button;
  171. std::string touch_device;
  172. int touch_from_button_map_index;
  173. std::vector<TouchFromButtonMap> touch_from_button_maps;
  174. std::atomic_bool is_device_reload_pending{true};
  175. // Data Storage
  176. bool use_virtual_sd;
  177. bool gamecard_inserted;
  178. bool gamecard_current_game;
  179. std::string gamecard_path;
  180. // Debugging
  181. bool record_frame_times;
  182. bool use_gdbstub;
  183. u16 gdbstub_port;
  184. std::string program_args;
  185. bool dump_exefs;
  186. bool dump_nso;
  187. bool reporting_services;
  188. bool quest_flag;
  189. bool disable_macro_jit;
  190. bool extended_logging;
  191. bool use_debug_asserts;
  192. bool use_auto_stub;
  193. // Miscellaneous
  194. std::string log_filter;
  195. bool use_dev_keys;
  196. // Services
  197. std::string bcat_backend;
  198. bool bcat_boxcat_local;
  199. // WebService
  200. bool enable_telemetry;
  201. std::string web_api_url;
  202. std::string yuzu_username;
  203. std::string yuzu_token;
  204. // Add-Ons
  205. std::map<u64, std::vector<std::string>> disabled_addons;
  206. };
  207. extern Values values;
  208. bool IsConfiguringGlobal();
  209. void SetConfiguringGlobal(bool is_global);
  210. bool IsGPULevelExtreme();
  211. bool IsGPULevelHigh();
  212. bool IsFastmemEnabled();
  213. float Volume();
  214. std::string GetTimeZoneString();
  215. void LogSettings();
  216. // Restore the global state of all applicable settings in the Values struct
  217. void RestoreGlobalState(bool is_powered_on);
  218. } // namespace Settings