diff options
author | erorcun <erorcunerorcun@hotmail.com.tr> | 2021-01-25 14:48:41 +0100 |
---|---|---|
committer | erorcun <erorcunerorcun@hotmail.com.tr> | 2021-01-25 14:48:41 +0100 |
commit | cb34060f0070706565601d629b621776f135e375 (patch) | |
tree | 1f337b1687ed689e783b9ba069a3febf2b0e3305 /src/skel/glfw/glfw.cpp | |
parent | modelinfo fixes (diff) | |
download | re3-cb34060f0070706565601d629b621776f135e375.tar re3-cb34060f0070706565601d629b621776f135e375.tar.gz re3-cb34060f0070706565601d629b621776f135e375.tar.bz2 re3-cb34060f0070706565601d629b621776f135e375.tar.lz re3-cb34060f0070706565601d629b621776f135e375.tar.xz re3-cb34060f0070706565601d629b621776f135e375.tar.zst re3-cb34060f0070706565601d629b621776f135e375.zip |
Diffstat (limited to 'src/skel/glfw/glfw.cpp')
-rw-r--r-- | src/skel/glfw/glfw.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index 332f59f0..938cc328 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -2067,22 +2067,30 @@ void CapturePad(RwInt32 padID) const float *axes = glfwGetJoystickAxes(glfwPad, &numAxes); GLFWgamepadstate gamepadState; - if (ControlsManager.m_bFirstCapture == false) - { + if (ControlsManager.m_bFirstCapture == false) { memcpy(&ControlsManager.m_OldState, &ControlsManager.m_NewState, sizeof(ControlsManager.m_NewState)); + } else { + // In case connected gamepad doesn't have L-R trigger axes. + ControlsManager.m_NewState.mappedButtons[15] = ControlsManager.m_NewState.mappedButtons[16] = 0; } ControlsManager.m_NewState.buttons = (uint8*)buttons; ControlsManager.m_NewState.numButtons = numButtons; ControlsManager.m_NewState.id = glfwPad; - ControlsManager.m_NewState.isGamepad = glfwJoystickIsGamepad(glfwPad); + ControlsManager.m_NewState.isGamepad = glfwGetGamepadState(glfwPad, &gamepadState); if (ControlsManager.m_NewState.isGamepad) { - glfwGetGamepadState(glfwPad, &gamepadState); memcpy(&ControlsManager.m_NewState.mappedButtons, gamepadState.buttons, sizeof(gamepadState.buttons)); - ControlsManager.m_NewState.mappedButtons[15] = gamepadState.axes[4] > -0.8f; - ControlsManager.m_NewState.mappedButtons[16] = gamepadState.axes[5] > -0.8f; + float lt = gamepadState.axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER], rt = gamepadState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER]; + + // glfw returns 0.0 for non-existent axises(which is bullocks) so we treat it as deadzone, and keep value of previous frame. + // otherwise if this axis is present, -1 = released, 1 = pressed + if (lt != 0.0f) + ControlsManager.m_NewState.mappedButtons[15] = lt > -0.8f; + + if (rt != 0.0f) + ControlsManager.m_NewState.mappedButtons[16] = rt > -0.8f; } - // TODO I'm not sure how to find/what to do with L2-R2, if joystick isn't registered in SDL database. + // TODO? L2-R2 axes(not buttons-that's fine) on joysticks that don't have SDL gamepad mapping AREN'T handled, and I think it's impossible to do without mapping. if (ControlsManager.m_bFirstCapture == true) { memcpy(&ControlsManager.m_OldState, &ControlsManager.m_NewState, sizeof(ControlsManager.m_NewState)); @@ -2096,12 +2104,13 @@ void CapturePad(RwInt32 padID) RsPadEventHandler(rsPADBUTTONUP, (void *)&bs); // Gamepad axes are guaranteed to return 0.0f if that particular gamepad doesn't have that axis. + // And that's really good for sticks, because gamepads return 0.0 for them when sticks are in released state. if ( glfwPad != -1 ) { - leftStickPos.x = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[0] : numAxes >= 1 ? axes[0] : 0.0f; - leftStickPos.y = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[1] : numAxes >= 2 ? axes[1] : 0.0f; + leftStickPos.x = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[GLFW_GAMEPAD_AXIS_LEFT_X] : numAxes >= 1 ? axes[0] : 0.0f; + leftStickPos.y = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y] : numAxes >= 2 ? axes[1] : 0.0f; - rightStickPos.x = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[2] : numAxes >= 3 ? axes[2] : 0.0f; - rightStickPos.y = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[3] : numAxes >= 4 ? axes[3] : 0.0f; + rightStickPos.x = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[GLFW_GAMEPAD_AXIS_RIGHT_X] : numAxes >= 3 ? axes[2] : 0.0f; + rightStickPos.y = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y] : numAxes >= 4 ? axes[3] : 0.0f; } { |