diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 3b5a4a8fc..ddb88cc38 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -24,7 +24,7 @@ | |||
| 24 | namespace InputCommon::SDL { | 24 | namespace InputCommon::SDL { |
| 25 | 25 | ||
| 26 | static std::string GetGUID(SDL_Joystick* joystick) { | 26 | static std::string GetGUID(SDL_Joystick* joystick) { |
| 27 | SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick); | 27 | const SDL_JoystickGUID guid = SDL_JoystickGetGUID(joystick); |
| 28 | char guid_str[33]; | 28 | char guid_str[33]; |
| 29 | SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); | 29 | SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); |
| 30 | return guid_str; | 30 | return guid_str; |
| @@ -158,7 +158,7 @@ std::shared_ptr<SDLJoystick> SDLState::GetSDLJoystickBySDLID(SDL_JoystickID sdl_ | |||
| 158 | const std::string guid = GetGUID(sdl_joystick); | 158 | const std::string guid = GetGUID(sdl_joystick); |
| 159 | 159 | ||
| 160 | std::lock_guard lock{joystick_map_mutex}; | 160 | std::lock_guard lock{joystick_map_mutex}; |
| 161 | auto map_it = joystick_map.find(guid); | 161 | const auto map_it = joystick_map.find(guid); |
| 162 | if (map_it != joystick_map.end()) { | 162 | if (map_it != joystick_map.end()) { |
| 163 | const auto vec_it = | 163 | const auto vec_it = |
| 164 | std::find_if(map_it->second.begin(), map_it->second.end(), | 164 | std::find_if(map_it->second.begin(), map_it->second.end(), |
| @@ -320,9 +320,10 @@ public: | |||
| 320 | trigger_if_greater(trigger_if_greater_) {} | 320 | trigger_if_greater(trigger_if_greater_) {} |
| 321 | 321 | ||
| 322 | bool GetStatus() const override { | 322 | bool GetStatus() const override { |
| 323 | float axis_value = joystick->GetAxis(axis); | 323 | const float axis_value = joystick->GetAxis(axis); |
| 324 | if (trigger_if_greater) | 324 | if (trigger_if_greater) { |
| 325 | return axis_value > threshold; | 325 | return axis_value > threshold; |
| 326 | } | ||
| 326 | return axis_value < threshold; | 327 | return axis_value < threshold; |
| 327 | } | 328 | } |
| 328 | 329 | ||
| @@ -447,7 +448,7 @@ public: | |||
| 447 | const int port = params.Get("port", 0); | 448 | const int port = params.Get("port", 0); |
| 448 | const int axis_x = params.Get("axis_x", 0); | 449 | const int axis_x = params.Get("axis_x", 0); |
| 449 | const int axis_y = params.Get("axis_y", 1); | 450 | const int axis_y = params.Get("axis_y", 1); |
| 450 | float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); | 451 | const float deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, .99f); |
| 451 | 452 | ||
| 452 | auto joystick = state.GetSDLJoystickByGUID(guid, port); | 453 | auto joystick = state.GetSDLJoystickByGUID(guid, port); |
| 453 | 454 | ||
| @@ -515,7 +516,7 @@ static Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const | |||
| 515 | 516 | ||
| 516 | switch (event.type) { | 517 | switch (event.type) { |
| 517 | case SDL_JOYAXISMOTION: { | 518 | case SDL_JOYAXISMOTION: { |
| 518 | auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); | 519 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); |
| 519 | params.Set("port", joystick->GetPort()); | 520 | params.Set("port", joystick->GetPort()); |
| 520 | params.Set("guid", joystick->GetGUID()); | 521 | params.Set("guid", joystick->GetGUID()); |
| 521 | params.Set("axis", event.jaxis.axis); | 522 | params.Set("axis", event.jaxis.axis); |
| @@ -529,14 +530,14 @@ static Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const | |||
| 529 | break; | 530 | break; |
| 530 | } | 531 | } |
| 531 | case SDL_JOYBUTTONUP: { | 532 | case SDL_JOYBUTTONUP: { |
| 532 | auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); | 533 | const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); |
| 533 | params.Set("port", joystick->GetPort()); | 534 | params.Set("port", joystick->GetPort()); |
| 534 | params.Set("guid", joystick->GetGUID()); | 535 | params.Set("guid", joystick->GetGUID()); |
| 535 | params.Set("button", event.jbutton.button); | 536 | params.Set("button", event.jbutton.button); |
| 536 | break; | 537 | break; |
| 537 | } | 538 | } |
| 538 | case SDL_JOYHATMOTION: { | 539 | case SDL_JOYHATMOTION: { |
| 539 | auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); | 540 | const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); |
| 540 | params.Set("port", joystick->GetPort()); | 541 | params.Set("port", joystick->GetPort()); |
| 541 | params.Set("guid", joystick->GetGUID()); | 542 | params.Set("guid", joystick->GetGUID()); |
| 542 | params.Set("hat", event.jhat.hat); | 543 | params.Set("hat", event.jhat.hat); |
| @@ -623,7 +624,7 @@ public: | |||
| 623 | } | 624 | } |
| 624 | // An analog device needs two axes, so we need to store the axis for later and wait for | 625 | // An analog device needs two axes, so we need to store the axis for later and wait for |
| 625 | // a second SDL event. The axes also must be from the same joystick. | 626 | // a second SDL event. The axes also must be from the same joystick. |
| 626 | int axis = event.jaxis.axis; | 627 | const int axis = event.jaxis.axis; |
| 627 | if (analog_xaxis == -1) { | 628 | if (analog_xaxis == -1) { |
| 628 | analog_xaxis = axis; | 629 | analog_xaxis = axis; |
| 629 | analog_axes_joystick = event.jaxis.which; | 630 | analog_axes_joystick = event.jaxis.which; |
| @@ -634,7 +635,7 @@ public: | |||
| 634 | } | 635 | } |
| 635 | Common::ParamPackage params; | 636 | Common::ParamPackage params; |
| 636 | if (analog_xaxis != -1 && analog_yaxis != -1) { | 637 | if (analog_xaxis != -1 && analog_yaxis != -1) { |
| 637 | auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); | 638 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); |
| 638 | params.Set("engine", "sdl"); | 639 | params.Set("engine", "sdl"); |
| 639 | params.Set("port", joystick->GetPort()); | 640 | params.Set("port", joystick->GetPort()); |
| 640 | params.Set("guid", joystick->GetGUID()); | 641 | params.Set("guid", joystick->GetGUID()); |