From a4c6712a4be249bf668df7f0ff83a0a5236283b2 Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 14 Apr 2021 16:07:40 -0700 Subject: common: Move settings to common from core. - Removes a dependency on core and input_common from common. --- src/common/settings.h | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 src/common/settings.h (limited to 'src/common/settings.h') diff --git a/src/common/settings.h b/src/common/settings.h new file mode 100644 index 000000000..d39b4aa45 --- /dev/null +++ b/src/common/settings.h @@ -0,0 +1,261 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "common/common_types.h" +#include "common/settings_input.h" + +namespace Settings { + +enum class RendererBackend : u32 { + OpenGL = 0, + Vulkan = 1, +}; + +enum class GPUAccuracy : u32 { + Normal = 0, + High = 1, + Extreme = 2, +}; + +enum class CPUAccuracy : u32 { + Accurate = 0, + Unsafe = 1, + DebugMode = 2, +}; + +template +class Setting final { +public: + Setting() = default; + explicit Setting(Type val) : global{val} {} + ~Setting() = default; + void SetGlobal(bool to_global) { + use_global = to_global; + } + bool UsingGlobal() const { + return use_global; + } + Type GetValue(bool need_global = false) const { + if (use_global || need_global) { + return global; + } + return local; + } + void SetValue(const Type& value) { + if (use_global) { + global = value; + } else { + local = value; + } + } + +private: + bool use_global = true; + Type global{}; + Type local{}; +}; + +/** + * The InputSetting class allows for getting a reference to either the global or local members. + * This is required as we cannot easily modify the values of user-defined types within containers + * using the SetValue() member function found in the Setting class. The primary purpose of this + * class is to store an array of 10 PlayerInput structs for both the global and local (per-game) + * setting and allows for easily accessing and modifying both settings. + */ +template +class InputSetting final { +public: + InputSetting() = default; + explicit InputSetting(Type val) : global{val} {} + ~InputSetting() = default; + void SetGlobal(bool to_global) { + use_global = to_global; + } + bool UsingGlobal() const { + return use_global; + } + Type& GetValue(bool need_global = false) { + if (use_global || need_global) { + return global; + } + return local; + } + +private: + bool use_global = true; + Type global{}; + Type local{}; +}; + +struct TouchFromButtonMap { + std::string name; + std::vector buttons; +}; + +struct Values { + // Audio + std::string audio_device_id; + std::string sink_id; + bool audio_muted; + Setting enable_audio_stretching; + Setting volume; + + // Core + Setting use_multi_core; + + // Cpu + CPUAccuracy cpu_accuracy; + + bool cpuopt_page_tables; + bool cpuopt_block_linking; + bool cpuopt_return_stack_buffer; + bool cpuopt_fast_dispatcher; + bool cpuopt_context_elimination; + bool cpuopt_const_prop; + bool cpuopt_misc_ir; + bool cpuopt_reduce_misalign_checks; + + bool cpuopt_unsafe_unfuse_fma; + bool cpuopt_unsafe_reduce_fp_error; + bool cpuopt_unsafe_inaccurate_nan; + + // Renderer + Setting renderer_backend; + bool renderer_debug; + Setting vulkan_device; + + Setting resolution_factor{1}; + Setting fullscreen_mode; + Setting aspect_ratio; + Setting max_anisotropy; + Setting use_frame_limit; + Setting frame_limit; + Setting use_disk_shader_cache; + Setting gpu_accuracy; + Setting use_asynchronous_gpu_emulation; + Setting use_nvdec_emulation; + Setting use_vsync; + Setting use_assembly_shaders; + Setting use_asynchronous_shaders; + Setting use_fast_gpu_time; + + Setting bg_red; + Setting bg_green; + Setting bg_blue; + + // System + Setting> rng_seed; + // Measured in seconds since epoch + Setting> custom_rtc; + // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` + std::chrono::seconds custom_rtc_differential; + + s32 current_user; + Setting language_index; + Setting region_index; + Setting time_zone_index; + Setting sound_index; + + // Controls + InputSetting> players; + + Setting use_docked_mode; + + Setting vibration_enabled; + Setting enable_accurate_vibrations; + + Setting motion_enabled; + std::string motion_device; + std::string udp_input_servers; + + bool mouse_panning; + float mouse_panning_sensitivity; + bool mouse_enabled; + std::string mouse_device; + MouseButtonsRaw mouse_buttons; + + bool emulate_analog_keyboard; + bool keyboard_enabled; + KeyboardKeysRaw keyboard_keys; + KeyboardModsRaw keyboard_mods; + + bool debug_pad_enabled; + ButtonsRaw debug_pad_buttons; + AnalogsRaw debug_pad_analogs; + + TouchscreenInput touchscreen; + + bool use_touch_from_button; + std::string touch_device; + int touch_from_button_map_index; + std::vector touch_from_button_maps; + + std::atomic_bool is_device_reload_pending{true}; + + // Data Storage + bool use_virtual_sd; + bool gamecard_inserted; + bool gamecard_current_game; + std::string gamecard_path; + + // Debugging + bool record_frame_times; + bool use_gdbstub; + u16 gdbstub_port; + std::string program_args; + bool dump_exefs; + bool dump_nso; + bool reporting_services; + bool quest_flag; + bool disable_macro_jit; + bool extended_logging; + bool use_debug_asserts; + bool use_auto_stub; + + // Miscellaneous + std::string log_filter; + bool use_dev_keys; + + // Services + std::string bcat_backend; + bool bcat_boxcat_local; + + // WebService + bool enable_telemetry; + std::string web_api_url; + std::string yuzu_username; + std::string yuzu_token; + + // Add-Ons + std::map> disabled_addons; +}; + +extern Values values; + +bool IsConfiguringGlobal(); +void SetConfiguringGlobal(bool is_global); + +bool IsGPULevelExtreme(); +bool IsGPULevelHigh(); + +float Volume(); + +std::string GetTimeZoneString(); + +void LogSettings(); + +// Restore the global state of all applicable settings in the Values struct +void RestoreGlobalState(bool is_powered_on); + +} // namespace Settings -- cgit v1.2.3