Permalink
Browse files

Merge pull request #7262 from lioncash/force

ControlGroup: Return state data via GetState() by value where applicable
  • Loading branch information...
leoetlino committed Sep 16, 2018
2 parents 40b7fab + 9983d92 commit e90bd035cb3b7d3bc02058bdeb19b11ddca126b3
@@ -4,6 +4,8 @@
#include "Core/HW/GCPadEmu.h"
#include <array>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
@@ -133,8 +135,6 @@ ControllerEmu::ControlGroup* GCPad::GetGroup(PadGroup group)
GCPadStatus GCPad::GetInput() const
{
const auto lock = GetStateLock();
ControlState x, y, triggers[2];
GCPadStatus pad = {};
if (!(m_always_connected->GetValue() || IsDefaultDeviceConnected()))
@@ -156,20 +156,21 @@ GCPadStatus GCPad::GetInput() const
m_dpad->GetState(&pad.button, dpad_bitmasks);
// sticks
m_main_stick->GetState(&x, &y);
pad.stickX =
static_cast<u8>(GCPadStatus::MAIN_STICK_CENTER_X + (x * GCPadStatus::MAIN_STICK_RADIUS));
pad.stickY =
static_cast<u8>(GCPadStatus::MAIN_STICK_CENTER_Y + (y * GCPadStatus::MAIN_STICK_RADIUS));
m_c_stick->GetState(&x, &y);
pad.substickX =
static_cast<u8>(GCPadStatus::C_STICK_CENTER_X + (x * GCPadStatus::C_STICK_RADIUS));
pad.substickY =
static_cast<u8>(GCPadStatus::C_STICK_CENTER_Y + (y * GCPadStatus::C_STICK_RADIUS));
const ControllerEmu::AnalogStick::StateData main_stick_state = m_main_stick->GetState();
pad.stickX = static_cast<u8>(GCPadStatus::MAIN_STICK_CENTER_X +
(main_stick_state.x * GCPadStatus::MAIN_STICK_RADIUS));
pad.stickY = static_cast<u8>(GCPadStatus::MAIN_STICK_CENTER_Y +
(main_stick_state.y * GCPadStatus::MAIN_STICK_RADIUS));
const ControllerEmu::AnalogStick::StateData c_stick_state = m_c_stick->GetState();
pad.substickX = static_cast<u8>(GCPadStatus::C_STICK_CENTER_X +
(c_stick_state.x * GCPadStatus::C_STICK_RADIUS));
pad.substickY = static_cast<u8>(GCPadStatus::C_STICK_CENTER_Y +
(c_stick_state.y * GCPadStatus::C_STICK_RADIUS));
// triggers
m_triggers->GetState(&pad.button, trigger_bitmasks, triggers);
std::array<ControlState, 2> triggers;
m_triggers->GetState(&pad.button, trigger_bitmasks, triggers.data());
pad.triggerLeft = static_cast<u8>(triggers[0] * 0xFF);
pad.triggerRight = static_cast<u8>(triggers[1] * 0xFF);
@@ -137,29 +137,27 @@ void Classic::GetState(u8* const data)
// left stick
{
ControlState x, y;
m_left_stick->GetState(&x, &y);
const ControllerEmu::AnalogStick::StateData left_stick_state = m_left_stick->GetState();
classic_data.regular_data.lx =
static_cast<u8>(Classic::LEFT_STICK_CENTER_X + (x * Classic::LEFT_STICK_RADIUS));
classic_data.regular_data.ly =
static_cast<u8>(Classic::LEFT_STICK_CENTER_Y + (y * Classic::LEFT_STICK_RADIUS));
classic_data.regular_data.lx = static_cast<u8>(
Classic::LEFT_STICK_CENTER_X + (left_stick_state.x * Classic::LEFT_STICK_RADIUS));
classic_data.regular_data.ly = static_cast<u8>(
Classic::LEFT_STICK_CENTER_Y + (left_stick_state.y * Classic::LEFT_STICK_RADIUS));
}
// right stick
{
ControlState x, y;
m_right_stick->GetState(&x, &y);
const u8 x_ =
static_cast<u8>(Classic::RIGHT_STICK_CENTER_X + (x * Classic::RIGHT_STICK_RADIUS));
const u8 y_ =
static_cast<u8>(Classic::RIGHT_STICK_CENTER_Y + (y * Classic::RIGHT_STICK_RADIUS));
classic_data.rx1 = x_;
classic_data.rx2 = x_ >> 1;
classic_data.rx3 = x_ >> 3;
classic_data.ry = y_;
const ControllerEmu::AnalogStick::StateData right_stick_data = m_right_stick->GetState();
const u8 x = static_cast<u8>(Classic::RIGHT_STICK_CENTER_X +
(right_stick_data.x * Classic::RIGHT_STICK_RADIUS));
const u8 y = static_cast<u8>(Classic::RIGHT_STICK_CENTER_Y +
(right_stick_data.y * Classic::RIGHT_STICK_RADIUS));
classic_data.rx1 = x;
classic_data.rx2 = x >> 1;
classic_data.rx3 = x >> 3;
classic_data.ry = y;
}
// triggers
@@ -74,11 +74,10 @@ void Drums::GetState(u8* const data)
// stick
{
ControlState x, y;
m_stick->GetState(&x, &y);
const ControllerEmu::AnalogStick::StateData stick_state = m_stick->GetState();
drum_data.sx = static_cast<u8>((x * 0x1F) + 0x20);
drum_data.sy = static_cast<u8>((y * 0x1F) + 0x20);
drum_data.sx = static_cast<u8>((stick_state.x * 0x1F) + 0x20);
drum_data.sy = static_cast<u8>((stick_state.y * 0x1F) + 0x20);
}
// TODO: softness maybe
@@ -87,6 +86,7 @@ void Drums::GetState(u8* const data)
// buttons
m_buttons->GetState(&drum_data.bt, drum_button_bitmasks.data());
// pads
m_pads->GetState(&drum_data.bt, drum_pad_bitmasks.data());
@@ -106,19 +106,18 @@ void Guitar::GetState(u8* const data)
// stick
{
ControlState x, y;
m_stick->GetState(&x, &y);
const ControllerEmu::AnalogStick::StateData stick_state = m_stick->GetState();
guitar_data.sx = static_cast<u8>((x * 0x1F) + 0x20);
guitar_data.sy = static_cast<u8>((y * 0x1F) + 0x20);
guitar_data.sx = static_cast<u8>((stick_state.x * 0x1F) + 0x20);
guitar_data.sy = static_cast<u8>((stick_state.y * 0x1F) + 0x20);
}
// slider bar
if (m_slider_bar->controls[0]->control_ref->BoundCount())
{
ControlState slider_bar;
m_slider_bar->GetState(&slider_bar);
guitar_data.sb = s_slider_bar_control_codes.lower_bound(slider_bar)->second;
const ControllerEmu::Slider::StateData slider_data = m_slider_bar->GetState();
guitar_data.sb = s_slider_bar_control_codes.lower_bound(slider_data.value)->second;
}
else
{
@@ -127,14 +126,15 @@ void Guitar::GetState(u8* const data)
}
// whammy bar
ControlState whammy;
m_whammy->GetState(&whammy);
guitar_data.whammy = static_cast<u8>(whammy * 0x1F);
const ControllerEmu::Triggers::StateData whammy_state = m_whammy->GetState();
guitar_data.whammy = static_cast<u8>(whammy_state.data[0] * 0x1F);
// buttons
m_buttons->GetState(&guitar_data.bt, guitar_button_bitmasks.data());
// frets
m_frets->GetState(&guitar_data.bt, guitar_fret_bitmasks.data());
// strum
m_strum->GetState(&guitar_data.bt, guitar_strum_bitmasks.data());
@@ -76,11 +76,9 @@ void Nunchuk::GetState(u8* const data)
wm_nc nc_data = {};
// stick
double jx, jy;
m_stick->GetState(&jx, &jy);
nc_data.jx = u8(STICK_CENTER + jx * STICK_RADIUS);
nc_data.jy = u8(STICK_CENTER + jy * STICK_RADIUS);
const ControllerEmu::AnalogStick::StateData stick_state = m_stick->GetState();
nc_data.jx = u8(STICK_CENTER + stick_state.x * STICK_RADIUS);
nc_data.jy = u8(STICK_CENTER + stick_state.y * STICK_RADIUS);
// Some terribly coded games check whether to move with a check like
//
@@ -90,54 +90,46 @@ void Turntable::GetState(u8* const data)
// stick
{
ControlState x, y;
m_stick->GetState(&x, &y);
const ControllerEmu::AnalogStick::StateData stick_state = m_stick->GetState();
tt_data.sx = static_cast<u8>((x * 0x1F) + 0x20);
tt_data.sy = static_cast<u8>((y * 0x1F) + 0x20);
tt_data.sx = static_cast<u8>((stick_state.x * 0x1F) + 0x20);
tt_data.sy = static_cast<u8>((stick_state.y * 0x1F) + 0x20);
}
// left table
{
ControlState tt;
m_left_table->GetState(&tt);
const ControllerEmu::Slider::StateData lt = m_left_table->GetState();
const s8 tt = static_cast<s8>(lt.value * 0x1F);
const s8 tt_ = static_cast<s8>(tt * 0x1F);
tt_data.ltable1 = tt_;
tt_data.ltable2 = tt_ >> 5;
tt_data.ltable1 = tt;
tt_data.ltable2 = tt >> 5;
}
// right table
{
ControlState tt;
m_right_table->GetState(&tt);
const s8 tt_ = static_cast<s8>(tt * 0x1F);
const ControllerEmu::Slider::StateData rt = m_right_table->GetState();
const s8 tt = static_cast<s8>(rt.value * 0x1F);
tt_data.rtable1 = tt_;
tt_data.rtable2 = tt_ >> 1;
tt_data.rtable3 = tt_ >> 3;
tt_data.rtable4 = tt_ >> 5;
tt_data.rtable1 = tt;
tt_data.rtable2 = tt >> 1;
tt_data.rtable3 = tt >> 3;
tt_data.rtable4 = tt >> 5;
}
// effect dial
{
ControlState dial;
m_effect_dial->GetState(&dial);
const u8 dial_ = static_cast<u8>(dial * 0x0F);
const ControllerEmu::Triggers::StateData state = m_effect_dial->GetState();
const u8 dial = static_cast<u8>(state.data[0] * 0x0F);
tt_data.dial1 = dial_;
tt_data.dial2 = dial_ >> 3;
tt_data.dial1 = dial;
tt_data.dial2 = dial >> 3;
}
// crossfade slider
{
ControlState cfs;
m_crossfade->GetState(&cfs);
const ControllerEmu::Slider::StateData cfs = m_crossfade->GetState();
tt_data.slider = static_cast<u8>((cfs * 0x07) + 0x08);
tt_data.slider = static_cast<u8>((cfs.value * 0x07) + 0x08);
}
// buttons
Oops, something went wrong.

0 comments on commit e90bd03

Please sign in to comment.