diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 0da159559b..9d8224315e 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -12,6 +12,76 @@ namespace Settings { Values values = {}; +Values::Values() : current_game(default_game) {} + +void Values::SetUpdateCurrentGameFunction(std::function new_function) { + update_current_game = std::move(new_function); +} + +u64 Values::CurrentTitleID() { + return current_title_id; +} + +void Values::SetCurrentTitleID(u64 title_id) { + // Ignore Updates + title_id &= ~0x800; + + if (current_title_id == title_id) + return; + + update_current_game(title_id, current_game); +} + +PerGameValues& Values::operator[](u64 title_id) { + // Ignore Updates + title_id &= ~0x800; + + if (current_title_id == title_id) + return current_game; + + if (!update_current_game(title_id, current_game)) + return default_game; + + current_title_id = title_id; + return current_game; +} + +const PerGameValues& Values::operator[](u64 title_id) const { + // Ignore Updates + title_id &= ~0x800; + + if (current_title_id == title_id) + return current_game; + + return default_game; +} + +PerGameValues* Values::operator->() { + if (current_title_id == 0) + return &default_game; + + return ¤t_game; +} + +const PerGameValues* Values::operator->() const { + if (current_title_id == 0) + return &default_game; + + return ¤t_game; +} + +PerGameValues& Values::operator*() { + if (current_title_id == 0) + return default_game; + return current_game; +} + +const PerGameValues& Values::operator*() const { + if (current_title_id == 0) + return default_game; + return current_game; +} + void Apply() { GDBStub::SetServerPort(values.gdbstub_port); GDBStub::ToggleServer(values.use_gdbstub); diff --git a/src/core/settings.h b/src/core/settings.h index b5aeff29b1..1ecc157c36 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -6,11 +6,16 @@ #include #include +#include #include +#include #include "common/common_types.h" +#include "input_common/motion_emu.h" namespace Settings { +constexpr u64 DEFAULT_PER_GAME = 0; + namespace NativeButton { enum Values { A, @@ -110,28 +115,15 @@ static const std::array mapping = {{ }}; } // namespace NativeAnalog -struct Values { - // System - bool use_docked_mode; - bool enable_nfc; - int current_user; - int language_index; - +struct PerGameValues { // Controls std::array buttons; std::array analogs; std::string motion_device; std::string touch_device; - std::atomic_bool is_device_reload_pending{true}; - // Core - bool use_cpu_jit; - bool use_multi_core; - - // Data Storage - bool use_virtual_sd; - std::string nand_dir; - std::string sdmc_dir; + // System + bool use_docked_mode; // Renderer float resolution_factor; @@ -143,10 +135,6 @@ struct Values { float bg_green; float bg_blue; - std::string log_filter; - - bool use_dev_keys; - // Audio std::string sink_id; bool enable_audio_stretching; @@ -154,15 +142,69 @@ struct Values { float volume; // Debugging + std::string program_args; + + // Add-Ons + std::vector disabled_patches; +}; + +struct Values { + Values(); + + // Per-Game + PerGameValues default_game; + + void SetUpdateCurrentGameFunction(std::function new_function); + u64 CurrentTitleID(); + void SetCurrentTitleID(u64 title_id); + + PerGameValues& operator[](u64 title_id); + const PerGameValues& operator[](u64 title_id) const; + PerGameValues* operator->(); + const PerGameValues* operator->() const; + PerGameValues& operator*(); + const PerGameValues& operator*() const; + + // Core + bool use_cpu_jit; + bool use_multi_core; + + // System + std::string username; + bool enable_nfc; + int current_user; + int language_index; + + // Renderer + bool use_accurate_framebuffers; + + // Input + std::atomic_bool is_device_reload_pending{true}; + + // Data Storage + bool use_virtual_sd; + std::string nand_dir; + std::string sdmc_dir; + + // Debugging + std::string log_filter; + bool use_dev_keys; bool use_gdbstub; u16 gdbstub_port; - std::string program_args; // WebService bool enable_telemetry; std::string web_api_url; std::string yuzu_username; std::string yuzu_token; + +private: + u64 current_title_id = 0; + PerGameValues current_game; + + std::function update_current_game = [](u64 in, PerGameValues& val) { + return false; + }; } extern values; void Apply();