From 0bfffe409589c016e35c1728f3be6cad768deca4 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 5 Jan 2022 03:25:19 +0100 Subject: [PATCH] Config: Port GC Adapter settings to new config system. --- Source/Core/Core/Config/MainSettings.cpp | 20 ++++++++++++---- Source/Core/Core/Config/MainSettings.h | 4 ++-- .../Core/ConfigLoaders/IsSettingSaveable.cpp | 10 +++++++- Source/Core/Core/ConfigManager.cpp | 4 ---- Source/Core/Core/ConfigManager.h | 4 ---- Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp | 3 ++- .../Config/Mapping/GCPadWiiUConfigDialog.cpp | 9 +++---- Source/Core/InputCommon/GCAdapter.cpp | 24 ++++++++++++++++++- 8 files changed, 57 insertions(+), 21 deletions(-) diff --git a/Source/Core/Core/Config/MainSettings.cpp b/Source/Core/Core/Config/MainSettings.cpp index ae7d3ce652..1bafe2b837 100644 --- a/Source/Core/Core/Config/MainSettings.cpp +++ b/Source/Core/Core/Config/MainSettings.cpp @@ -69,14 +69,26 @@ Info GetInfoForSIDevice(u32 channel) SerialInterface::SIDEVICE_NONE)}; } -Info GetInfoForAdapterRumble(u32 channel) +const Info& GetInfoForAdapterRumble(int channel) { - return {{System::Main, "Core", fmt::format("AdapterRumble{}", channel)}, true}; + static const std::array, 4> infos{ + Info{{System::Main, "Core", "AdapterRumble0"}, true}, + Info{{System::Main, "Core", "AdapterRumble1"}, true}, + Info{{System::Main, "Core", "AdapterRumble2"}, true}, + Info{{System::Main, "Core", "AdapterRumble3"}, true}, + }; + return infos[channel]; } -Info GetInfoForSimulateKonga(u32 channel) +const Info& GetInfoForSimulateKonga(int channel) { - return {{System::Main, "Core", fmt::format("SimulateKonga{}", channel)}, false}; + static const std::array, 4> infos{ + Info{{System::Main, "Core", "SimulateKonga0"}, false}, + Info{{System::Main, "Core", "SimulateKonga1"}, false}, + Info{{System::Main, "Core", "SimulateKonga2"}, false}, + Info{{System::Main, "Core", "SimulateKonga3"}, false}, + }; + return infos[channel]; } const Info MAIN_WII_SD_CARD{{System::Main, "Core", "WiiSDCard"}, true}; diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index 1424433647..28beff16d2 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -66,8 +66,8 @@ extern const Info MAIN_BBA_MAC; extern const Info MAIN_BBA_XLINK_IP; extern const Info MAIN_BBA_XLINK_CHAT_OSD; Info GetInfoForSIDevice(u32 channel); -Info GetInfoForAdapterRumble(u32 channel); -Info GetInfoForSimulateKonga(u32 channel); +const Info& GetInfoForAdapterRumble(int channel); +const Info& GetInfoForSimulateKonga(int channel); extern const Info MAIN_WII_SD_CARD; extern const Info MAIN_WII_KEYBOARD; extern const Info MAIN_WIIMOTE_CONTINUOUS_SCANNING; diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index a33d0448c4..a41ef76b09 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -48,7 +48,7 @@ bool IsSettingSaveable(const Config::Location& config_location) } } - static constexpr auto s_setting_saveable = { + static const auto s_setting_saveable = { // Main.Core &Config::MAIN_DEFAULT_ISO.GetLocation(), @@ -89,6 +89,14 @@ bool IsSettingSaveable(const Config::Location& config_location) &Config::MAIN_LOW_DCBZ_HACK.GetLocation(), &Config::MAIN_FPRF.GetLocation(), &Config::MAIN_ACCURATE_NANS.GetLocation(), + &Config::GetInfoForAdapterRumble(0).GetLocation(), + &Config::GetInfoForAdapterRumble(1).GetLocation(), + &Config::GetInfoForAdapterRumble(2).GetLocation(), + &Config::GetInfoForAdapterRumble(3).GetLocation(), + &Config::GetInfoForSimulateKonga(0).GetLocation(), + &Config::GetInfoForSimulateKonga(1).GetLocation(), + &Config::GetInfoForSimulateKonga(2).GetLocation(), + &Config::GetInfoForSimulateKonga(3).GetLocation(), // UI.General diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 3bb3abb8b9..2f936c006b 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -113,8 +113,6 @@ void SConfig::SaveCoreSettings(IniFile& ini) for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) { core->Set(fmt::format("SIDevice{}", i), m_SIDevice[i]); - core->Set(fmt::format("AdapterRumble{}", i), m_AdapterRumble[i]); - core->Set(fmt::format("SimulateKonga{}", i), m_AdapterKonga[i]); } core->Set("WiiSDCard", m_WiiSDCard); core->Set("WiiKeyboard", m_WiiKeyboard); @@ -155,8 +153,6 @@ void SConfig::LoadCoreSettings(IniFile& ini) { core->Get(fmt::format("SIDevice{}", i), &m_SIDevice[i], (i == 0) ? SerialInterface::SIDEVICE_GC_CONTROLLER : SerialInterface::SIDEVICE_NONE); - core->Get(fmt::format("AdapterRumble{}", i), &m_AdapterRumble[i], true); - core->Get(fmt::format("SimulateKonga{}", i), &m_AdapterKonga[i], false); } core->Get("WiiSDCard", &m_WiiSDCard, true); core->Get("WiiKeyboard", &m_WiiKeyboard, false); diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 06e9a8c7f6..1f334076d7 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -151,10 +151,6 @@ struct SConfig float m_EmulationSpeed; - // Input settings - bool m_AdapterRumble[4]; - bool m_AdapterKonga[4]; - SConfig(const SConfig&) = delete; SConfig& operator=(const SConfig&) = delete; SConfig(SConfig&&) = delete; diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp index a3f24824fb..4ce82787bd 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp @@ -7,6 +7,7 @@ #include "Common/CommonTypes.h" #include "Common/Swap.h" +#include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/HW/GCPad.h" @@ -24,7 +25,7 @@ CSIDevice_GCAdapter::CSIDevice_GCAdapter(SIDevices device, int device_number) // get the correct pad number that should rumble locally when using netplay const int pad_num = NetPlay_InGamePadToLocalPad(m_device_number); if (pad_num < 4) - m_simulate_konga = SConfig::GetInstance().m_AdapterKonga[pad_num]; + m_simulate_konga = Config::Get(Config::GetInfoForSimulateKonga(pad_num)); } GCPadStatus CSIDevice_GCAdapter::GetPadStatus() diff --git a/Source/Core/DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.cpp b/Source/Core/DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.cpp index 2f25ea450a..af9231abd1 100644 --- a/Source/Core/DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/GCPadWiiUConfigDialog.cpp @@ -8,6 +8,7 @@ #include #include +#include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" #include "DolphinQt/QtUtils/QueueOnObject.h" @@ -86,12 +87,12 @@ void GCPadWiiUConfigDialog::UpdateAdapterStatus() void GCPadWiiUConfigDialog::LoadSettings() { - m_rumble->setChecked(SConfig::GetInstance().m_AdapterRumble[m_port]); - m_simulate_bongos->setChecked(SConfig::GetInstance().m_AdapterKonga[m_port]); + m_rumble->setChecked(Config::Get(Config::GetInfoForAdapterRumble(m_port))); + m_simulate_bongos->setChecked(Config::Get(Config::GetInfoForSimulateKonga(m_port))); } void GCPadWiiUConfigDialog::SaveSettings() { - SConfig::GetInstance().m_AdapterRumble[m_port] = m_rumble->isChecked(); - SConfig::GetInstance().m_AdapterKonga[m_port] = m_simulate_bongos->isChecked(); + Config::SetBaseOrCurrent(Config::GetInfoForAdapterRumble(m_port), m_rumble->isChecked()); + Config::SetBaseOrCurrent(Config::GetInfoForSimulateKonga(m_port), m_simulate_bongos->isChecked()); } diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index bf8ec87b3b..26984ca4dc 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -2,14 +2,17 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include +#include #include "Common/Event.h" #include "Common/Flag.h" #include "Common/Logging/Log.h" #include "Common/ScopeGuard.h" #include "Common/Thread.h" +#include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/CoreTiming.h" @@ -79,6 +82,9 @@ static u8 s_endpoint_out = 0; static u64 s_last_init = 0; +static std::optional s_config_callback_id = std::nullopt; +static std::array s_config_rumble_enabled{}; + static void Read() { int payload_size = 0; @@ -196,6 +202,12 @@ void SetAdapterCallback(std::function func) s_detect_callback = func; } +static void RefreshConfig() +{ + for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) + s_config_rumble_enabled[i] = Config::Get(Config::GetInfoForAdapterRumble(i)); +} + void Init() { if (s_handle != nullptr) @@ -211,6 +223,10 @@ void Init() s_status = NO_ADAPTER_DETECTED; + if (!s_config_callback_id) + s_config_callback_id = Config::AddConfigChangedCallback(RefreshConfig); + RefreshConfig(); + if (UseAdapter()) StartScanThread(); } @@ -382,6 +398,12 @@ void Shutdown() Reset(); s_status = NO_ADAPTER_DETECTED; + + if (s_config_callback_id) + { + Config::RemoveConfigChangedCallback(*s_config_callback_id); + s_config_callback_id = std::nullopt; + } } static void Reset() @@ -557,7 +579,7 @@ static void ResetRumbleLockNeeded() void Output(int chan, u8 rumble_command) { - if (s_handle == nullptr || !UseAdapter() || !SConfig::GetInstance().m_AdapterRumble[chan]) + if (s_handle == nullptr || !UseAdapter() || !s_config_rumble_enabled[chan]) return; // Skip over rumble commands if it has not changed or the controller is wireless