mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 21:07:52 +00:00
padbutton enum class and struct initiailization
This commit is contained in:
parent
743e1f02a0
commit
c18dc9c707
3 changed files with 32 additions and 36 deletions
|
@ -33,11 +33,13 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
|
|||
adapter_controllers_status[port] = type;
|
||||
|
||||
constexpr std::array<PadButton, 8> b1_buttons{
|
||||
PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y,
|
||||
PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_UP};
|
||||
PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, PadButton::PAD_BUTTON_X,
|
||||
PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT,
|
||||
PadButton::PAD_BUTTON_DOWN, PadButton::PAD_BUTTON_UP};
|
||||
|
||||
constexpr std::array<PadButton, 4> b2_buttons{PAD_BUTTON_START, PAD_TRIGGER_Z, PAD_TRIGGER_R,
|
||||
PAD_TRIGGER_L};
|
||||
constexpr std::array<PadButton, 4> b2_buttons{
|
||||
PadButton::PAD_BUTTON_START, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R,
|
||||
PadButton::PAD_TRIGGER_L};
|
||||
|
||||
if (adapter_controllers_status[port] != ControllerTypes::None) {
|
||||
const u8 b1 = adapter_payload[1 + (9 * port) + 1];
|
||||
|
@ -45,13 +47,13 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
|
|||
|
||||
for (int i = 0; i < b1_buttons.size(); i++) {
|
||||
if (b1 & (1 << i)) {
|
||||
pad.button |= b1_buttons[i];
|
||||
pad.button |= static_cast<u16>(b1_buttons[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < b2_buttons.size(); j++) {
|
||||
if (b2 & (1 << j)) {
|
||||
pad.button |= b2_buttons[j];
|
||||
pad.button |= static_cast<u16>(b2_buttons[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,18 +72,11 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
|
|||
}
|
||||
|
||||
void Adapter::PadToState(const GCPadStatus& pad, GCState& state) {
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A);
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B);
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X);
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_Y, pad.button & PAD_BUTTON_Y);
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_LEFT, pad.button & PAD_BUTTON_LEFT);
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_RIGHT, pad.button & PAD_BUTTON_RIGHT);
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_DOWN, pad.button & PAD_BUTTON_DOWN);
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_UP, pad.button & PAD_BUTTON_UP);
|
||||
state.buttons.insert_or_assign(PAD_BUTTON_START, pad.button & PAD_BUTTON_START);
|
||||
state.buttons.insert_or_assign(PAD_TRIGGER_Z, pad.button & PAD_TRIGGER_Z);
|
||||
state.buttons.insert_or_assign(PAD_TRIGGER_L, pad.button & PAD_TRIGGER_L);
|
||||
state.buttons.insert_or_assign(PAD_TRIGGER_R, pad.button & PAD_TRIGGER_R);
|
||||
for (auto button : PadButtonArray) {
|
||||
u16 button_value = static_cast<u16>(button);
|
||||
state.buttons.insert_or_assign(button_value, pad.button & button_value);
|
||||
}
|
||||
|
||||
state.axes.insert_or_assign(static_cast<u8>(PadAxes::StickX), pad.stick_x);
|
||||
state.axes.insert_or_assign(static_cast<u8>(PadAxes::StickY), pad.stick_y);
|
||||
state.axes.insert_or_assign(static_cast<u8>(PadAxes::SubstickX), pad.substick_x);
|
||||
|
|
|
@ -19,7 +19,7 @@ enum {
|
|||
PAD_ERR_STATUS = 0x8000,
|
||||
};
|
||||
|
||||
enum PadButton {
|
||||
enum class PadButton {
|
||||
PAD_BUTTON_LEFT = 0x0001,
|
||||
PAD_BUTTON_RIGHT = 0x0002,
|
||||
PAD_BUTTON_DOWN = 0x0004,
|
||||
|
@ -34,14 +34,14 @@ enum PadButton {
|
|||
PAD_BUTTON_START = 0x1000,
|
||||
// Below is for compatibility with "AxisButton" type
|
||||
PAD_STICK = 0x2000,
|
||||
|
||||
};
|
||||
|
||||
/// Used to loop through the and assign button in poller
|
||||
static constexpr std::array<PadButton, 12> PadButtonArray{
|
||||
PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_UP,
|
||||
PAD_TRIGGER_Z, PAD_TRIGGER_R, PAD_TRIGGER_L, PAD_BUTTON_A,
|
||||
PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y, PAD_BUTTON_START};
|
||||
PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN,
|
||||
PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R,
|
||||
PadButton::PAD_TRIGGER_L, PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B,
|
||||
PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START};
|
||||
|
||||
enum class PadAxes : u8 {
|
||||
StickX,
|
||||
|
@ -54,13 +54,13 @@ enum class PadAxes : u8 {
|
|||
};
|
||||
|
||||
struct GCPadStatus {
|
||||
u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits
|
||||
u8 stick_x; // 0 <= stick_x <= 255
|
||||
u8 stick_y; // 0 <= stick_y <= 255
|
||||
u8 substick_x; // 0 <= substick_x <= 255
|
||||
u8 substick_y; // 0 <= substick_y <= 255
|
||||
u8 trigger_left; // 0 <= trigger_left <= 255
|
||||
u8 trigger_right; // 0 <= trigger_right <= 255
|
||||
u16 button{}; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits
|
||||
u8 stick_x{}; // 0 <= stick_x <= 255
|
||||
u8 stick_y{}; // 0 <= stick_y <= 255
|
||||
u8 substick_x{}; // 0 <= substick_x <= 255
|
||||
u8 substick_y{}; // 0 <= substick_y <= 255
|
||||
u8 trigger_left{}; // 0 <= trigger_left <= 255
|
||||
u8 trigger_right{}; // 0 <= trigger_right <= 255
|
||||
|
||||
static constexpr u8 MAIN_STICK_CENTER_X = 0x80;
|
||||
static constexpr u8 MAIN_STICK_CENTER_Y = 0x80;
|
||||
|
@ -71,9 +71,9 @@ struct GCPadStatus {
|
|||
static constexpr u8 TRIGGER_CENTER = 20;
|
||||
static constexpr u8 THRESHOLD = 10;
|
||||
|
||||
u8 port;
|
||||
PadAxes axis = PadAxes::Undefined;
|
||||
u8 axis_value = 255;
|
||||
u8 port{};
|
||||
PadAxes axis{PadAxes::Undefined};
|
||||
u8 axis_value{255};
|
||||
};
|
||||
|
||||
struct GCState {
|
||||
|
|
|
@ -96,8 +96,9 @@ Common::ParamPackage GCButtonFactory::GetNextInput() {
|
|||
// or to use a while loop shifting the bits to test and set the value.
|
||||
|
||||
for (auto button : GCAdapter::PadButtonArray) {
|
||||
if (pad.button & button) {
|
||||
params.Set("button", button);
|
||||
u16 button_value = static_cast<u16>(button);
|
||||
if (pad.button & button_value) {
|
||||
params.Set("button", button_value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +106,7 @@ Common::ParamPackage GCButtonFactory::GetNextInput() {
|
|||
// For Axis button implementation
|
||||
if (pad.axis != GCAdapter::PadAxes::Undefined) {
|
||||
params.Set("axis", static_cast<u8>(pad.axis));
|
||||
params.Set("button", GCAdapter::PAD_STICK);
|
||||
params.Set("button", static_cast<u16>(GCAdapter::PadButton::PAD_STICK));
|
||||
if (pad.axis_value > 128) {
|
||||
params.Set("direction", "+");
|
||||
params.Set("threshold", "0.5");
|
||||
|
|
Loading…
Reference in a new issue