Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Gamepad Class for SFML (using XInput and SDL database)  (Read 12845 times)

0 Members and 1 Guest are viewing this topic.

Guido_Ion

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Flow Soccer development
Gamepad Class for SFML (using XInput and SDL database)
« on: October 09, 2021, 12:12:19 am »
Hi guys I wanted to share this class that I made that uses SDL's controller database. I started looking for a gamepad db for SFML and I noticed that it is a common request from users so I decided to do it myself.

https://github.com/GuidoBisocoli/SFML_GamepadSupport


Features:
  • It supports Left and Right Trigger as button or axis seamlessly
  • It manages inverted axes

TO DO:
  • Support for dpad
  • Hide buttons, axes and triggers, now they are public
  • Read also linux and MacOs gamepads
  • Test gamepads

I've only tested it with my 2 gamepads (Logitech Dual Action and Controller (XBOX 360 For Windows)) and it works great, if you can help testing other gamepads please comment and let us know.
« Last Edit: October 25, 2021, 08:27:10 pm by Guido_Ion »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Oh, this is really cool to see.
Yes, it's been something that quite a few people have requested and/or thought about doing.

Would be awesome if you could put it somewhere on GitHub/GitLab and add a license, so it can be more easily shared and contributed to, plus the license makes it possible to use it (I recommend MIT or similar permissive license).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Guido_Ion

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Flow Soccer development
Uploaded!

https://github.com/GuidoBisocoli/SFML_GamepadSupport

I added XInput support and other things, still some things to do and also check more gamepads. MIT license  :)

Guido_Ion

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Flow Soccer development
Re: Gamepad Class for SFML (using XInput and SDL database)
« Reply #3 on: October 25, 2021, 08:30:07 pm »
Added support for events with the method "getButtonNumber(GAMEPAD_BUTTON btn)"

Code: [Select]
if (_currentEvent.type == sf::Event::EventType::JoystickButtonReleased && _currentEvent.joystickButton.joystickId == 0 && _currentEvent.joystickButton.button == _gamepadOne->getButtonNumber(Gamepad::GAMEPAD_BUTTON::btn_start))
  /// do something

This is to avoid checking many times the same button.

Guido_Ion

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Flow Soccer development
Re: Gamepad Class for SFML (using XInput and SDL database)
« Reply #4 on: December 22, 2021, 06:38:41 pm »
Update:
- XInput gamepad number is not always the same as the number provided by sf::Joystick, this is determined and handled properly by the Gamepad Manager.

This was an issue when connecting an XInput Gamepad and another not XInput Gamepad and the number assigned by XInput (always 0 if there is only one connected) didn't match the number provided by sf::Joystick which can be 0 or 1.

For this I added a Gamepad Manager that takes care of initializing and populating every Gamepad whether it is XInput or other and regardless of whether the XInput number matches or not the one provided by sf::Joystick.