settings.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 Settings {
  15. enum class RendererBackend {
  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 {
  25. Accurate = 0,
  26. Unsafe = 1,
  27. DebugMode = 2,
  28. };
  29. extern bool configuring_global;
  30. template <typename Type>
  31. class Setting final {
  32. public:
  33. Setting() = default;
  34. explicit Setting(Type val) : global{val} {}
  35. ~Setting() = default;
  36. void SetGlobal(bool to_global) {
  37. use_global = to_global;
  38. }
  39. bool UsingGlobal() const {
  40. return use_global;
  41. }
  42. Type GetValue(bool need_global = false) const {
  43. if (use_global || need_global) {
  44. return global;
  45. }
  46. return local;
  47. }
  48. void SetValue(const Type& value) {
  49. if (use_global) {
  50. global = value;
  51. } else {
  52. local = value;
  53. }
  54. }
  55. private:
  56. bool use_global = true;
  57. Type global{};
  58. Type local{};
  59. };
  60. struct Values {
  61. // Audio
  62. std::string audio_device_id;
  63. std::string sink_id;
  64. bool audio_muted;
  65. Setting<bool> enable_audio_stretching;
  66. Setting<float> volume;
  67. // Core
  68. Setting<bool> use_multi_core;
  69. // Cpu
  70. CPUAccuracy cpu_accuracy;
  71. bool cpuopt_page_tables;
  72. bool cpuopt_block_linking;
  73. bool cpuopt_return_stack_buffer;
  74. bool cpuopt_fast_dispatcher;
  75. bool cpuopt_context_elimination;
  76. bool cpuopt_const_prop;
  77. bool cpuopt_misc_ir;
  78. bool cpuopt_reduce_misalign_checks;
  79. bool cpuopt_unsafe_unfuse_fma;
  80. bool cpuopt_unsafe_reduce_fp_error;
  81. // Renderer
  82. Setting<RendererBackend> renderer_backend;
  83. bool renderer_debug;
  84. Setting<int> vulkan_device;
  85. Setting<u16> resolution_factor = Setting(static_cast<u16>(1));
  86. Setting<int> aspect_ratio;
  87. Setting<int> max_anisotropy;
  88. Setting<bool> use_frame_limit;
  89. Setting<u16> frame_limit;
  90. Setting<bool> use_disk_shader_cache;
  91. Setting<GPUAccuracy> gpu_accuracy;
  92. Setting<bool> use_asynchronous_gpu_emulation;
  93. Setting<bool> use_vsync;
  94. Setting<bool> use_assembly_shaders;
  95. Setting<bool> use_asynchronous_shaders;
  96. Setting<bool> use_fast_gpu_time;
  97. Setting<float> bg_red;
  98. Setting<float> bg_green;
  99. Setting<float> bg_blue;
  100. // System
  101. Setting<std::optional<u32>> rng_seed;
  102. // Measured in seconds since epoch
  103. Setting<std::optional<std::chrono::seconds>> custom_rtc;
  104. // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
  105. std::chrono::seconds custom_rtc_differential;
  106. s32 current_user;
  107. Setting<s32> language_index;
  108. Setting<s32> region_index;
  109. Setting<s32> time_zone_index;
  110. Setting<s32> sound_index;
  111. // Controls
  112. std::array<PlayerInput, 10> players;
  113. bool use_docked_mode;
  114. bool mouse_enabled;
  115. std::string mouse_device;
  116. MouseButtonsRaw mouse_buttons;
  117. bool keyboard_enabled;
  118. KeyboardKeysRaw keyboard_keys;
  119. KeyboardModsRaw keyboard_mods;
  120. bool debug_pad_enabled;
  121. ButtonsRaw debug_pad_buttons;
  122. AnalogsRaw debug_pad_analogs;
  123. std::string motion_device;
  124. bool vibration_enabled;
  125. TouchscreenInput touchscreen;
  126. std::atomic_bool is_device_reload_pending{true};
  127. std::string udp_input_address;
  128. u16 udp_input_port;
  129. u8 udp_pad_index;
  130. // Data Storage
  131. bool use_virtual_sd;
  132. bool gamecard_inserted;
  133. bool gamecard_current_game;
  134. std::string gamecard_path;
  135. // Debugging
  136. bool record_frame_times;
  137. bool use_gdbstub;
  138. u16 gdbstub_port;
  139. std::string program_args;
  140. bool dump_exefs;
  141. bool dump_nso;
  142. bool reporting_services;
  143. bool quest_flag;
  144. bool disable_macro_jit;
  145. // Misceallaneous
  146. std::string log_filter;
  147. bool use_dev_keys;
  148. // Services
  149. std::string bcat_backend;
  150. bool bcat_boxcat_local;
  151. // WebService
  152. bool enable_telemetry;
  153. std::string web_api_url;
  154. std::string yuzu_username;
  155. std::string yuzu_token;
  156. // Add-Ons
  157. std::map<u64, std::vector<std::string>> disabled_addons;
  158. } extern values;
  159. float Volume();
  160. bool IsGPULevelExtreme();
  161. bool IsGPULevelHigh();
  162. std::string GetTimeZoneString();
  163. void Apply();
  164. void LogSettings();
  165. // Restore the global state of all applicable settings in the Values struct
  166. void RestoreGlobalState();
  167. // Fixes settings that are known to cause issues with the emulator
  168. void Sanitize();
  169. } // namespace Settings