From 62ac1f4eb6f47350526d2253697b4f421118dd58 Mon Sep 17 00:00:00 2001 From: Chris Sarbora Date: Tue, 31 Dec 2024 11:30:49 -0600 Subject: [PATCH] fill in x and y only if axes are valid --- ddio/sdlcontroller.cpp | 10 +++++----- ddio/sdljoy.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ddio/sdlcontroller.cpp b/ddio/sdlcontroller.cpp index 23fbfc6c..50027325 100644 --- a/ddio/sdlcontroller.cpp +++ b/ddio/sdlcontroller.cpp @@ -901,11 +901,11 @@ bool sdlgameController::enum_controllers() { m_ControlList[num_devs].buttons = jc.num_btns; m_ControlList[num_devs].btnmask = 0; m_ControlList[num_devs].flags = - CTF_X_AXIS | CTF_Y_AXIS | ((jc.axes_mask & JOYFLAG_ZVALID) ? CTF_Z_AXIS : 0) | - ((jc.axes_mask & JOYFLAG_RVALID) ? CTF_R_AXIS : 0) | ((jc.axes_mask & JOYFLAG_UVALID) ? CTF_U_AXIS : 0) | - ((jc.axes_mask & JOYFLAG_VVALID) ? CTF_V_AXIS : 0) | ((jc.axes_mask & JOYFLAG_POVVALID) ? CTF_POV : 0) | - ((jc.axes_mask & JOYFLAG_POV2VALID) ? CTF_POV2 : 0) | ((jc.axes_mask & JOYFLAG_POV3VALID) ? CTF_POV3 : 0) | - ((jc.axes_mask & JOYFLAG_POV4VALID) ? CTF_POV4 : 0); + ((jc.axes_mask & JOYFLAG_XVALID) ? CTF_X_AXIS : 0) | ((jc.axes_mask & JOYFLAG_YVALID) ? CTF_Y_AXIS : 0) | + ((jc.axes_mask & JOYFLAG_ZVALID) ? CTF_Z_AXIS : 0) | ((jc.axes_mask & JOYFLAG_RVALID) ? CTF_R_AXIS : 0) | + ((jc.axes_mask & JOYFLAG_UVALID) ? CTF_U_AXIS : 0) | ((jc.axes_mask & JOYFLAG_VVALID) ? CTF_V_AXIS : 0) | + ((jc.axes_mask & JOYFLAG_POVVALID) ? CTF_POV : 0) | ((jc.axes_mask & JOYFLAG_POV2VALID) ? CTF_POV2 : 0) | + ((jc.axes_mask & JOYFLAG_POV3VALID) ? CTF_POV3 : 0) | ((jc.axes_mask & JOYFLAG_POV4VALID) ? CTF_POV4 : 0); m_ControlList[num_devs].normalizer[0] = (jc.maxx - jc.minx) / 2.0f; m_ControlList[num_devs].normalizer[1] = (jc.maxy - jc.miny) / 2.0f; m_ControlList[num_devs].normalizer[2] = (jc.maxz - jc.minz) / 2.0f; diff --git a/ddio/sdljoy.cpp b/ddio/sdljoy.cpp index eb59a2c5..054d6143 100644 --- a/ddio/sdljoy.cpp +++ b/ddio/sdljoy.cpp @@ -284,8 +284,12 @@ void joy_GetPos(tJoystick joy, tJoyPos *pos) { uint32_t mask; mask = Joysticks[joy].caps.axes_mask; - pos->x = SDL_JoystickGetAxis(stick, 0); - pos->y = SDL_JoystickGetAxis(stick, 1); + if (mask & JOYFLAG_XVALID) { + pos->x = SDL_JoystickGetAxis(stick, 0); + } + if (mask & JOYFLAG_YVALID) { + pos->y = SDL_JoystickGetAxis(stick, 1); + } if (mask & JOYFLAG_ZVALID) { pos->z = SDL_JoystickGetAxis(stick, 2); }