Config: Port WiimoteEnableSpeaker setting to new config system.

This commit is contained in:
Admiral H. Curtiss 2022-01-06 05:32:26 +01:00
parent 8c554d2e64
commit 2354fb4466
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
10 changed files with 56 additions and 12 deletions

View File

@ -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

View File

@ -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);

View File

@ -50,7 +50,6 @@ struct BootParameters;
struct SConfig
{
// Wii Devices
bool m_WiimoteEnableSpeaker;
bool connect_wiimotes_for_ciface;
// Settings

View File

@ -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)

View File

@ -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<double> m_speaker_pan_setting;
bool m_speaker_enabled = false;
};
} // namespace WiimoteEmu

View File

@ -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);

View File

@ -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

View File

@ -142,7 +142,16 @@ void AddWiimoteToPool(std::unique_ptr<Wiimote> 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;

View File

@ -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<Report> m_read_reports;
Common::SPSCQueue<Report> 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

View File

@ -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());