From e1d68ef097429680226ec269fabf2832676d35f7 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 5 Aug 2018 18:01:50 -0700 Subject: [PATCH] Fix Y values wrapping at -32768 --- app/streaming/input.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/streaming/input.cpp b/app/streaming/input.cpp index 5ea555f4..f82a3238 100644 --- a/app/streaming/input.cpp +++ b/app/streaming/input.cpp @@ -2,6 +2,8 @@ #include #include "streaming/session.hpp" +#include + #define VK_0 0x30 #define VK_A 0x41 @@ -441,13 +443,18 @@ void SdlInputHandler::handleControllerAxisEvent(SDL_ControllerAxisEvent* event) state->lsX = event->value; break; case SDL_CONTROLLER_AXIS_LEFTY: - state->lsY = -event->value; + // Signed values have one more negative value than + // positive value, so inverting the sign on -32768 + // could actually cause the value to overflow and + // wrap around to be negative again. Avoid that by + // capping the value at 32767. + state->lsY = -qMax(event->value, (short)-32767); break; case SDL_CONTROLLER_AXIS_RIGHTX: state->rsX = event->value; break; case SDL_CONTROLLER_AXIS_RIGHTY: - state->rsY = -event->value; + state->rsY = -qMax(event->value, (short)-32767); break; case SDL_CONTROLLER_AXIS_TRIGGERLEFT: state->lt = (unsigned char)(event->value * 255UL / 32767);