Start integrating new controller classes

This commit is contained in:
Phillip Stephens 2022-03-20 17:30:47 -07:00
parent 22c9b55300
commit e3c8fa1d8f
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
14 changed files with 379 additions and 165 deletions

View File

@ -927,10 +927,12 @@ void ImGuiConsole::ShowInputViewer() {
if (input.x4_controllerIdx != 0) {
return;
}
#if 0
if (m_whichController != input.m_which) {
m_controllerName = static_cast<std::string>(aurora::get_controller_name(input.m_which));
m_whichController = input.m_which;
}
#endif
// Code -stolen- borrowed from Practice Mod
ImGuiIO& io = ImGui::GetIO();
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |

View File

@ -25,9 +25,9 @@ enum class EAnalogButton {
};
class CControllerButton {
bool x0_pressed;
bool x1_pressEvent;
bool x2_releaseEvent;
bool x0_pressed = false;
bool x1_pressEvent = false;
bool x2_releaseEvent = false;
public:
void SetIsPressed(bool pressed) { x0_pressed = pressed; }

View File

@ -6,126 +6,54 @@ namespace metaforce {
CFinalInput::CFinalInput() = default;
// CFinalInput::CFinalInput(int cIdx, float dt, const boo::DolphinControllerState& data, const CFinalInput& prevInput,
// float leftDiv, float rightDiv)
//: x0_dt(dt)
//, x4_controllerIdx(cIdx)
//, x8_anaLeftX(zeus::clamp(-1.0f, data.m_leftStick[0] / 72.0f / leftDiv, 1.0f))
//, xc_anaLeftY(zeus::clamp(-1.0f, data.m_leftStick[1] / 72.0f / leftDiv, 1.0f))
//, x10_anaRightX(zeus::clamp(-1.0f, data.m_rightStick[0] / 59.0f / rightDiv, 1.0f))
//, x14_anaRightY(zeus::clamp(-1.0f, data.m_rightStick[1] / 59.0f / rightDiv, 1.0f))
//, x18_anaLeftTrigger(data.m_analogTriggers[0] * 0.007f)
//, x1c_anaRightTrigger(data.m_analogTriggers[1] * 0.007f)
//, x20_enableAnaLeftXP(DLARight() && !prevInput.DLARight())
//, x20_enableAnaLeftNegXP(DLALeft() && !prevInput.DLALeft())
//, x21_enableAnaLeftYP(DLAUp() && !prevInput.DLAUp())
//, x21_enableAnaLeftNegYP(DLADown() && !prevInput.DLADown())
//, x22_enableAnaRightXP(DRARight() && !prevInput.DRARight())
//, x22_enableAnaRightNegXP(DRALeft() && !prevInput.DRALeft())
//, x23_enableAnaRightYP(DRAUp() && !prevInput.DRAUp())
//, x23_enableAnaRightNegYP(DRADown() && !prevInput.DRADown())
//, x24_anaLeftTriggerP(DLTrigger() && !prevInput.DLTrigger())
//, x28_anaRightTriggerP(DRTrigger() && !prevInput.DRTrigger())
//, x2c_b24_A(data.m_btns & uint16_t(boo::EDolphinControllerButtons::A))
//, x2c_b25_B(data.m_btns & uint16_t(boo::EDolphinControllerButtons::B))
//, x2c_b26_X(data.m_btns & uint16_t(boo::EDolphinControllerButtons::X))
//, x2c_b27_Y(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Y))
//, x2c_b28_Z(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Z))
//, x2c_b29_L(data.m_btns & uint16_t(boo::EDolphinControllerButtons::L))
//, x2c_b30_R(data.m_btns & uint16_t(boo::EDolphinControllerButtons::R))
//, x2c_b31_DPUp(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Up))
//, x2d_b24_DPRight(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Right))
//, x2d_b25_DPDown(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Down))
//, x2d_b26_DPLeft(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Left))
//, x2d_b27_Start(data.m_btns & uint16_t(boo::EDolphinControllerButtons::Start))
//, x2d_b28_PA(DA() && !prevInput.DA())
//, x2d_b29_PB(DB() && !prevInput.DB())
//, x2d_b30_PX(DX() && !prevInput.DX())
//, x2d_b31_PY(DY() && !prevInput.DY())
//, x2e_b24_PZ(DZ() && !prevInput.DZ())
//, x2e_b25_PL(DL() && !prevInput.DL())
//, x2e_b26_PR(DR() && !prevInput.DR())
//, x2e_b27_PDPUp(DDPUp() && !prevInput.DDPUp())
//, x2e_b28_PDPRight(DDPRight() && !prevInput.DDPRight())
//, x2e_b29_PDPDown(DDPDown() && !prevInput.DDPDown())
//, x2e_b30_PDPLeft(DDPLeft() && !prevInput.DDPLeft())
//, x2e_b31_PStart(DStart() && !prevInput.DStart()) {}
CFinalInput::CFinalInput(int cIdx, float dt, const SAuroraControllerState& data, const CFinalInput& prevInput,
float leftDiv, float rightDiv)
CFinalInput::CFinalInput(int cIdx, float dt, const CControllerGamepadData& data, float leftDiv, float rightDiv)
: x0_dt(dt)
, x4_controllerIdx(cIdx)
, x8_anaLeftX(zeus::clamp(-1.0f, data.m_axes[size_t(aurora::ControllerAxis::LeftX)] / 72.0f / leftDiv, 1.0f))
, xc_anaLeftY(zeus::clamp(-1.0f, data.m_axes[size_t(aurora::ControllerAxis::LeftY)] / 72.0f / leftDiv, 1.0f))
, x10_anaRightX(zeus::clamp(-1.0f, data.m_axes[size_t(aurora::ControllerAxis::RightX)] / 59.0f / rightDiv, 1.0f))
, x14_anaRightY(zeus::clamp(-1.0f, data.m_axes[size_t(aurora::ControllerAxis::RightY)] / 59.0f / rightDiv, 1.0f))
, x18_anaLeftTrigger(data.m_axes[size_t(aurora::ControllerAxis::TriggerLeft)] * 0.007f)
, x1c_anaRightTrigger(data.m_axes[size_t(aurora::ControllerAxis::TriggerRight)] * 0.007f)
, x20_enableAnaLeftXP(DLARight() && !prevInput.DLARight())
, x20_enableAnaLeftNegXP(DLALeft() && !prevInput.DLALeft())
, x21_enableAnaLeftYP(DLAUp() && !prevInput.DLAUp())
, x21_enableAnaLeftNegYP(DLADown() && !prevInput.DLADown())
, x22_enableAnaRightXP(DRARight() && !prevInput.DRARight())
, x22_enableAnaRightNegXP(DRALeft() && !prevInput.DRALeft())
, x23_enableAnaRightYP(DRAUp() && !prevInput.DRAUp())
, x23_enableAnaRightNegYP(DRADown() && !prevInput.DRADown())
, x24_anaLeftTriggerP(DLTrigger() && !prevInput.DLTrigger())
, x28_anaRightTriggerP(DRTrigger() && !prevInput.DRTrigger())
, x2c_b24_A(data.m_btns[size_t(aurora::ControllerButton::A)])
, x2c_b25_B(data.m_btns[size_t(aurora::ControllerButton::B)])
, x2c_b26_X(data.m_btns[size_t(aurora::ControllerButton::X)])
, x2c_b27_Y(data.m_btns[size_t(aurora::ControllerButton::Y)])
, x2c_b28_Z(data.m_btns[size_t(aurora::ControllerButton::Back)])
, x2c_b29_L(data.m_btns[size_t(aurora::ControllerButton::LeftShoulder)])
, x2c_b30_R(data.m_btns[size_t(aurora::ControllerButton::RightShoulder)])
, x2c_b31_DPUp(data.m_btns[size_t(aurora::ControllerButton::DPadUp)])
, x2d_b24_DPRight(data.m_btns[size_t(aurora::ControllerButton::DPadRight)])
, x2d_b25_DPDown(data.m_btns[size_t(aurora::ControllerButton::DPadDown)])
, x2d_b26_DPLeft(data.m_btns[size_t(aurora::ControllerButton::DPadLeft)])
, x2d_b27_Start(data.m_btns[size_t(aurora::ControllerButton::Start)])
, x2d_b28_PA(DA() && !prevInput.DA())
, x2d_b29_PB(DB() && !prevInput.DB())
, x2d_b30_PX(DX() && !prevInput.DX())
, x2d_b31_PY(DY() && !prevInput.DY())
, x2e_b24_PZ(DZ() && !prevInput.DZ())
, x2e_b25_PL(DL() && !prevInput.DL())
, x2e_b26_PR(DR() && !prevInput.DR())
, x2e_b27_PDPUp(DDPUp() && !prevInput.DDPUp())
, x2e_b28_PDPRight(DDPRight() && !prevInput.DDPRight())
, x2e_b29_PDPDown(DDPDown() && !prevInput.DDPDown())
, x2e_b30_PDPLeft(DDPLeft() && !prevInput.DDPLeft())
, x2e_b31_PStart(DStart() && !prevInput.DStart())
, m_which(data.m_which){
if (!data.m_isGamecube) {
if (x2c_b29_L && x18_anaLeftTrigger <= 0.f) {
x18_anaLeftTrigger = 150.f * 0.007f;
}
if (x2c_b30_R && x1c_anaRightTrigger <= 0.f) {
x1c_anaRightTrigger = 150.f * 0.007f;
}
if (x18_anaLeftTrigger >= (150.f * 0.007f) && !x2c_b29_L) {
x2c_b29_L = true;
}
if (x1c_anaRightTrigger >= (150.f * 0.007f) && !x2c_b30_R) {
x2c_b30_R = true;
}
}
, x8_anaLeftX(data.GetAxis(EJoyAxis::LeftX).GetAbsoluteValue())
, xc_anaLeftY(data.GetAxis(EJoyAxis::LeftY).GetAbsoluteValue())
, x10_anaRightX(data.GetAxis(EJoyAxis::RightX).GetAbsoluteValue())
, x14_anaRightY(data.GetAxis(EJoyAxis::RightY).GetAbsoluteValue())
, x18_anaLeftTrigger(data.GetAnalogButton(EAnalogButton::Left).GetAbsoluteValue())
, x1c_anaRightTrigger(data.GetAnalogButton(EAnalogButton::Right).GetAbsoluteValue())
, x24_anaLeftTriggerP(data.GetAnalogButton(EAnalogButton::Left).GetRelativeValue())
, x28_anaRightTriggerP(data.GetAnalogButton(EAnalogButton::Right).GetRelativeValue())
, x2c_b24_A(data.GetButton(EButton::A).GetIsPressed())
, x2c_b25_B(data.GetButton(EButton::B).GetIsPressed())
, x2c_b26_X(data.GetButton(EButton::X).GetIsPressed())
, x2c_b27_Y(data.GetButton(EButton::Y).GetIsPressed())
, x2c_b28_Z(data.GetButton(EButton::Z).GetIsPressed())
, x2c_b29_L(data.GetButton(EButton::L).GetIsPressed())
, x2c_b30_R(data.GetButton(EButton::R).GetIsPressed())
, x2c_b31_DPUp(data.GetButton(EButton::Up).GetIsPressed())
, x2d_b24_DPRight(data.GetButton(EButton::Right).GetIsPressed())
, x2d_b25_DPDown(data.GetButton(EButton::Down).GetIsPressed())
, x2d_b26_DPLeft(data.GetButton(EButton::Left).GetIsPressed())
, x2d_b27_Start(data.GetButton(EButton::Start).GetIsPressed())
, x2d_b28_PA(data.GetButton(EButton::A).GetPressEvent())
, x2d_b29_PB(data.GetButton(EButton::B).GetPressEvent())
, x2d_b30_PX(data.GetButton(EButton::X).GetPressEvent())
, x2d_b31_PY(data.GetButton(EButton::Y).GetPressEvent())
, x2e_b24_PZ(data.GetButton(EButton::Z).GetPressEvent())
, x2e_b25_PL(data.GetButton(EButton::L).GetPressEvent())
, x2e_b26_PR(data.GetButton(EButton::R).GetPressEvent())
, x2e_b27_PDPUp(data.GetButton(EButton::Up).GetPressEvent())
, x2e_b28_PDPRight(data.GetButton(EButton::Right).GetPressEvent())
, x2e_b29_PDPDown(data.GetButton(EButton::Down).GetPressEvent())
, x2e_b30_PDPLeft(data.GetButton(EButton::Left).GetPressEvent())
, x2e_b31_PStart(data.GetButton(EButton::Start).GetPressEvent()) {
InitializeAnalog(leftDiv, rightDiv);
}
#if 0
CFinalInput::CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData& data, const CFinalInput& prevInput)
: x0_dt(dt)
, x4_controllerIdx(cIdx)
, x18_anaLeftTrigger(false)
, x1c_anaRightTrigger(false)
, x20_enableAnaLeftXP(DLARight() && !prevInput.DLARight())
, x20_enableAnaLeftNegXP(DLALeft() && !prevInput.DLALeft())
, x21_enableAnaLeftYP(DLAUp() && !prevInput.DLAUp())
, x21_enableAnaLeftNegYP(DLADown() && !prevInput.DLADown())
, x22_enableAnaRightXP(DRARight() && !prevInput.DRARight())
, x22_enableAnaRightNegXP(DRALeft() && !prevInput.DRALeft())
, x23_enableAnaRightYP(DRAUp() && !prevInput.DRAUp())
, x23_enableAnaRightNegYP(DRADown() && !prevInput.DRADown())
, x24_anaLeftTriggerP(DLTrigger() && !prevInput.DLTrigger())
, x28_anaRightTriggerP(DRTrigger() && !prevInput.DRTrigger())
, x2c_b31_DPUp(data.m_specialKeys[size_t(aurora::SpecialKey::Up)])
@ -172,15 +100,11 @@ CFinalInput& CFinalInput::operator|=(const CFinalInput& other) {
if (std::fabs(other.x1c_anaRightTrigger) > std::fabs(x1c_anaRightTrigger))
x1c_anaRightTrigger = other.x1c_anaRightTrigger;
x20_enableAnaLeftXP |= other.x20_enableAnaLeftXP;
x20_enableAnaLeftNegXP |= other.x20_enableAnaLeftNegXP;
x21_enableAnaLeftYP |= other.x21_enableAnaLeftYP;
x21_enableAnaLeftNegYP |= other.x21_enableAnaLeftNegYP;
x22_enableAnaRightXP |= other.x22_enableAnaRightXP;
x22_enableAnaRightNegXP |= other.x22_enableAnaRightNegXP;
x23_enableAnaRightYP |= other.x23_enableAnaRightYP;
x23_enableAnaRightNegYP |= other.x23_enableAnaRightNegYP;
x24_anaLeftTriggerP |= other.x24_anaLeftTriggerP;
x28_anaRightTriggerP |= other.x28_anaRightTriggerP;
x24_anaLeftTriggerP = other.x24_anaLeftTriggerP;
x28_anaRightTriggerP = other.x28_anaRightTriggerP;
x2c_b24_A |= other.x2c_b24_A;
x2c_b25_B |= other.x2c_b25_B;
x2c_b26_X |= other.x2c_b26_X;
@ -214,6 +138,7 @@ CFinalInput& CFinalInput::operator|=(const CFinalInput& other) {
m_which = other.m_which;
return *this;
}
#endif
CFinalInput CFinalInput::ScaleAnalogueSticks(float leftDiv, float rightDiv) const {
CFinalInput ret = *this;
@ -221,11 +146,78 @@ CFinalInput CFinalInput::ScaleAnalogueSticks(float leftDiv, float rightDiv) cons
ret.xc_anaLeftY = zeus::clamp(-1.f, xc_anaLeftY / leftDiv, 1.f);
ret.x10_anaRightX = zeus::clamp(-1.f, x10_anaRightX / rightDiv, 1.f);
ret.x14_anaRightY = zeus::clamp(-1.f, x14_anaRightY / rightDiv, 1.f);
ret.m_leftMul = 1.f / leftDiv;
ret.m_rightMul = 1.f / rightDiv;
return ret;
}
static std::array<std::array<bool, 4>, 4> sIsAnalogPressed{};
void CFinalInput::InitializeAnalog(float leftDiv, float rightDiv) {
x8_anaLeftX = zeus::clamp(-1.f, x8_anaLeftX / leftDiv, 1.f);
xc_anaLeftY = zeus::clamp(-1.f, xc_anaLeftY / leftDiv, 1.f);
x10_anaRightX = zeus::clamp(-1.f, x10_anaRightX / rightDiv, 1.f);
x14_anaRightY = zeus::clamp(-1.f, x14_anaRightY / rightDiv, 1.f);
if (xc_anaLeftY > 0.7f && !sIsAnalogPressed[x4_controllerIdx][0]) {
sIsAnalogPressed[x4_controllerIdx][0] = true;
x21_enableAnaLeftYP = true;
} else if (xc_anaLeftY > 0.7f && sIsAnalogPressed[x4_controllerIdx][0]) {
x21_enableAnaLeftYP = false;
} else if (xc_anaLeftY < 0.7f && !sIsAnalogPressed[x4_controllerIdx][0]) {
x21_enableAnaLeftYP = true;
sIsAnalogPressed[x4_controllerIdx][0] = true;
} else if (xc_anaLeftY < 0.7f && sIsAnalogPressed[x4_controllerIdx][0]) {
x21_enableAnaLeftYP = false;
} else if (std::fabs(xc_anaLeftY) < 0.7f) {
x21_enableAnaLeftYP = false;
sIsAnalogPressed[x4_controllerIdx][0] = false;
}
if (x8_anaLeftX > 0.7f && !sIsAnalogPressed[x4_controllerIdx][1]) {
sIsAnalogPressed[x4_controllerIdx][1] = true;
x20_enableAnaLeftXP = true;
} else if (x8_anaLeftX > 0.7f && sIsAnalogPressed[x4_controllerIdx][1]) {
x20_enableAnaLeftXP = false;
} else if (x8_anaLeftX < 0.7f && !sIsAnalogPressed[x4_controllerIdx][1]) {
x20_enableAnaLeftXP = true;
sIsAnalogPressed[x4_controllerIdx][1] = true;
} else if (x8_anaLeftX < 0.7f && sIsAnalogPressed[x4_controllerIdx][1]) {
x20_enableAnaLeftXP = false;
} else if (std::fabs(x8_anaLeftX) < 0.7f) {
x20_enableAnaLeftXP = false;
sIsAnalogPressed[x4_controllerIdx][1] = false;
}
if (x14_anaRightY > 0.7f && !sIsAnalogPressed[x4_controllerIdx][2]) {
sIsAnalogPressed[x4_controllerIdx][2] = true;
x23_enableAnaRightYP = true;
} else if (x14_anaRightY > 0.7f && sIsAnalogPressed[x4_controllerIdx][2]) {
x23_enableAnaRightYP = false;
} else if (x14_anaRightY < 0.7f && !sIsAnalogPressed[x4_controllerIdx][2]) {
x23_enableAnaRightYP = true;
sIsAnalogPressed[x4_controllerIdx][2] = true;
} else if (x14_anaRightY < 0.7f && sIsAnalogPressed[x4_controllerIdx][2]) {
x23_enableAnaRightYP = false;
} else if (std::fabs(x14_anaRightY) < 0.7f) {
x23_enableAnaRightYP = false;
sIsAnalogPressed[x4_controllerIdx][2] = false;
}
if (x10_anaRightX > 0.7f && !sIsAnalogPressed[x4_controllerIdx][3]) {
sIsAnalogPressed[x4_controllerIdx][3] = true;
x22_enableAnaRightXP = true;
} else if (x10_anaRightX > 0.7f && sIsAnalogPressed[x4_controllerIdx][3]) {
x22_enableAnaRightXP = false;
} else if (x10_anaRightX < 0.7f && !sIsAnalogPressed[x4_controllerIdx][3]) {
x22_enableAnaRightXP = true;
sIsAnalogPressed[x4_controllerIdx][3] = true;
} else if (x10_anaRightX < 0.7f && sIsAnalogPressed[x4_controllerIdx][3]) {
x22_enableAnaRightXP = false;
} else if (std::fabs(x10_anaRightX) < 0.7f) {
x22_enableAnaRightXP = false;
sIsAnalogPressed[x4_controllerIdx][3] = false;
}
}
/* The following code is derived from pad.c in libogc
*
* Copyright (C) 2004 - 2009

View File

@ -3,6 +3,7 @@
#include <array>
#include "Runtime/Input/CKeyboardMouseController.hpp"
#include "Runtime/Input/CControllerGamepadData.hpp"
#include "Runtime/RetroTypes.hpp"
namespace metaforce {
@ -30,22 +31,13 @@ struct CFinalInput {
float x18_anaLeftTrigger = 0.0f;
float x1c_anaRightTrigger = 0.0f;
/* These were originally per-axis bools, requiring two logical tests
* at read-time; now they're logical cardinal-direction states
* (negative values indicated) */
bool x20_enableAnaLeftXP : 1 = false;
bool x20_enableAnaLeftNegXP : 1 = false;
bool x21_enableAnaLeftYP : 1 = false;
bool x21_enableAnaLeftNegYP : 1 = false;
bool x22_enableAnaRightXP : 1 = false;
bool x22_enableAnaRightNegXP : 1 = false;
bool x23_enableAnaRightYP : 1 = false;
bool x23_enableAnaRightNegYP : 1 = false;
bool x20_enableAnaLeftXP = false;
bool x21_enableAnaLeftYP = false;
bool x22_enableAnaRightXP = false;
bool x23_enableAnaRightYP = false;
/* These were originally redundantly-compared floats;
* now the logical state is stored directly */
bool x24_anaLeftTriggerP : 1 = false;
bool x28_anaRightTriggerP : 1 = false;
float x24_anaLeftTriggerP;
float x28_anaRightTriggerP;
bool x2c_b24_A : 1 = false;
bool x2c_b25_B : 1 = false;
@ -79,19 +71,12 @@ struct CFinalInput {
std::array<bool, size_t(aurora::SpecialKey::MAX)> m_PSpecialKeys{};
std::array<bool, 6> m_PMouseButtons{};
float m_leftMul = 1.f;
float m_rightMul = 1.f;
u32 m_which = -1;
CFinalInput();
// CFinalInput(int cIdx, float dt, const boo::DolphinControllerState& data, const CFinalInput& prevInput, float
// leftDiv,
// float rightDiv);
CFinalInput(int cIdx, float dt, const SAuroraControllerState& data, const CFinalInput& prevInput, float leftDiv,
float rightDiv);
CFinalInput(int cIdx, float dt, const CControllerGamepadData& data, float leftDiv, float rightDiv);
CFinalInput(int cIdx, float dt, const CKeyboardMouseControllerData& data, const CFinalInput& prevInput);
CFinalInput& operator|=(const CFinalInput& other);
//CFinalInput& operator|=(const CFinalInput& other);
bool operator==(const CFinalInput& other) const { return memcmp(this, &other, sizeof(CFinalInput)) == 0; }
bool operator!=(const CFinalInput& other) const { return !operator==(other); }
@ -111,16 +96,16 @@ struct CFinalInput {
bool PDPLeft() const { return x2e_b30_PDPLeft; }
bool PDPDown() const { return x2e_b29_PDPDown; }
bool PDPUp() const { return x2e_b27_PDPUp; }
bool PRTrigger() const { return x28_anaRightTriggerP; }
bool PLTrigger() const { return x24_anaLeftTriggerP; }
bool PRARight() const { return x22_enableAnaRightXP; }
bool PRALeft() const { return x22_enableAnaRightNegXP; }
bool PRADown() const { return x23_enableAnaRightNegYP; }
bool PRAUp() const { return x23_enableAnaRightYP; }
bool PLARight() const { return x20_enableAnaLeftXP; }
bool PLALeft() const { return x20_enableAnaLeftNegXP; }
bool PLADown() const { return x21_enableAnaLeftNegYP; }
bool PLAUp() const { return x21_enableAnaLeftYP; }
bool PRTrigger() const { return x28_anaRightTriggerP > 0.5f; }
bool PLTrigger() const { return x24_anaLeftTriggerP > 0.5f; }
bool PRARight() const { return x10_anaRightX > 0.7f && x22_enableAnaRightXP; }
bool PRALeft() const { return x10_anaRightX < -0.7f && x22_enableAnaRightXP; }
bool PRADown() const { return x14_anaRightY < -0.7f && x23_enableAnaRightYP; }
bool PRAUp() const { return x14_anaRightY > 0.7f && x23_enableAnaRightYP; }
bool PLARight() const { return x8_anaLeftX > 0.7f && x20_enableAnaLeftXP; }
bool PLALeft() const { return x8_anaLeftX < -0.7f && x20_enableAnaLeftXP; }
bool PLADown() const { return xc_anaLeftY < -0.7f && x21_enableAnaLeftYP; }
bool PLAUp() const { return xc_anaLeftY > 0.7f && x21_enableAnaLeftYP; }
bool DStart() const { return x2d_b27_Start; }
bool DR() const { return x2c_b30_R; }
bool DL() const { return x2c_b29_L; }
@ -174,6 +159,7 @@ struct CFinalInput {
float ARightTrigger() const { return x1c_anaRightTrigger; }
CFinalInput ScaleAnalogueSticks(float leftDiv, float rightDiv) const;
void InitializeAnalog(float leftDiv, float rightDiv);
bool PKey(char k) const { return m_kbm && m_PCharKeys[size_t(k)]; }
bool PSpecialKey(aurora::SpecialKey k) const { return m_kbm && m_PSpecialKeys[size_t(k)]; }

View File

@ -117,12 +117,14 @@ void CInputGenerator::SetMotorState(EIOPort port, EMotorState state) {
}
const CFinalInput& CInputGenerator::getFinalInput(unsigned int idx, float dt) {
#if 0
auto input = CFinalInput(idx, dt, m_data, m_lastUpdate);
// Merge controller input with kb/m input
auto state = m_state[idx];
state.clamp();
input |= CFinalInput(idx, dt, state, m_lastUpdate, m_leftDiv, m_rightDiv);
m_lastUpdate = input;
#endif
return m_lastUpdate;
}

View File

@ -7,6 +7,7 @@ set(INPUT_SOURCES
CDolphinController.hpp CDolphinController.cpp
CKeyboardMouseController.hpp
ControlMapper.hpp ControlMapper.cpp
NewCInputGenerator.hpp NewCInputGenerator.cpp
CInputGenerator.hpp CInputGenerator.cpp
CFinalInput.hpp CFinalInput.cpp
CRumbleManager.hpp CRumbleManager.cpp

View File

@ -339,6 +339,7 @@ float ControlMapper::GetAnalogInput(ECommands cmd, const CFinalInput& input) {
ret = (input.*fn)();
}
}
#if 0 // TODO: reimplement this
if (const auto& kbm = input.GetKBM()) {
switch (cmd) {
case ECommands::Forward:
@ -395,6 +396,7 @@ float ControlMapper::GetAnalogInput(ECommands cmd, const CFinalInput& input) {
}
}
}
#endif
return ret;
}

View File

@ -1,4 +1,3 @@
#include "Runtime/Input/IController.hpp"
#include "Runtime/Input/CDolphinController.hpp"
namespace metaforce {

View File

@ -14,6 +14,7 @@ protected:
static constexpr float kRelativeMinimum = -1.f;
static constexpr float kRelativeMaximum = 1.f;
public:
virtual ~IController() = default;
virtual void Poll() = 0;
virtual u32 GetDeviceCount() const = 0;
virtual CControllerGamepadData& GetGamepadData(u32 controller) = 0;

View File

@ -0,0 +1,40 @@
#include "Runtime/Input/NewCInputGenerator.hpp"
#include "Runtime/Input/IController.hpp"
#include "Runtime/Input/CFinalInput.hpp"
#include "Runtime/CArchitectureQueue.hpp"
namespace metaforce::WIP {
CInputGenerator::CInputGenerator(/*COsContext& context, */ float leftDiv, float rightDiv)
/*: x0_context(context) */ {
x4_controller.reset(IController::Create());
xc_leftDiv = leftDiv;
x10_rightDiv = rightDiv;
}
void CInputGenerator::Update(float dt, CArchitectureQueue& queue) {
#if 0
if (!x0_context.Update()) {
return;
}
#endif
bool firstController = false;
if (x4_controller) {
x4_controller->Poll();
for (u32 i = 0; i < x4_controller->GetDeviceCount(); ++i) {
auto cont = x4_controller->GetGamepadData(i);
if (!cont.DeviceIsPresent()) {
continue;
}
if (i == 0) {
firstController = true;
}
queue.Push(MakeMsg::CreateUserInput(EArchMsgTarget::Game, CFinalInput(i, dt, cont, xc_leftDiv, x10_rightDiv)));
// TODO: Finish
}
}
}
} // namespace metaforce::WIP

View File

@ -0,0 +1,32 @@
#pragma once
#include <memory>
#include "Runtime/Input/IController.hpp"
namespace metaforce {
struct COsContext {
bool GetOsKeyState(int key) { return false; }
};
class CArchitectureQueue;
namespace WIP {
class CInputGenerator {
//COsContext& x0_context;
std::unique_ptr<IController> x4_controller;
bool x8_ = false;
bool x9_ = false;
bool xa_ = false;
bool xb_ = false;
float xc_leftDiv;
float x10_rightDiv;
public:
CInputGenerator(/*COsContext& context, */float leftDiv, float rightDiv);
void Update(float dt, CArchitectureQueue& queue);
};
} // namespace WIP
} // namespace metaforce

View File

@ -94,6 +94,7 @@ CGameArchitectureSupport::CGameArchitectureSupport(CMain& parent, boo::IAudioVoi
amuse::IBackendVoiceAllocator& backend)
: m_parent(parent)
, x0_audioSys(voiceEngine, backend, 0, 0, 0, 0, 0)
, x30_newInputGenerator(/*osCtx, */ g_tweakPlayer->GetLeftLogicalThreshold(), g_tweakPlayer->GetRightLogicalThreshold())
, x30_inputGenerator(g_tweakPlayer->GetLeftLogicalThreshold(), g_tweakPlayer->GetRightLogicalThreshold())
, x44_guiSys(*g_ResFactory, *g_SimplePool, CGuiSys::EUsageMode::Zero) {
auto* m = static_cast<CMain*>(g_Main);
@ -135,7 +136,8 @@ void CGameArchitectureSupport::UpdateTicks(float dt) {
void CGameArchitectureSupport::Update(float dt) {
g_GameState->GetWorldTransitionManager()->TouchModels();
x30_inputGenerator.Update(dt, x4_archQueue);
x30_newInputGenerator.Update(dt, x4_archQueue);
// x30_inputGenerator.Update(dt, x4_archQueue);
x4_archQueue.Push(MakeMsg::CreateFrameEnd(EArchMsgTarget::Game, x78_gameFrameCount));
x58_ioWinManager.PumpMessages(x4_archQueue);
}
@ -635,8 +637,7 @@ void CMain::Init(const FileStoreManager& storeMgr, CVarManager* cvarMgr, boo::IA
while (args.end() - it >= 4) {
const char* layerStr = (*(it + 3)).c_str();
if (!(layerStr[0] == '0' && layerStr[1] == 'x') &&
(layerStr[0] == '0' || layerStr[0] == '1')) {
if (!(layerStr[0] == '0' && layerStr[1] == 'x') && (layerStr[0] == '0' || layerStr[0] == '1')) {
for (const auto* cur = layerStr; *cur != '\0'; ++cur)
if (*cur == '1')
m_warpLayerBits |= u64(1) << (cur - layerStr);
@ -691,9 +692,7 @@ bool CMain::Proc(float dt) {
return x160_24_finished;
}
void CMain::Draw() {
x164_archSupport->Draw();
}
void CMain::Draw() { x164_archSupport->Draw(); }
void CMain::ShutdownSubsystems() {
CDecalManager::Shutdown();

View File

@ -19,6 +19,7 @@
#include "Runtime/Particle/CGenDescription.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/Audio/CAudioSys.hpp"
#include "Runtime/Input/NewCInputGenerator.hpp"
#include "Runtime/Input/CInputGenerator.hpp"
#include "Runtime/GuiSys/CGuiSys.hpp"
#include "Runtime/CIOWinManager.hpp"
@ -115,6 +116,7 @@ class CGameArchitectureSupport {
CMain& m_parent;
CArchitectureQueue x4_archQueue;
CAudioSys x0_audioSys;
WIP::CInputGenerator x30_newInputGenerator;
CInputGenerator x30_inputGenerator;
CGuiSys x44_guiSys;
CIOWinManager x58_ioWinManager;

View File

@ -6,6 +6,7 @@
#include <absl/container/btree_map.h>
#include <absl/container/flat_hash_map.h>
#include <absl/strings/str_split.h>
#include <cmath>
namespace aurora::input {
static logvisor::Module Log("aurora::input");
@ -343,7 +344,7 @@ MouseButton translate_mouse_button_state(Uint8 state) noexcept {
} // namespace aurora::input
void PADSetSpec(u32 spec) {}
void PADSetSpec(s32 spec) {}
void PADInit() {}
static const std::array<std::pair<SDL_GameControllerButton, PAD::BUTTON>, 12> mMapping{{
@ -401,7 +402,6 @@ u32 PADRead(PAD::Status* status) {
status[i].x6_triggerL = static_cast<s8>(x);
status[i].x7_triggerR = static_cast<s8>(y);
if (controller.m_hasRumble) {
rumbleSupport |= PAD::CHAN0_BIT >> i;
}
@ -431,7 +431,6 @@ void PADControlAllMotors(const u32* commands) {
}
}
u32 SIProbe(s32 chan) {
const auto controller = aurora::input::get_controller_for_player(chan);
if (controller == aurora::input::GameController{}) {
@ -447,3 +446,160 @@ u32 SIProbe(s32 chan) {
return SI::GC_CONTROLLER;
}
struct PADCLampRegion {
u8 minTrigger;
u8 maxTrigger;
s8 minStick;
s8 maxStick;
s8 xyStick;
s8 minSubstick;
s8 maxSubstick;
s8 xySubstick;
s8 radStick;
s8 radSubstick;
};
static constexpr PADCLampRegion ClampRegion{
// Triggers
30,
180,
// Left stick
15,
72,
40,
// Right stick
15,
59,
31,
// Stick radii
56,
44,
};
void ClampTrigger(u8* trigger, u8 min, u8 max) {
if (*trigger <= min) {
*trigger = 0;
} else {
if (*trigger > max) {
*trigger = max;
}
*trigger -= min;
}
}
void ClampCircle(s8* px, s8* py, s8 radius, s8 min) {
int x = *px;
int y = *py;
if (-min < x && x < min) {
x = 0;
} else if (0 < x) {
x -= min;
} else {
x += min;
}
if (-min < y && y < min) {
y = 0;
} else if (0 < y) {
y -= min;
} else {
y += min;
}
int squared = x * x + y * y;
if (radius * radius < squared) {
s32 length = static_cast<s32>(std::sqrt(squared));
x = (x * radius) / length;
y = (y * radius) / length;
}
*px = static_cast<s8>(x);
*py = static_cast<s8>(y);
}
void ClampStick(s8* px, s8* py, s8 max, s8 xy, s8 min) {
s8 x = *px;
s8 y = *py;
s8 signX = 0;
if (0 <= x) {
signX = 1;
} else {
signX = -1;
x = -x;
}
s8 signY = 0;
if (0 <= y) {
signY = 1;
} else {
signY = -1;
y = -y;
}
if (x <= min) {
x = 0;
} else {
x -= min;
}
if (y <= min) {
y = 0;
} else {
y -= min;
}
if (x == 0 && y == 0) {
*px = *py = 0;
return;
}
if (xy * y <= xy * x) {
s8 d = xy * x + (max - xy) * y;
if (xy * max < d) {
x = (xy * max * x / d);
y = (xy * max * y / d);
}
} else {
s8 d = xy * y + (max - xy) * x;
if (xy * max < d) {
x = (xy * max * x / d);
y = (xy * max * y / d);
}
}
*px = (signX * x);
*py = (signY * y);
}
void PADClamp(PAD::Status* status) {
for (u32 i = 0; i < 4; ++i) {
if (status[i].xa_err != PAD::ERR_NONE) {
continue;
}
ClampStick(&status[i].x2_stickX, &status[i].x3_stickY, ClampRegion.maxStick, ClampRegion.xyStick,
ClampRegion.minStick);
ClampStick(&status[i].x4_substickX, &status[i].x5_substickY, ClampRegion.maxSubstick, ClampRegion.xySubstick,
ClampRegion.minSubstick);
ClampTrigger(&status[i].x6_triggerL, ClampRegion.minTrigger, ClampRegion.maxTrigger);
ClampTrigger(&status[i].x7_triggerR, ClampRegion.minTrigger, ClampRegion.maxTrigger);
}
}
void PADClampCircle(PAD::Status* status) {
for (u32 i = 0; i < 4; ++i) {
if (status[i].xa_err != PAD::ERR_NONE) {
continue;
}
ClampCircle(&status[i].x2_stickX, &status[i].x3_stickY, ClampRegion.radStick, ClampRegion.minStick);
ClampCircle(&status[i].x4_substickX, &status[i].x5_substickY, ClampRegion.radSubstick, ClampRegion.minSubstick);
ClampTrigger(&status[i].x6_triggerL, ClampRegion.minTrigger, ClampRegion.maxTrigger);
ClampTrigger(&status[i].x7_triggerR, ClampRegion.minTrigger, ClampRegion.maxTrigger);
}
}