1
0
mirror of https://github.com/cathery/sys-con.git synced 2024-12-28 09:17:34 +00:00

Remove unnecessary bound checks since this was a one-off error

Thanks libnx
This commit is contained in:
cathery 2020-01-24 02:03:52 +03:00
parent bbed9abf55
commit 033b9abece
2 changed files with 2 additions and 8 deletions

View File

@ -27,7 +27,8 @@ void SwitchControllerHandler::Exit()
void SwitchControllerHandler::ConvertAxisToSwitchAxis(float x, float y, float deadzone, s32 *x_out, s32 *y_out) void SwitchControllerHandler::ConvertAxisToSwitchAxis(float x, float y, float deadzone, s32 *x_out, s32 *y_out)
{ {
float floatRange = 2.0f; float floatRange = 2.0f;
float newRange = (JOYSTICK_MAX - JOYSTICK_MIN); //JOYSTICK_MAX is 1 above the s16 max value, causing crashes on various games including Xenoblade Chronicles 2
float newRange = ((JOYSTICK_MAX-1) - JOYSTICK_MIN);
*x_out = (((x + 1.0f) * newRange) / floatRange) + JOYSTICK_MIN; *x_out = (((x + 1.0f) * newRange) / floatRange) + JOYSTICK_MIN;
*y_out = (((y + 1.0f) * newRange) / floatRange) + JOYSTICK_MIN; *y_out = (((y + 1.0f) * newRange) / floatRange) + JOYSTICK_MIN;

View File

@ -1,7 +1,6 @@
#include "SwitchHDLHandler.h" #include "SwitchHDLHandler.h"
#include "ControllerHelpers.h" #include "ControllerHelpers.h"
#include <cmath> #include <cmath>
#include <algorithm>
SwitchHDLHandler::SwitchHDLHandler(std::unique_ptr<IController> &&controller) SwitchHDLHandler::SwitchHDLHandler(std::unique_ptr<IController> &&controller)
: SwitchVirtualGamepadHandler(std::move(controller)) : SwitchVirtualGamepadHandler(std::move(controller))
@ -159,12 +158,6 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data)
m_controllerHandler.ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_hdlState.joysticks[JOYSTICK_RIGHT].dx, &m_hdlState.joysticks[JOYSTICK_RIGHT].dy); m_controllerHandler.ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_hdlState.joysticks[JOYSTICK_RIGHT].dx, &m_hdlState.joysticks[JOYSTICK_RIGHT].dy);
//Actual joystick values never use the full range of the s32 type and exceeding them has caused crashes with multiple games, so we clamp them to s16
m_hdlState.joysticks[JOYSTICK_LEFT].dx = std::clamp(m_hdlState.joysticks[JOYSTICK_LEFT].dx, -32768, 32768 -1);
m_hdlState.joysticks[JOYSTICK_LEFT].dy = std::clamp(m_hdlState.joysticks[JOYSTICK_LEFT].dy, -32768, 32768 -1);
m_hdlState.joysticks[JOYSTICK_RIGHT].dx = std::clamp(m_hdlState.joysticks[JOYSTICK_RIGHT].dx, -32768, 32768 -1);
m_hdlState.joysticks[JOYSTICK_RIGHT].dy = std::clamp(m_hdlState.joysticks[JOYSTICK_RIGHT].dy, -32768, 32768 -1);
m_hdlState.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0); m_hdlState.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0);
m_hdlState.buttons |= (data.buttons[17] ? KEY_HOME : 0); m_hdlState.buttons |= (data.buttons[17] ? KEY_HOME : 0);
m_hdlState.buttons |= (data.buttons[18] ? KEY_TOUCH : 0); m_hdlState.buttons |= (data.buttons[18] ? KEY_TOUCH : 0);