diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 52 |
1 files changed, 20 insertions, 32 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 35a9d45ec..dec7540e2 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -545,17 +545,16 @@ SDLState::~SDLState() { | |||
| 545 | 545 | ||
| 546 | std::vector<Common::ParamPackage> SDLState::GetInputDevices() { | 546 | std::vector<Common::ParamPackage> SDLState::GetInputDevices() { |
| 547 | std::scoped_lock lock(joystick_map_mutex); | 547 | std::scoped_lock lock(joystick_map_mutex); |
| 548 | std::vector<Common::ParamPackage> devices = {}; | 548 | std::vector<Common::ParamPackage> devices; |
| 549 | for (const auto& [key, value] : joystick_map) { | 549 | for (const auto& [key, value] : joystick_map) { |
| 550 | for (const auto& joystick : value) { | 550 | for (const auto& joystick : value) { |
| 551 | auto controller = joystick->GetSDLGameController(); | ||
| 552 | auto joy = joystick->GetSDLJoystick(); | 551 | auto joy = joystick->GetSDLJoystick(); |
| 553 | if (controller) { | 552 | if (auto controller = joystick->GetSDLGameController()) { |
| 554 | std::string name = | 553 | std::string name = |
| 555 | fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort()); | 554 | fmt::format("{} {}", SDL_GameControllerName(controller), joystick->GetPort()); |
| 556 | devices.emplace_back(Common::ParamPackage{ | 555 | devices.emplace_back(Common::ParamPackage{ |
| 557 | {"class", "sdl"}, | 556 | {"class", "sdl"}, |
| 558 | {"display", name}, | 557 | {"display", std::move(name)}, |
| 559 | {"guid", joystick->GetGUID()}, | 558 | {"guid", joystick->GetGUID()}, |
| 560 | {"port", std::to_string(joystick->GetPort())}, | 559 | {"port", std::to_string(joystick->GetPort())}, |
| 561 | }); | 560 | }); |
| @@ -563,7 +562,7 @@ std::vector<Common::ParamPackage> SDLState::GetInputDevices() { | |||
| 563 | std::string name = fmt::format("{} {}", SDL_JoystickName(joy), joystick->GetPort()); | 562 | std::string name = fmt::format("{} {}", SDL_JoystickName(joy), joystick->GetPort()); |
| 564 | devices.emplace_back(Common::ParamPackage{ | 563 | devices.emplace_back(Common::ParamPackage{ |
| 565 | {"class", "sdl"}, | 564 | {"class", "sdl"}, |
| 566 | {"display", name}, | 565 | {"display", std::move(name)}, |
| 567 | {"guid", joystick->GetGUID()}, | 566 | {"guid", joystick->GetGUID()}, |
| 568 | {"port", std::to_string(joystick->GetPort())}, | 567 | {"port", std::to_string(joystick->GetPort())}, |
| 569 | }); | 568 | }); |
| @@ -624,54 +623,43 @@ Common::ParamPackage BuildHatParamPackageForButton(int port, std::string guid, u | |||
| 624 | } | 623 | } |
| 625 | 624 | ||
| 626 | Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const SDL_Event& event) { | 625 | Common::ParamPackage SDLEventToButtonParamPackage(SDLState& state, const SDL_Event& event) { |
| 627 | Common::ParamPackage params{}; | ||
| 628 | |||
| 629 | switch (event.type) { | 626 | switch (event.type) { |
| 630 | case SDL_JOYAXISMOTION: { | 627 | case SDL_JOYAXISMOTION: { |
| 631 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); | 628 | const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which); |
| 632 | params = BuildAnalogParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 629 | return BuildAnalogParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 633 | event.jaxis.axis, event.jaxis.value); | 630 | event.jaxis.axis, event.jaxis.value); |
| 634 | break; | ||
| 635 | } | 631 | } |
| 636 | case SDL_JOYBUTTONUP: { | 632 | case SDL_JOYBUTTONUP: { |
| 637 | const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); | 633 | const auto joystick = state.GetSDLJoystickBySDLID(event.jbutton.which); |
| 638 | params = BuildButtonParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 634 | return BuildButtonParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 639 | event.jbutton.button); | 635 | event.jbutton.button); |
| 640 | break; | ||
| 641 | } | 636 | } |
| 642 | case SDL_JOYHATMOTION: { | 637 | case SDL_JOYHATMOTION: { |
| 643 | const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); | 638 | const auto joystick = state.GetSDLJoystickBySDLID(event.jhat.which); |
| 644 | params = BuildHatParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), | 639 | return BuildHatParamPackageForButton(joystick->GetPort(), joystick->GetGUID(), |
| 645 | event.jhat.hat, event.jhat.value); | 640 | event.jhat.hat, event.jhat.value); |
| 646 | break; | ||
| 647 | } | 641 | } |
| 648 | } | 642 | } |
| 649 | return params; | 643 | return {}; |
| 650 | } | 644 | } |
| 651 | 645 | ||
| 652 | Common::ParamPackage BuildParamPackageForBinding(int port, const std::string& guid, | 646 | Common::ParamPackage BuildParamPackageForBinding(int port, const std::string& guid, |
| 653 | const SDL_GameControllerButtonBind& binding) { | 647 | const SDL_GameControllerButtonBind& binding) { |
| 654 | Common::ParamPackage out{}; | ||
| 655 | switch (binding.bindType) { | 648 | switch (binding.bindType) { |
| 656 | case SDL_CONTROLLER_BINDTYPE_AXIS: | 649 | case SDL_CONTROLLER_BINDTYPE_AXIS: |
| 657 | out = BuildAnalogParamPackageForButton(port, guid, binding.value.axis); | 650 | return BuildAnalogParamPackageForButton(port, guid, binding.value.axis); |
| 658 | break; | ||
| 659 | case SDL_CONTROLLER_BINDTYPE_BUTTON: | 651 | case SDL_CONTROLLER_BINDTYPE_BUTTON: |
| 660 | out = BuildButtonParamPackageForButton(port, guid, binding.value.button); | 652 | return BuildButtonParamPackageForButton(port, guid, binding.value.button); |
| 661 | break; | ||
| 662 | case SDL_CONTROLLER_BINDTYPE_HAT: | 653 | case SDL_CONTROLLER_BINDTYPE_HAT: |
| 663 | out = BuildHatParamPackageForButton(port, guid, binding.value.hat.hat, | 654 | return BuildHatParamPackageForButton(port, guid, binding.value.hat.hat, |
| 664 | binding.value.hat.hat_mask); | 655 | binding.value.hat.hat_mask); |
| 665 | break; | ||
| 666 | default: | ||
| 667 | break; | ||
| 668 | } | 656 | } |
| 669 | return out; | 657 | return {}; |
| 670 | }; | 658 | } |
| 671 | 659 | ||
| 672 | Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& guid, int axis_x, | 660 | Common::ParamPackage BuildParamPackageForAnalog(int port, const std::string& guid, int axis_x, |
| 673 | int axis_y) { | 661 | int axis_y) { |
| 674 | Common::ParamPackage params{}; | 662 | Common::ParamPackage params; |
| 675 | params.Set("engine", "sdl"); | 663 | params.Set("engine", "sdl"); |
| 676 | params.Set("port", port); | 664 | params.Set("port", port); |
| 677 | params.Set("guid", guid); | 665 | params.Set("guid", guid); |
| @@ -769,7 +757,7 @@ class SDLPoller : public InputCommon::Polling::DevicePoller { | |||
| 769 | public: | 757 | public: |
| 770 | explicit SDLPoller(SDLState& state_) : state(state_) {} | 758 | explicit SDLPoller(SDLState& state_) : state(state_) {} |
| 771 | 759 | ||
| 772 | void Start(std::string device_id) override { | 760 | void Start(const std::string& device_id) override { |
| 773 | state.event_queue.Clear(); | 761 | state.event_queue.Clear(); |
| 774 | state.polling = true; | 762 | state.polling = true; |
| 775 | } | 763 | } |
| @@ -821,7 +809,7 @@ public: | |||
| 821 | explicit SDLAnalogPreferredPoller(SDLState& state_) | 809 | explicit SDLAnalogPreferredPoller(SDLState& state_) |
| 822 | : SDLPoller(state_), button_poller(state_) {} | 810 | : SDLPoller(state_), button_poller(state_) {} |
| 823 | 811 | ||
| 824 | void Start(std::string device_id) override { | 812 | void Start(const std::string& device_id) override { |
| 825 | SDLPoller::Start(device_id); | 813 | SDLPoller::Start(device_id); |
| 826 | // Load the game controller | 814 | // Load the game controller |
| 827 | // Reset stored axes | 815 | // Reset stored axes |