diff options
| author | 2021-10-07 20:35:30 -0500 | |
|---|---|---|
| committer | 2021-10-11 01:03:01 -0500 | |
| commit | 8212a864cad67b5b3c1fb2212a637801539ba7eb (patch) | |
| tree | 9fcf59baa18ee9fdee1eb1e93ec0f2d38535232a /src/input_common/sdl/sdl_impl.cpp | |
| parent | Merge pull request #7118 from ameerj/vc-gpu-impl (diff) | |
| download | yuzu-8212a864cad67b5b3c1fb2212a637801539ba7eb.tar.gz yuzu-8212a864cad67b5b3c1fb2212a637801539ba7eb.tar.xz yuzu-8212a864cad67b5b3c1fb2212a637801539ba7eb.zip | |
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.cpp | 7 |
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: | |||
| 170 | float GetAxis(int axis, float range, float offset) const { | 170 | float GetAxis(int axis, float range, float offset) const { |
| 171 | std::lock_guard lock{mutex}; | 171 | std::lock_guard lock{mutex}; |
| 172 | const float value = static_cast<float>(state.axes.at(axis)) / 32767.0f; | 172 | const float value = static_cast<float>(state.axes.at(axis)) / 32767.0f; |
| 173 | return (value + offset) / range; | 173 | const float offset_scale = (value + offset) > 0.0f ? 1.0f + offset : 1.0f - offset; |
| 174 | return (value + offset) / range / offset_scale; | ||
| 174 | } | 175 | } |
| 175 | 176 | ||
| 176 | bool RumblePlay(u16 amp_low, u16 amp_high) { | 177 | bool RumblePlay(u16 amp_low, u16 amp_high) { |
| @@ -789,8 +790,8 @@ public: | |||
| 789 | const std::string invert_y_value = params.Get("invert_y", "+"); | 790 | const std::string invert_y_value = params.Get("invert_y", "+"); |
| 790 | const bool invert_x = invert_x_value == "-"; | 791 | const bool invert_x = invert_x_value == "-"; |
| 791 | const bool invert_y = invert_y_value == "-"; | 792 | const bool invert_y = invert_y_value == "-"; |
| 792 | const float offset_x = params.Get("offset_x", 0.0f); | 793 | const float offset_x = std::clamp(params.Get("offset_x", 0.0f), -0.99f, 0.99f); |
| 793 | const float offset_y = params.Get("offset_y", 0.0f); | 794 | const float offset_y = std::clamp(params.Get("offset_y", 0.0f), -0.99f, 0.99f); |
| 794 | auto joystick = state.GetSDLJoystickByGUID(guid, port); | 795 | auto joystick = state.GetSDLJoystickByGUID(guid, port); |
| 795 | 796 | ||
| 796 | // This is necessary so accessing GetAxis with axis_x and axis_y won't crash | 797 | // This is necessary so accessing GetAxis with axis_x and axis_y won't crash |