From 2354fb446659f5d7702a1a7839fe2e0bcd74551b Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Thu, 6 Jan 2022 05:32:26 +0100 Subject: [PATCH] Config: Port WiimoteEnableSpeaker setting to new config system. --- .../Core/ConfigLoaders/IsSettingSaveable.cpp | 1 + Source/Core/Core/ConfigManager.cpp | 2 -- Source/Core/Core/ConfigManager.h | 1 - Source/Core/Core/HW/WiimoteEmu/Speaker.cpp | 7 ++++++- Source/Core/Core/HW/WiimoteEmu/Speaker.h | 4 ++++ Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 16 ++++++++++++++-- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h | 5 +++++ .../Core/Core/HW/WiimoteReal/WiimoteReal.cpp | 18 ++++++++++++++++-- Source/Core/Core/HW/WiimoteReal/WiimoteReal.h | 9 +++++++-- .../Config/WiimoteControllersWidget.cpp | 5 +++-- 10 files changed, 56 insertions(+), 12 deletions(-) diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 60944f1b59..950b394f15 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -108,6 +108,7 @@ bool IsSettingSaveable(const Config::Location& config_location) &Config::MAIN_WII_SD_CARD.GetLocation(), &Config::MAIN_WII_KEYBOARD.GetLocation(), &Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING.GetLocation(), + &Config::MAIN_WIIMOTE_ENABLE_SPEAKER.GetLocation(), // UI.General diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 4402817a1f..c730af852e 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -111,7 +111,6 @@ void SConfig::SaveCoreSettings(IniFile& ini) { core->Set(fmt::format("SIDevice{}", i), m_SIDevice[i]); } - core->Set("WiimoteEnableSpeaker", m_WiimoteEnableSpeaker); core->Set("WiimoteControllerInterface", connect_wiimotes_for_ciface); core->Set("MMU", bMMU); } @@ -140,7 +139,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("WiimoteEnableSpeaker", &m_WiimoteEnableSpeaker, false); core->Get("WiimoteControllerInterface", &connect_wiimotes_for_ciface, false); core->Get("MMU", &bMMU, bMMU); core->Get("BBDumpPort", &iBBDumpPort, -1); diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index bbb111cc8a..33a649c461 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -50,7 +50,6 @@ struct BootParameters; struct SConfig { // Wii Devices - bool m_WiimoteEnableSpeaker; bool connect_wiimotes_for_ciface; // Settings diff --git a/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp b/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp index 62aad0bc62..e09c991419 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/Speaker.cpp @@ -73,7 +73,7 @@ void stopdamnwav() void SpeakerLogic::SpeakerData(const u8* data, int length, float speaker_pan) { // TODO: should we still process samples for the decoder state? - if (!SConfig::GetInstance().m_WiimoteEnableSpeaker) + if (!m_speaker_enabled) return; if (reg_data.sample_rate == 0 || length == 0) @@ -186,6 +186,11 @@ void SpeakerLogic::DoState(PointerWrap& p) p.Do(reg_data); } +void SpeakerLogic::SetSpeakerEnabled(bool enabled) +{ + m_speaker_enabled = enabled; +} + int SpeakerLogic::BusRead(u8 slave_addr, u8 addr, int count, u8* data_out) { if (I2C_ADDR != slave_addr) diff --git a/Source/Core/Core/HW/WiimoteEmu/Speaker.h b/Source/Core/Core/HW/WiimoteEmu/Speaker.h index d2004df459..9a6a652bb1 100644 --- a/Source/Core/Core/HW/WiimoteEmu/Speaker.h +++ b/Source/Core/Core/HW/WiimoteEmu/Speaker.h @@ -29,6 +29,8 @@ public: void Reset(); void DoState(PointerWrap& p); + void SetSpeakerEnabled(bool enabled); + private: // Pan is -1.0 to +1.0 void SpeakerData(const u8* data, int length, float speaker_pan); @@ -71,6 +73,8 @@ private: ADPCMState adpcm_state{}; ControllerEmu::SettingValue m_speaker_pan_setting; + + bool m_speaker_enabled = false; }; } // namespace WiimoteEmu diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 4ccf02fc17..b266464021 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -17,8 +17,7 @@ #include "Common/MathUtil.h" #include "Common/MsgHandler.h" -#include "Core/Config/SYSCONFSettings.h" -#include "Core/ConfigManager.h" +#include "Core/Config/MainSettings.h" #include "Core/Core.h" #include "Core/HW/Wiimote.h" #include "Core/Movie.h" @@ -297,6 +296,14 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index) m_hotkeys->AddInput(_trans("Upright Hold"), false); Reset(); + + m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); }); + RefreshConfig(); +} + +Wiimote::~Wiimote() +{ + Config::RemoveConfigChangedCallback(m_config_changed_callback_id); } std::string Wiimote::GetName() const @@ -726,6 +733,11 @@ void Wiimote::SetRumble(bool on) m_rumble->controls.front()->control_ref->State(on); } +void Wiimote::RefreshConfig() +{ + m_speaker_logic.SetSpeakerEnabled(Config::Get(Config::MAIN_WIIMOTE_ENABLE_SPEAKER)); +} + void Wiimote::StepDynamics() { EmulateSwing(&m_swing_state, m_swing, 1.f / ::Wiimote::UPDATE_FREQ); diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index 8107111099..31448c6e3c 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -109,6 +109,7 @@ public: static constexpr u16 BUTTON_HOME = 0x8000; explicit Wiimote(unsigned int index); + ~Wiimote(); std::string GetName() const override; void LoadDefaults(const ControllerInterface& ciface) override; @@ -144,6 +145,8 @@ private: // This is the region exposed over bluetooth: static constexpr int EEPROM_FREE_SIZE = 0x1700; + void RefreshConfig(); + void StepDynamics(); void UpdateButtonsStatus(); @@ -297,5 +300,7 @@ private: PositionalState m_shake_state; IMUCursorState m_imu_cursor_state; + + size_t m_config_changed_callback_id; }; } // namespace WiimoteEmu diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp index 328994a0c8..66518258e3 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp @@ -142,7 +142,16 @@ void AddWiimoteToPool(std::unique_ptr wiimote) s_wiimote_pool.emplace_back(WiimotePoolEntry{std::move(wiimote)}); } -Wiimote::Wiimote() = default; +Wiimote::Wiimote() +{ + m_config_changed_callback_id = Config::AddConfigChangedCallback([this] { RefreshConfig(); }); + RefreshConfig(); +} + +Wiimote::~Wiimote() +{ + Config::RemoveConfigChangedCallback(m_config_changed_callback_id); +} void Wiimote::Shutdown() { @@ -263,7 +272,7 @@ void Wiimote::InterruptDataOutput(const u8* data, const u32 size) } } else if (rpt[1] == u8(OutputReportID::SpeakerData) && - (!SConfig::GetInstance().m_WiimoteEnableSpeaker || !m_speaker_enable || m_speaker_mute)) + (!m_speaker_enabled_in_dolphin_config || !m_speaker_enable || m_speaker_mute)) { rpt.resize(3); // Translate undesired speaker data reports into rumble reports. @@ -804,6 +813,11 @@ void Wiimote::ThreadFunc() DisconnectInternal(); } +void Wiimote::RefreshConfig() +{ + m_speaker_enabled_in_dolphin_config = Config::Get(Config::MAIN_WIIMOTE_ENABLE_SPEAKER); +} + int Wiimote::GetIndex() const { return m_index; diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h index 18b927962c..34573a0609 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h @@ -51,7 +51,7 @@ public: Wiimote(Wiimote&&) = delete; Wiimote& operator=(Wiimote&&) = delete; - virtual ~Wiimote() {} + ~Wiimote() override; // This needs to be called in derived destructors! void Shutdown(); @@ -125,6 +125,8 @@ private: void ThreadFunc(); + void RefreshConfig(); + bool m_is_linked = false; // We track the speaker state to convert unnecessary speaker data into rumble reports. @@ -144,6 +146,10 @@ private: Common::SPSCQueue m_read_reports; Common::SPSCQueue m_write_reports; + + bool m_speaker_enabled_in_dolphin_config = false; + + size_t m_config_changed_callback_id; }; class WiimoteScannerBackend @@ -209,5 +215,4 @@ void InitAdapterClass(); void HandleWiimotesInControllerInterfaceSettingChange(); void PopulateDevices(); void ProcessWiimotePool(); - } // namespace WiimoteReal diff --git a/Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp b/Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp index 418dba8371..1a6bfbfef8 100644 --- a/Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp +++ b/Source/Core/DolphinQt/Config/WiimoteControllersWidget.cpp @@ -305,7 +305,7 @@ void WiimoteControllersWidget::LoadSettings() } m_wiimote_real_balance_board->setChecked(WiimoteCommon::GetSource(WIIMOTE_BALANCE_BOARD) == WiimoteSource::Real); - m_wiimote_speaker_data->setChecked(SConfig::GetInstance().m_WiimoteEnableSpeaker); + m_wiimote_speaker_data->setChecked(Config::Get(Config::MAIN_WIIMOTE_ENABLE_SPEAKER)); m_wiimote_ciface->setChecked(SConfig::GetInstance().connect_wiimotes_for_ciface); m_wiimote_continuous_scanning->setChecked(Config::Get(Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING)); @@ -319,7 +319,8 @@ void WiimoteControllersWidget::LoadSettings() void WiimoteControllersWidget::SaveSettings() { - SConfig::GetInstance().m_WiimoteEnableSpeaker = m_wiimote_speaker_data->isChecked(); + Config::SetBaseOrCurrent(Config::MAIN_WIIMOTE_ENABLE_SPEAKER, + m_wiimote_speaker_data->isChecked()); SConfig::GetInstance().connect_wiimotes_for_ciface = m_wiimote_ciface->isChecked(); Config::SetBaseOrCurrent(Config::MAIN_WIIMOTE_CONTINUOUS_SCANNING, m_wiimote_continuous_scanning->isChecked());