From 7c52b8f838945d577f23cdaffba83796fe3194f0 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Tue, 21 Mar 2017 13:18:17 -0700 Subject: [PATCH] WiimoteEmu: refer to settings by name, not index Fixes https://bugs.dolphin-emu.org/issues/10159 "Emulated Wii remote options not working correctly," which was introduced by PR #4856: "Move 'Background Input' out of individual controller configurations." --- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp | 36 ++++++++++--------- Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h | 8 +++++ 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 26f1ca5cfe..a1d4cbe195 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -231,7 +231,7 @@ void Wiimote::Reset() // 0x33 - 0x43: level 2 // 0x33 - 0x54: level 3 // 0x55 - 0xff: level 4 - m_status.battery = (u8)(m_options->numeric_settings[1]->GetValue() * 100); + m_status.battery = (u8)(m_battery_setting->GetValue() * 100); memset(m_shake_step, 0, sizeof(m_shake_step)); @@ -282,11 +282,11 @@ Wiimote::Wiimote(const unsigned int index) m_extension->attachments.emplace_back(new WiimoteEmu::Turntable(m_reg_ext)); m_extension->boolean_settings.emplace_back( - std::make_unique(_trans("Motion Plus"), false)); + m_motion_plus_setting = new ControllerEmu::BooleanSetting(_trans("Motion Plus"), false)); // rumble groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble"))); - m_rumble->controls.emplace_back(new ControllerEmu::Output(_trans("Motor"))); + m_rumble->controls.emplace_back(m_motor = new ControllerEmu::Output(_trans("Motor"))); // dpad groups.emplace_back(m_dpad = new ControllerEmu::Buttons("D-Pad")); @@ -295,16 +295,18 @@ Wiimote::Wiimote(const unsigned int index) // options groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options"))); - m_options->boolean_settings.emplace_back(std::make_unique( - "Sideways Wiimote", _trans("Sideways Wii Remote"), false)); - m_options->boolean_settings.emplace_back(std::make_unique( - "Upright Wiimote", _trans("Upright Wii Remote"), false)); + m_options->boolean_settings.emplace_back( + m_sideways_setting = new ControllerEmu::BooleanSetting("Sideways Wiimote", + _trans("Sideways Wii Remote"), false)); + m_options->boolean_settings.emplace_back( + m_upright_setting = new ControllerEmu::BooleanSetting("Upright Wiimote", + _trans("Upright Wii Remote"), false)); m_options->boolean_settings.emplace_back(std::make_unique( _trans("Iterative Input"), false, ControllerEmu::SettingType::VIRTUAL)); m_options->numeric_settings.emplace_back( std::make_unique(_trans("Speaker Pan"), 0, -127, 127)); m_options->numeric_settings.emplace_back( - std::make_unique(_trans("Battery"), 95.0 / 100, 0, 255)); + m_battery_setting = new ControllerEmu::NumericSetting(_trans("Battery"), 95.0 / 100, 0, 255)); // hotkeys groups.emplace_back(m_hotkeys = new ControllerEmu::ModifySettingsButton(_trans("Hotkeys"))); @@ -386,9 +388,9 @@ ControllerEmu::ControlGroup* Wiimote::GetTurntableGroup(TurntableGroup group) bool Wiimote::Step() { // TODO: change this a bit - m_motion_plus_present = m_extension->boolean_settings[0]->GetValue(); + m_motion_plus_present = m_motion_plus_setting->GetValue(); - m_rumble->controls[0]->control_ref->State(m_rumble_on); + m_motor->control_ref->State(m_rumble_on); // when a movie is active, this button status update is disabled (moved), because movies only // record data reports. @@ -441,8 +443,8 @@ void Wiimote::UpdateButtonsStatus() m_status.buttons.hex = 0; const bool sideways_modifier_toggle = m_hotkeys->getSettingsModifier()[0]; const bool sideways_modifier_switch = m_hotkeys->getSettingsModifier()[2]; - const bool is_sideways = m_options->boolean_settings[1]->GetValue() ^ sideways_modifier_toggle ^ - sideways_modifier_switch; + const bool is_sideways = + m_sideways_setting->GetValue() ^ sideways_modifier_toggle ^ sideways_modifier_switch; m_buttons->GetState(&m_status.buttons.hex, button_bitmasks); m_dpad->GetState(&m_status.buttons.hex, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks); } @@ -465,10 +467,10 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf) const bool upright_modifier_toggle = m_hotkeys->getSettingsModifier()[1]; const bool sideways_modifier_switch = m_hotkeys->getSettingsModifier()[2]; const bool upright_modifier_switch = m_hotkeys->getSettingsModifier()[3]; - const bool is_sideways = m_options->boolean_settings[1]->GetValue() ^ sideways_modifier_toggle ^ - sideways_modifier_switch; - const bool is_upright = m_options->boolean_settings[2]->GetValue() ^ upright_modifier_toggle ^ - upright_modifier_switch; + const bool is_sideways = + m_sideways_setting->GetValue() ^ sideways_modifier_toggle ^ sideways_modifier_switch; + const bool is_upright = + m_upright_setting->GetValue() ^ upright_modifier_toggle ^ upright_modifier_switch; EmulateTilt(&m_accel, m_tilt, is_sideways, is_upright); EmulateSwing(&m_accel, m_swing, is_sideways, is_upright); @@ -721,7 +723,7 @@ void Wiimote::Update() Movie::SetPolledDevice(); - m_status.battery = (u8)(m_options->numeric_settings[1]->GetValue() * 100); + m_status.battery = (u8)(m_battery_setting->GetValue() * 100); const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - WM_REPORT_CORE]; s8 rptf_size = rptf.size; diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index 31204766c5..fd624c31b0 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -22,12 +22,15 @@ class PointerWrap; namespace ControllerEmu { +class BooleanSetting; class Buttons; class ControlGroup; class Cursor; class Extension; class Force; class ModifySettingsButton; +class NumericSetting; +class Output; class Tilt; } @@ -245,8 +248,13 @@ private: ControllerEmu::Tilt* m_tilt; ControllerEmu::Force* m_swing; ControllerEmu::ControlGroup* m_rumble; + ControllerEmu::Output* m_motor; ControllerEmu::Extension* m_extension; + ControllerEmu::BooleanSetting* m_motion_plus_setting; ControllerEmu::ControlGroup* m_options; + ControllerEmu::BooleanSetting* m_sideways_setting; + ControllerEmu::BooleanSetting* m_upright_setting; + ControllerEmu::NumericSetting* m_battery_setting; ControllerEmu::ModifySettingsButton* m_hotkeys; // Wiimote accel data