From 5c325eef38ca087ecb7a4f95b8315101723f2806 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Thu, 6 Jan 2022 08:08:02 +0100 Subject: [PATCH] Config: Port SI device settings to new config system. --- Source/Core/Core/BootManager.cpp | 22 ---------------- Source/Core/Core/Config/MainSettings.cpp | 16 +++++++++--- Source/Core/Core/Config/MainSettings.h | 7 +++++- .../Core/ConfigLoaders/GameConfigLoader.cpp | 4 +++ .../Core/ConfigLoaders/IsSettingSaveable.cpp | 4 +++ Source/Core/Core/ConfigManager.cpp | 9 ------- Source/Core/Core/ConfigManager.h | 2 -- Source/Core/Core/HW/SI/SI.cpp | 5 ++-- Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp | 3 +-- .../Core/Core/HW/SI/SI_DeviceGCController.cpp | 23 +++++++++++++++-- .../Core/Core/HW/SI/SI_DeviceGCController.h | 11 +++++++- Source/Core/Core/Movie.cpp | 13 ++++++---- Source/Core/Core/NetPlayClient.cpp | 11 +++++--- .../Config/GamecubeControllersWidget.cpp | 5 ++-- Source/Core/DolphinQt/MainWindow.cpp | 10 +++++--- Source/Core/InputCommon/GCAdapter.cpp | 10 +++++--- Source/Core/InputCommon/GCAdapter_Android.cpp | 25 ++++++++++++++++--- 17 files changed, 114 insertions(+), 66 deletions(-) diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index e61f873539..a5e0f434c1 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -66,7 +66,6 @@ public: // alone on restore (false) bool bSetVolume = false; std::array bSetWiimoteSource{}; - std::array bSetPads{}; private: bool valid = false; @@ -77,7 +76,6 @@ private: int iSyncGpuMinDistance = 0; float fSyncGpuOverclock = 0; std::array iWiimoteSource{}; - std::array Pads{}; }; void ConfigCache::SaveConfig(const SConfig& config) @@ -94,11 +92,8 @@ void ConfigCache::SaveConfig(const SConfig& config) for (int i = 0; i != MAX_BBMOTES; ++i) iWiimoteSource[i] = WiimoteCommon::GetSource(i); - std::copy(std::begin(config.m_SIDevice), std::end(config.m_SIDevice), std::begin(Pads)); - bSetVolume = false; bSetWiimoteSource.fill(false); - bSetPads.fill(false); } void ConfigCache::RestoreConfig(SConfig* config) @@ -125,12 +120,6 @@ void ConfigCache::RestoreConfig(SConfig* config) WiimoteCommon::SetSource(i, iWiimoteSource[i]); } } - - for (unsigned int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) - { - if (bSetPads[i]) - config->m_SIDevice[i] = Pads[i]; - } } static ConfigCache config_cache; @@ -161,17 +150,6 @@ bool BootCore(std::unique_ptr boot, const WindowSystemInfo& wsi) core_section->Get("MMU", &StartUp.bMMU, StartUp.bMMU); core_section->Get("SyncGPU", &StartUp.bSyncGPU, StartUp.bSyncGPU); - for (unsigned int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) - { - int source; - controls_section->Get(fmt::format("PadType{}", i), &source, -1); - if (source >= SerialInterface::SIDEVICE_NONE && source < SerialInterface::SIDEVICE_COUNT) - { - StartUp.m_SIDevice[i] = static_cast(source); - config_cache.bSetPads[i] = true; - } - } - // Wii settings if (StartUp.bWii) { diff --git a/Source/Core/Core/Config/MainSettings.cpp b/Source/Core/Core/Config/MainSettings.cpp index 23a1ae99a6..8910d27f66 100644 --- a/Source/Core/Core/Config/MainSettings.cpp +++ b/Source/Core/Core/Config/MainSettings.cpp @@ -76,11 +76,19 @@ const Info MAIN_BBA_MAC{{System::Main, "Core", "BBA_MAC"}, ""}; const Info MAIN_BBA_XLINK_IP{{System::Main, "Core", "BBA_XLINK_IP"}, "127.0.0.1"}; const Info MAIN_BBA_XLINK_CHAT_OSD{{System::Main, "Core", "BBA_XLINK_CHAT_OSD"}, true}; -Info GetInfoForSIDevice(u32 channel) +const Info& GetInfoForSIDevice(int channel) { - return {{System::Main, "Core", fmt::format("SIDevice{}", channel)}, - static_cast(channel == 0 ? SerialInterface::SIDEVICE_GC_CONTROLLER : - SerialInterface::SIDEVICE_NONE)}; + static const std::array, 4> infos{ + Info{{System::Main, "Core", "SIDevice0"}, + SerialInterface::SIDEVICE_GC_CONTROLLER}, + Info{{System::Main, "Core", "SIDevice1"}, + SerialInterface::SIDEVICE_NONE}, + Info{{System::Main, "Core", "SIDevice2"}, + SerialInterface::SIDEVICE_NONE}, + Info{{System::Main, "Core", "SIDevice3"}, + SerialInterface::SIDEVICE_NONE}, + }; + return infos[channel]; } const Info& GetInfoForAdapterRumble(int channel) diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index 6b7777d48b..5eb75241f2 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -36,6 +36,11 @@ namespace ExpansionInterface enum TEXIDevices : int; } +namespace SerialInterface +{ +enum SIDevices : int; +} + namespace Config { // Main.Core @@ -71,7 +76,7 @@ const Info& GetInfoForEXIDevice(int channel); 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); +const Info& GetInfoForSIDevice(int channel); const Info& GetInfoForAdapterRumble(int channel); const Info& GetInfoForSimulateKonga(int channel); extern const Info MAIN_WII_SD_CARD; diff --git a/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp index 9012e7c9f9..812b10269b 100644 --- a/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp +++ b/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp @@ -75,6 +75,10 @@ static const INIToLocationMap& GetINIToLocationMap() {{"Wii", "Language"}, {Config::SYSCONF_LANGUAGE.GetLocation()}}, {{"Core", "HLE_BS2"}, {Config::MAIN_SKIP_IPL.GetLocation()}}, {{"Core", "GameCubeLanguage"}, {Config::MAIN_GC_LANGUAGE.GetLocation()}}, + {{"Core", "PadType0"}, {Config::GetInfoForSIDevice(0).GetLocation()}}, + {{"Core", "PadType1"}, {Config::GetInfoForSIDevice(1).GetLocation()}}, + {{"Core", "PadType2"}, {Config::GetInfoForSIDevice(2).GetLocation()}}, + {{"Core", "PadType3"}, {Config::GetInfoForSIDevice(3).GetLocation()}}, }; return ini_to_location; } diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 0713f550ac..a505a815ae 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -113,6 +113,10 @@ bool IsSettingSaveable(const Config::Location& config_location) &Config::MAIN_SLOT_A.GetLocation(), &Config::MAIN_SLOT_B.GetLocation(), &Config::MAIN_SERIAL_PORT_1.GetLocation(), + &Config::GetInfoForSIDevice(0).GetLocation(), + &Config::GetInfoForSIDevice(1).GetLocation(), + &Config::GetInfoForSIDevice(2).GetLocation(), + &Config::GetInfoForSIDevice(3).GetLocation(), // UI.General diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index d222941b65..09f4c79853 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -104,10 +104,6 @@ void SConfig::SaveCoreSettings(IniFile& ini) core->Set("SyncGpuMaxDistance", iSyncGpuMaxDistance); core->Set("SyncGpuMinDistance", iSyncGpuMinDistance); core->Set("SyncGpuOverclock", fSyncGpuOverclock); - for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) - { - core->Set(fmt::format("SIDevice{}", i), m_SIDevice[i]); - } core->Set("MMU", bMMU); } @@ -127,11 +123,6 @@ void SConfig::LoadCoreSettings(IniFile& ini) IniFile::Section* core = ini.GetOrCreateSection("Core"); core->Get("CPUThread", &bCPUThread, true); - for (size_t i = 0; i < std::size(m_SIDevice); ++i) - { - core->Get(fmt::format("SIDevice{}", i), &m_SIDevice[i], - (i == 0) ? SerialInterface::SIDEVICE_GC_CONTROLLER : SerialInterface::SIDEVICE_NONE); - } core->Get("MMU", &bMMU, bMMU); core->Get("BBDumpPort", &iBBDumpPort, -1); core->Get("SyncGPU", &bSyncGPU, false); diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 318f5db807..a8a1c70fdf 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -114,8 +114,6 @@ struct SConfig static IniFile LoadLocalGameIni(const std::string& id, std::optional revision); static IniFile LoadGameIni(const std::string& id, std::optional revision); - SerialInterface::SIDevices m_SIDevice[4]; - SConfig(const SConfig&) = delete; SConfig& operator=(const SConfig&) = delete; SConfig(SConfig&&) = delete; diff --git a/Source/Core/Core/HW/SI/SI.cpp b/Source/Core/Core/HW/SI/SI.cpp index c55ce4e932..2a1549b213 100644 --- a/Source/Core/Core/HW/SI/SI.cpp +++ b/Source/Core/Core/HW/SI/SI.cpp @@ -16,6 +16,7 @@ #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" #include "Common/Swap.h" +#include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" #include "Core/CoreTiming.h" #include "Core/HW/MMIO.h" @@ -411,7 +412,7 @@ void Init() } else if (Movie::IsUsingPad(i)) { - SIDevices current = SConfig::GetInstance().m_SIDevice[i]; + SIDevices current = Config::Get(Config::GetInfoForSIDevice(i)); // GC pad-compatible devices can be used for both playing and recording if (Movie::IsUsingBongo(i)) s_desired_device_types[i] = SIDEVICE_GC_TARUKONGA; @@ -423,7 +424,7 @@ void Init() } else if (!NetPlay::IsNetPlayRunning()) { - s_desired_device_types[i] = SConfig::GetInstance().m_SIDevice[i]; + s_desired_device_types[i] = Config::Get(Config::GetInfoForSIDevice(i)); } AddDevice(s_desired_device_types[i], i); diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp index 4ce82787bd..e57cdd0c0b 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCAdapter.cpp @@ -81,9 +81,8 @@ bool CSIDevice_GCAdapter::GetData(u32& hi, u32& low) return true; } -void CSIDevice_GCController::Rumble(int pad_num, ControlState strength) +void CSIDevice_GCController::Rumble(int pad_num, ControlState strength, SIDevices device) { - SIDevices device = SConfig::GetInstance().m_SIDevice[pad_num]; if (device == SIDEVICE_WIIU_ADAPTER) GCAdapter::Output(pad_num, static_cast(strength)); else if (SIDevice_IsGCController(device)) diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp index 985033f97b..568e3ccf6a 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.cpp @@ -10,6 +10,7 @@ #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" #include "Common/Swap.h" +#include "Core/Config/MainSettings.h" #include "Core/CoreTiming.h" #include "Core/HW/GCPad.h" #include "Core/HW/ProcessorInterface.h" @@ -33,6 +34,14 @@ CSIDevice_GCController::CSIDevice_GCController(SIDevices device, int device_numb m_origin.origin_stick_y = GCPadStatus::MAIN_STICK_CENTER_Y; m_origin.substick_x = GCPadStatus::C_STICK_CENTER_X; m_origin.substick_y = GCPadStatus::C_STICK_CENTER_Y; + + m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); }); + RefreshConfig(); +} + +CSIDevice_GCController::~CSIDevice_GCController() +{ + Config::RemoveConfigChangedCallback(m_config_changed_callback_id); } int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length) @@ -299,10 +308,11 @@ void CSIDevice_GCController::SendCommand(u32 command, u8 poll) if (pad_num < 4) { + const SIDevices device = m_config_si_devices[pad_num]; if (type == 1) - CSIDevice_GCController::Rumble(pad_num, 1.0); + CSIDevice_GCController::Rumble(pad_num, 1.0, device); else - CSIDevice_GCController::Rumble(pad_num, 0.0); + CSIDevice_GCController::Rumble(pad_num, 0.0, device); } if (poll == 0) @@ -328,6 +338,15 @@ void CSIDevice_GCController::DoState(PointerWrap& p) p.Do(m_last_button_combo); } +void CSIDevice_GCController::RefreshConfig() +{ + for (int i = 0; i < 4; ++i) + { + const SerialInterface::SIDevices device = Config::Get(Config::GetInfoForSIDevice(i)); + m_config_si_devices[i] = device; + } +} + CSIDevice_TaruKonga::CSIDevice_TaruKonga(SIDevices device, int device_number) : CSIDevice_GCController(device, device_number) { diff --git a/Source/Core/Core/HW/SI/SI_DeviceGCController.h b/Source/Core/Core/HW/SI/SI_DeviceGCController.h index 6d7f4722af..0630edb17d 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGCController.h +++ b/Source/Core/Core/HW/SI/SI_DeviceGCController.h @@ -3,6 +3,8 @@ #pragma once +#include + #include "Core/HW/GCPad.h" #include "Core/HW/SI/SI_Device.h" #include "InputCommon/GCPadStatus.h" @@ -52,6 +54,7 @@ protected: public: // Constructor CSIDevice_GCController(SIDevices device, int device_number); + ~CSIDevice_GCController() override; // Run the SI Buffer int RunBuffer(u8* buffer, int request_length) override; @@ -74,12 +77,18 @@ public: static int NetPlay_InGamePadToLocalPad(int pad_num); // Direct rumble to the right GC Controller - static void Rumble(int pad_num, ControlState strength); + static void Rumble(int pad_num, ControlState strength, SIDevices device); static void HandleMoviePadStatus(int device_number, GCPadStatus* pad_status); protected: void SetOrigin(const GCPadStatus& pad_status); + +private: + void RefreshConfig(); + + std::array m_config_si_devices{}; + size_t m_config_changed_callback_id; }; // "TaruKonga", the DK Bongo controller diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 8b4402e2bc..4f73226e60 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -453,9 +453,10 @@ void ChangePads() for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) { - if (SConfig::GetInstance().m_SIDevice[i] == SerialInterface::SIDEVICE_GC_GBA_EMULATED) + const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(i)); + if (si_device == SerialInterface::SIDEVICE_GC_GBA_EMULATED) controllers[i] = ControllerType::GBA; - else if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[i])) + else if (SerialInterface::SIDevice_IsGCController(si_device)) controllers[i] = ControllerType::GC; else controllers[i] = ControllerType::None; @@ -473,9 +474,10 @@ void ChangePads() } else if (IsUsingPad(i)) { - if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[i])) + const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(i)); + if (SerialInterface::SIDevice_IsGCController(si_device)) { - device = SConfig::GetInstance().m_SIDevice[i]; + device = si_device; } else { @@ -548,7 +550,8 @@ bool BeginRecordingInput(const ControllerTypeArray& controllers, for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) { - if (SConfig::GetInstance().m_SIDevice[i] == SerialInterface::SIDEVICE_GC_TARUKONGA) + const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(i)); + if (si_device == SerialInterface::SIDEVICE_GC_TARUKONGA) s_bongos |= (1 << i); } diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 4e40ec7f3b..5497db41ac 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -1838,11 +1838,13 @@ void NetPlayClient::UpdateDevices() else if (player_id == m_local_player->pid) { // Use local controller types for local controllers if they are compatible - if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[local_pad])) + const SerialInterface::SIDevices si_device = + Config::Get(Config::GetInfoForSIDevice(local_pad)); + if (SerialInterface::SIDevice_IsGCController(si_device)) { - SerialInterface::ChangeDevice(SConfig::GetInstance().m_SIDevice[local_pad], pad); + SerialInterface::ChangeDevice(si_device, pad); - if (SConfig::GetInstance().m_SIDevice[local_pad] == SerialInterface::SIDEVICE_WIIU_ADAPTER) + if (si_device == SerialInterface::SIDEVICE_WIIU_ADAPTER) { GCAdapter::ResetDeviceType(local_pad); } @@ -2161,7 +2163,8 @@ bool NetPlayClient::PollLocalPad(const int local_pad, sf::Packet& packet) { pad_status = Pad::GetGBAStatus(local_pad); } - else if (SConfig::GetInstance().m_SIDevice[local_pad] == SerialInterface::SIDEVICE_WIIU_ADAPTER) + else if (Config::Get(Config::GetInfoForSIDevice(local_pad)) == + SerialInterface::SIDEVICE_WIIU_ADAPTER) { pad_status = GCAdapter::Input(local_pad); } diff --git a/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp b/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp index d940f46461..05db15ae13 100644 --- a/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp +++ b/Source/Core/DolphinQt/Config/GamecubeControllersWidget.cpp @@ -178,7 +178,8 @@ void GamecubeControllersWidget::LoadSettings() { for (size_t i = 0; i < m_gc_groups.size(); i++) { - const SerialInterface::SIDevices si_device = SConfig::GetInstance().m_SIDevice[i]; + const SerialInterface::SIDevices si_device = + Config::Get(Config::GetInfoForSIDevice(static_cast(i))); const std::optional gc_index = ToGCMenuIndex(si_device); if (gc_index) { @@ -194,7 +195,7 @@ void GamecubeControllersWidget::SaveSettings() { const int index = m_gc_controller_boxes[i]->currentIndex(); const SerialInterface::SIDevices si_device = FromGCMenuIndex(index); - SConfig::GetInstance().m_SIDevice[i] = si_device; + Config::SetBaseOrCurrent(Config::GetInfoForSIDevice(static_cast(i)), si_device); if (Core::IsRunning()) SerialInterface::ChangeDevice(si_device, static_cast(i)); diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index ef462d313f..4585209ba3 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -1728,9 +1728,10 @@ void MainWindow::OnStartRecording() for (int i = 0; i < 4; i++) { - if (SConfig::GetInstance().m_SIDevice[i] == SerialInterface::SIDEVICE_GC_GBA_EMULATED) + const SerialInterface::SIDevices si_device = Config::Get(Config::GetInfoForSIDevice(i)); + if (si_device == SerialInterface::SIDEVICE_GC_GBA_EMULATED) controllers[i] = Movie::ControllerType::GBA; - else if (SerialInterface::SIDevice_IsGCController(SConfig::GetInstance().m_SIDevice[i])) + else if (SerialInterface::SIDevice_IsGCController(si_device)) controllers[i] = Movie::ControllerType::GC; else controllers[i] = Movie::ControllerType::None; @@ -1782,8 +1783,9 @@ void MainWindow::ShowTASInput() { for (int i = 0; i < num_gc_controllers; i++) { - if (SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_NONE && - SConfig::GetInstance().m_SIDevice[i] != SerialInterface::SIDEVICE_GC_GBA) + const auto si_device = Config::Get(Config::GetInfoForSIDevice(i)); + if (si_device != SerialInterface::SIDEVICE_NONE && + si_device != SerialInterface::SIDEVICE_GC_GBA) { m_gc_tas_input_windows[i]->show(); m_gc_tas_input_windows[i]->raise(); diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp index 26984ca4dc..e03cf99f82 100644 --- a/Source/Core/InputCommon/GCAdapter.cpp +++ b/Source/Core/InputCommon/GCAdapter.cpp @@ -83,6 +83,8 @@ 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_si_device_type{}; static std::array s_config_rumble_enabled{}; static void Read() @@ -205,7 +207,10 @@ void SetAdapterCallback(std::function func) static void RefreshConfig() { for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) + { + s_config_si_device_type[i] = Config::Get(Config::GetInfoForSIDevice(i)); s_config_rumble_enabled[i] = Config::Get(Config::GetInfoForAdapterRumble(i)); + } } void Init() @@ -542,9 +547,8 @@ void ResetDeviceType(int chan) bool UseAdapter() { - const auto& si_devices = SConfig::GetInstance().m_SIDevice; - - return std::any_of(std::begin(si_devices), std::end(si_devices), [](const auto device_type) { + const auto& si_devices = s_config_si_device_type; + return std::any_of(si_devices.begin(), si_devices.end(), [](const auto device_type) { return device_type == SerialInterface::SIDEVICE_WIIU_ADAPTER; }); } diff --git a/Source/Core/InputCommon/GCAdapter_Android.cpp b/Source/Core/InputCommon/GCAdapter_Android.cpp index 416fa30523..1e58733236 100644 --- a/Source/Core/InputCommon/GCAdapter_Android.cpp +++ b/Source/Core/InputCommon/GCAdapter_Android.cpp @@ -12,7 +12,7 @@ #include "Common/Flag.h" #include "Common/Logging/Log.h" #include "Common/Thread.h" -#include "Core/ConfigManager.h" +#include "Core/Config/MainSettings.h" #include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/HW/SI/SI.h" @@ -61,6 +61,16 @@ static Common::Flag s_adapter_detect_thread_running; static u64 s_last_init = 0; +static std::optional s_config_callback_id = std::nullopt; +static std::array + s_config_si_device_type{}; + +static void RefreshConfig() +{ + for (int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i) + s_config_si_device_type[i] = Config::Get(Config::GetInfoForSIDevice(i)); +} + static void ScanThreadFunc() { Common::SetCurrentThreadName("GC Adapter Scanning Thread"); @@ -200,6 +210,10 @@ void Init() jclass adapter_class = env->FindClass("org/dolphinemu/dolphinemu/utils/Java_GCAdapter"); s_adapter_class = reinterpret_cast(env->NewGlobalRef(adapter_class)); + if (!s_config_callback_id) + s_config_callback_id = Config::AddConfigChangedCallback(RefreshConfig); + RefreshConfig(); + if (UseAdapter()) StartScanThread(); } @@ -236,6 +250,12 @@ void Shutdown() { StopScanThread(); Reset(); + + if (s_config_callback_id) + { + Config::RemoveConfigChangedCallback(*s_config_callback_id); + s_config_callback_id = std::nullopt; + } } void StartScanThread() @@ -376,8 +396,7 @@ void ResetDeviceType(int chan) bool UseAdapter() { - const auto& si_devices = SConfig::GetInstance().m_SIDevice; - + const auto& si_devices = s_config_si_device_type; return std::any_of(std::begin(si_devices), std::end(si_devices), [](const auto device_type) { return device_type == SerialInterface::SIDEVICE_WIIU_ADAPTER; });