summaryrefslogtreecommitdiff
path: root/src/input_common/sdl/sdl_impl.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2020-08-28 21:13:23 -0400
committerGravatar Lioncash2020-08-28 21:13:26 -0400
commite92164e6a06361382b8072228530f69a6b10189f (patch)
tree9a92ac94e4f5d57c8c2606fd196a13b22cf58820 /src/input_common/sdl/sdl_impl.cpp
parentsdl_impl: Prevent type truncation in BuildAnalogParamPackageForButton() defau... (diff)
downloadyuzu-e92164e6a06361382b8072228530f69a6b10189f.tar.gz
yuzu-e92164e6a06361382b8072228530f69a6b10189f.tar.xz
yuzu-e92164e6a06361382b8072228530f69a6b10189f.zip
sdl_impl: Make use of insert_or_assign() where applicable
Avoids churning ParamPackage instances.
Diffstat (limited to 'src/input_common/sdl/sdl_impl.cpp')
-rw-r--r--src/input_common/sdl/sdl_impl.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 9d3d1803c..85fcd457c 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -697,16 +697,17 @@ ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& pa
697 return {}; 697 return {};
698 } 698 }
699 const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0)); 699 const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
700 auto controller = joystick->GetSDLGameController(); 700 auto* controller = joystick->GetSDLGameController();
701 if (!controller) { 701 if (controller == nullptr) {
702 return {}; 702 return {};
703 } 703 }
704 704
705 ButtonMapping mapping{}; 705 ButtonMapping mapping{};
706 for (const auto& [switch_button, sdl_button] : switch_to_sdl_button) { 706 for (const auto& [switch_button, sdl_button] : switch_to_sdl_button) {
707 const auto& binding = SDL_GameControllerGetBindForButton(controller, sdl_button); 707 const auto& binding = SDL_GameControllerGetBindForButton(controller, sdl_button);
708 mapping[switch_button] = 708 mapping.insert_or_assign(
709 BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding); 709 switch_button,
710 BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
710 } 711 }
711 712
712 // Add the missing bindings for ZL/ZR 713 // Add the missing bindings for ZL/ZR
@@ -717,8 +718,9 @@ ButtonMapping SDLState::GetButtonMappingForDevice(const Common::ParamPackage& pa
717 }; 718 };
718 for (const auto& [switch_button, sdl_axis] : switch_to_sdl_axis) { 719 for (const auto& [switch_button, sdl_axis] : switch_to_sdl_axis) {
719 const auto& binding = SDL_GameControllerGetBindForAxis(controller, sdl_axis); 720 const auto& binding = SDL_GameControllerGetBindForAxis(controller, sdl_axis);
720 mapping[switch_button] = 721 mapping.insert_or_assign(
721 BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding); 722 switch_button,
723 BuildParamPackageForBinding(joystick->GetPort(), joystick->GetGUID(), binding));
722 } 724 }
723 725
724 return mapping; 726 return mapping;
@@ -729,8 +731,8 @@ AnalogMapping SDLState::GetAnalogMappingForDevice(const Common::ParamPackage& pa
729 return {}; 731 return {};
730 } 732 }
731 const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0)); 733 const auto joystick = GetSDLJoystickByGUID(params.Get("guid", ""), params.Get("port", 0));
732 auto controller = joystick->GetSDLGameController(); 734 auto* controller = joystick->GetSDLGameController();
733 if (!controller) { 735 if (controller == nullptr) {
734 return {}; 736 return {};
735 } 737 }
736 738
@@ -739,16 +741,18 @@ AnalogMapping SDLState::GetAnalogMappingForDevice(const Common::ParamPackage& pa
739 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX); 741 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX);
740 const auto& binding_left_y = 742 const auto& binding_left_y =
741 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY); 743 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY);
742 mapping[Settings::NativeAnalog::LStick] = 744 mapping.insert_or_assign(Settings::NativeAnalog::LStick,
743 BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(), 745 BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(),
744 binding_left_x.value.axis, binding_left_y.value.axis); 746 binding_left_x.value.axis,
747 binding_left_y.value.axis));
745 const auto& binding_right_x = 748 const auto& binding_right_x =
746 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX); 749 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX);
747 const auto& binding_right_y = 750 const auto& binding_right_y =
748 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY); 751 SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY);
749 mapping[Settings::NativeAnalog::RStick] = 752 mapping.insert_or_assign(Settings::NativeAnalog::RStick,
750 BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(), 753 BuildParamPackageForAnalog(joystick->GetPort(), joystick->GetGUID(),
751 binding_right_x.value.axis, binding_right_y.value.axis); 754 binding_right_x.value.axis,
755 binding_right_y.value.axis));
752 return mapping; 756 return mapping;
753} 757}
754 758