Merge pull request #5560 from shuffle2/gh5

Implement slider bar present on GHWT and GH5 controllers
This commit is contained in:
shuffle2 2017-06-06 13:12:02 -07:00 committed by GitHub
commit bd489008ff
5 changed files with 45 additions and 9 deletions

View File

@ -260,7 +260,7 @@ struct wm_guitar_extension
u8 sy : 6;
u8 pad2 : 2; // 1 on gh3, 0 on ghwt
u8 tb : 5; // not used in gh3
u8 sb : 5; // not used in gh3
u8 pad3 : 3; // always 0
u8 whammy : 5;

View File

@ -7,6 +7,8 @@
#include <array>
#include <cassert>
#include <map>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
@ -15,10 +17,22 @@
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/Slider.h"
#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h"
namespace WiimoteEmu
{
static const std::map<const ControlState, const u8> s_slider_bar_control_codes{
// values determined using a PS3 Guitar Hero 5 controller, which maps the touchbar to Zr on
// Windows
{0.0, 0x0F}, // not touching
{-0.4375, 0x04}, // top fret
{-0.097656, 0x0A}, // second fret
{0.203125, 0x12}, // third fret
{0.578125, 0x17}, // fourth fret
{1.0, 0x1F} // bottom fret
};
constexpr std::array<u8, 6> guitar_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x03}};
constexpr std::array<u16, 5> guitar_fret_bitmasks{{
@ -63,6 +77,9 @@ Guitar::Guitar(ExtensionReg& reg) : Attachment(_trans("Guitar"), reg)
groups.emplace_back(m_whammy = new ControllerEmu::Triggers(_trans("Whammy")));
m_whammy->controls.emplace_back(new ControllerEmu::Input(_trans("Bar")));
// slider bar
groups.emplace_back(m_slider_bar = new ControllerEmu::Slider(_trans("Slider Bar")));
// set up register
m_id = guitar_id;
}
@ -83,8 +100,18 @@ void Guitar::GetState(u8* const data)
gdata->sy = static_cast<u8>((y * 0x1F) + 0x20);
}
// TODO: touch bar, probably not
gdata->tb = 0x0F; // not touched
// slider bar
if (m_slider_bar->controls[0]->control_ref->BoundCount())
{
ControlState slider_bar;
m_slider_bar->GetState(&slider_bar);
gdata->sb = s_slider_bar_control_codes.lower_bound(slider_bar)->second;
}
else
{
// if user has not mapped controls for slider bar, tell game it's untouched
gdata->sb = 0x0F;
}
// whammy bar
ControlState whammy;
@ -125,6 +152,8 @@ ControllerEmu::ControlGroup* Guitar::GetGroup(GuitarGroup group)
return m_whammy;
case GuitarGroup::Stick:
return m_stick;
case GuitarGroup::SliderBar:
return m_slider_bar;
default:
assert(false);
return nullptr;

View File

@ -12,6 +12,7 @@ class AnalogStick;
class Buttons;
class ControlGroup;
class Triggers;
class Slider;
}
namespace WiimoteEmu
@ -48,5 +49,6 @@ private:
ControllerEmu::Buttons* m_strum;
ControllerEmu::Triggers* m_whammy;
ControllerEmu::AnalogStick* m_stick;
ControllerEmu::Slider* m_slider_bar;
};
}

View File

@ -91,7 +91,8 @@ enum class GuitarGroup
Frets,
Strum,
Whammy,
Stick
Stick,
SliderBar
};
enum class DrumsGroup

View File

@ -20,11 +20,15 @@ GuitarInputConfigDialog::GuitarInputConfigDialog(wxWindow* const parent, InputCo
Wiimote::GetGuitarGroup(port_num, WiimoteEmu::GuitarGroup::Buttons), this, this);
auto* const group_left_strum = new ControlGroupBox(
Wiimote::GetGuitarGroup(port_num, WiimoteEmu::GuitarGroup::Strum), this, this);
auto* const group_slider_bar = new ControlGroupBox(
Wiimote::GetGuitarGroup(port_num, WiimoteEmu::GuitarGroup::SliderBar), this, this);
auto* const buttons_strum_sizer = new wxBoxSizer(wxVERTICAL);
buttons_strum_sizer->Add(group_box_buttons, 0, wxEXPAND);
buttons_strum_sizer->AddSpacer(space5);
buttons_strum_sizer->Add(group_left_strum, 0, wxEXPAND);
auto* const buttons_strum_slider_bar_sizer = new wxBoxSizer(wxVERTICAL);
buttons_strum_slider_bar_sizer->Add(group_box_buttons, 0, wxEXPAND);
buttons_strum_slider_bar_sizer->AddSpacer(space5);
buttons_strum_slider_bar_sizer->Add(group_left_strum, 0, wxEXPAND);
buttons_strum_slider_bar_sizer->AddSpacer(space5);
buttons_strum_slider_bar_sizer->Add(group_slider_bar, 0, wxEXPAND);
auto* const group_box_frets = new ControlGroupBox(
Wiimote::GetGuitarGroup(port_num, WiimoteEmu::GuitarGroup::Frets), this, this);
@ -41,7 +45,7 @@ GuitarInputConfigDialog::GuitarInputConfigDialog(wxWindow* const parent, InputCo
auto* const controls_sizer = new wxBoxSizer(wxHORIZONTAL);
controls_sizer->AddSpacer(space5);
controls_sizer->Add(buttons_strum_sizer, 0, wxEXPAND);
controls_sizer->Add(buttons_strum_slider_bar_sizer, 0, wxEXPAND);
controls_sizer->AddSpacer(space5);
controls_sizer->Add(frets_whammy_sizer, 0, wxEXPAND);
controls_sizer->AddSpacer(space5);