diff options
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 03888b7cb..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) { |
| @@ -254,11 +255,25 @@ public: | |||
| 254 | } | 255 | } |
| 255 | 256 | ||
| 256 | bool IsJoyconLeft() const { | 257 | bool IsJoyconLeft() const { |
| 257 | return std::strstr(GetControllerName().c_str(), "Joy-Con Left") != nullptr; | 258 | const std::string controller_name = GetControllerName(); |
| 259 | if (std::strstr(controller_name.c_str(), "Joy-Con Left") != nullptr) { | ||
| 260 | return true; | ||
| 261 | } | ||
| 262 | if (std::strstr(controller_name.c_str(), "Joy-Con (L)") != nullptr) { | ||
| 263 | return true; | ||
| 264 | } | ||
| 265 | return false; | ||
| 258 | } | 266 | } |
| 259 | 267 | ||
| 260 | bool IsJoyconRight() const { | 268 | bool IsJoyconRight() const { |
| 261 | return std::strstr(GetControllerName().c_str(), "Joy-Con Right") != nullptr; | 269 | const std::string controller_name = GetControllerName(); |
| 270 | if (std::strstr(controller_name.c_str(), "Joy-Con Right") != nullptr) { | ||
| 271 | return true; | ||
| 272 | } | ||
| 273 | if (std::strstr(controller_name.c_str(), "Joy-Con (R)") != nullptr) { | ||
| 274 | return true; | ||
| 275 | } | ||
| 276 | return false; | ||
| 262 | } | 277 | } |
| 263 | 278 | ||
| 264 | std::string GetControllerName() const { | 279 | std::string GetControllerName() const { |
| @@ -775,8 +790,8 @@ public: | |||
| 775 | const std::string invert_y_value = params.Get("invert_y", "+"); | 790 | const std::string invert_y_value = params.Get("invert_y", "+"); |
| 776 | const bool invert_x = invert_x_value == "-"; | 791 | const bool invert_x = invert_x_value == "-"; |
| 777 | const bool invert_y = invert_y_value == "-"; | 792 | const bool invert_y = invert_y_value == "-"; |
| 778 | 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); |
| 779 | 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); |
| 780 | auto joystick = state.GetSDLJoystickByGUID(guid, port); | 795 | auto joystick = state.GetSDLJoystickByGUID(guid, port); |
| 781 | 796 | ||
| 782 | // 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 |