summaryrefslogtreecommitdiff
path: root/src/input_common/sdl/sdl_impl.cpp
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-10-13 15:15:18 -0700
committerGitHub <noreply@github.com>2021-10-13 15:15:18 -0700
commit2643752f9343a7464e46c813104333911ad070fb (patch)
treecd726588a3bb623c5ab0c27a0c9b504399d1e697 /src/input_common/sdl/sdl_impl.cpp
parent9f0f827db47b7aaec45f3d0ee87a0e3ad14ebc5c (diff)
parent8212a864cad67b5b3c1fb2212a637801539ba7eb (diff)
Merge pull request #7142 from german77/sdl_range
input_common/sdl: Fix joystick range
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
-rw-r--r--src/input_common/sdl/sdl_impl.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index ab6211b29..ecb00d428 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -170,7 +170,8 @@ public:
float GetAxis(int axis, float range, float offset) const {
std::lock_guard lock{mutex};
const float value = static_cast<float>(state.axes.at(axis)) / 32767.0f;
- return (value + offset) / range;
+ const float offset_scale = (value + offset) > 0.0f ? 1.0f + offset : 1.0f - offset;
+ return (value + offset) / range / offset_scale;
}
bool RumblePlay(u16 amp_low, u16 amp_high) {
@@ -789,8 +790,8 @@ public:
const std::string invert_y_value = params.Get("invert_y", "+");
const bool invert_x = invert_x_value == "-";
const bool invert_y = invert_y_value == "-";
- const float offset_x = params.Get("offset_x", 0.0f);
- const float offset_y = params.Get("offset_y", 0.0f);
+ const float offset_x = std::clamp(params.Get("offset_x", 0.0f), -0.99f, 0.99f);
+ const float offset_y = std::clamp(params.Get("offset_y", 0.0f), -0.99f, 0.99f);
auto joystick = state.GetSDLJoystickByGUID(guid, port);
// This is necessary so accessing GetAxis with axis_x and axis_y won't crash