Fix input not working properly

This commit is contained in:
Phillip Stephens 2022-03-22 08:01:33 -07:00
parent e3c8fa1d8f
commit 9804543327
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
3 changed files with 31 additions and 26 deletions

View File

@ -10,13 +10,13 @@ enum class EJoyAxis {
}; };
class CControllerAxis { class CControllerAxis {
float x0_absolute = 0.f; float x0_relative = 0.f;
float x4_relative = 0.f; float x4_absolute = 0.f;
public: public:
void SetRelativeValue(float val) { x0_absolute = val; } void SetRelativeValue(float val) { x0_relative = val; }
float GetRelativeValue() const { return x0_absolute; } float GetRelativeValue() const { return x0_relative; }
void SetAbsoluteValue(float val) { x4_relative = val; } void SetAbsoluteValue(float val) { x4_absolute = val; }
float GetAbsoluteValue() const { return x4_relative; } float GetAbsoluteValue() const { return x4_absolute; }
}; };
} // namespace metaforce } // namespace metaforce

View File

@ -103,21 +103,8 @@ void CDolphinController::ProcessAxis(u32 controller, EJoyAxis axis) {
axisValue = x4_status[controller].x5_substickY; axisValue = x4_status[controller].x5_substickY;
} }
axisValue *= 1.f / maxAxisValue; axisValue *= 1.f / maxAxisValue;
float absolute = kAbsoluteMinimum; float absolute = zeus::clamp(kAbsoluteMinimum, axisValue, kAbsoluteMaximum);
if (axisValue < kAbsoluteMinimum) { float relativeValue = zeus::clamp(kRelativeMinimum, absolute - data.GetAbsoluteValue(), kRelativeMaximum);
absolute = kAbsoluteMinimum;
} else if (axisValue > kAbsoluteMaximum) {
absolute = kAbsoluteMaximum;
}
axisValue = absolute - data.GetAbsoluteValue();
float relativeValue = kRelativeMinimum;
if (axisValue < kRelativeMinimum) {
relativeValue = kRelativeMinimum;
} else if (axisValue > kRelativeMaximum) {
relativeValue = kRelativeMaximum;
}
data.SetAbsoluteValue(absolute); data.SetAbsoluteValue(absolute);
data.SetRelativeValue(relativeValue); data.SetRelativeValue(relativeValue);
} }
@ -141,7 +128,7 @@ void CDolphinController::ProcessDigitalButton(u32 controller, CControllerButton&
bool btnPressed = (x4_status[controller].x0_buttons & mapping) != 0; bool btnPressed = (x4_status[controller].x0_buttons & mapping) != 0;
button.SetPressEvent(PADButtonDown(button.GetIsPressed(), btnPressed)); button.SetPressEvent(PADButtonDown(button.GetIsPressed(), btnPressed));
button.SetReleaseEvent(PADButtonUp(button.GetIsPressed(), btnPressed)); button.SetReleaseEvent(PADButtonUp(button.GetIsPressed(), btnPressed));
button.SetPressEvent(btnPressed); button.SetIsPressed(btnPressed);
} }
void CDolphinController::ProcessAnalogButton(float value, CControllerAxis& axis) { void CDolphinController::ProcessAnalogButton(float value, CControllerAxis& axis) {
float absolute = value * (1 / 150.f); float absolute = value * (1 / 150.f);

View File

@ -380,16 +380,34 @@ u32 PADRead(PAD::Status* status) {
Sint16 x = SDL_GameControllerGetAxis(controller.m_controller, SDL_CONTROLLER_AXIS_LEFTX); Sint16 x = SDL_GameControllerGetAxis(controller.m_controller, SDL_CONTROLLER_AXIS_LEFTX);
Sint16 y = SDL_GameControllerGetAxis(controller.m_controller, SDL_CONTROLLER_AXIS_LEFTY); Sint16 y = SDL_GameControllerGetAxis(controller.m_controller, SDL_CONTROLLER_AXIS_LEFTY);
if (std::abs(x) > 8000) {
x /= 256; x /= 256;
} else {
x = 0;
}
if (std::abs(y) > 8000) {
y = (-(y + 1u)) / 256u; y = (-(y + 1u)) / 256u;
} else {
y = 0;
}
status[i].x2_stickX = static_cast<s8>(x); status[i].x2_stickX = static_cast<s8>(x);
status[i].x3_stickY = static_cast<s8>(y); status[i].x3_stickY = static_cast<s8>(y);
x = SDL_GameControllerGetAxis(controller.m_controller, SDL_CONTROLLER_AXIS_RIGHTX); x = SDL_GameControllerGetAxis(controller.m_controller, SDL_CONTROLLER_AXIS_RIGHTX);
y = SDL_GameControllerGetAxis(controller.m_controller, SDL_CONTROLLER_AXIS_RIGHTY); y = SDL_GameControllerGetAxis(controller.m_controller, SDL_CONTROLLER_AXIS_RIGHTY);
if (std::abs(x) > 8000) {
x /= 256; x /= 256;
} else {
x = 0;
}
if (std::abs(y) > 8000) {
y = (-(y + 1u)) / 256u; y = (-(y + 1u)) / 256u;
} else {
y = 0;
}
status[i].x4_substickX = static_cast<s8>(x); status[i].x4_substickX = static_cast<s8>(x);
status[i].x5_substickY = static_cast<s8>(y); status[i].x5_substickY = static_cast<s8>(y);