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

Author Topic: XInput support in SFML?  (Read 9470 times)

0 Members and 2 Guests are viewing this topic.

ekun

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Vagante
    • Email
XInput support in SFML?
« on: April 07, 2016, 02:05:10 am »
I'm currently implementing XInput and DirectInput support for our game, and I was wondering if XInput support belongs in SFML. If so, I wouldn't mind submitting a pull request when I'm done.

The current sf::Joystick uses the Windows Multimedia API, which works decently for most use cases. But having official support for XInput adds some useful things.
  • It fixes the annoying bug of not being able to press L2 and R2 at the same time.
  • It lets us easily detect and use a standardized controller configuration, instead of manually checking against a long list of different product ids and vendor ids.
  • It allows us to send controller vibration events if SFML ever decides to add them.
Because XInput doesn't support certain controllers, it needs to be implemented alongside winmm or DirectInput for full gamepad support.


As a side note: my preliminary testing using DirectInput over winmm seems to indicate improved performance. It looks like winmm's joyGetPosEx(...) occasionally takes a lot of time to execute, but I need to do more testing to see what's going on.
@ekunenuke

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: XInput support in SFML?
« Reply #1 on: April 07, 2016, 09:20:01 am »
What are the alternatives for the other OS (Linux, OS X, ...)?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ekun

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Vagante
    • Email
Re: XInput support in SFML?
« Reply #2 on: April 07, 2016, 09:52:27 am »
What are the alternatives for the other OS (Linux, OS X, ...)?

That's a good question. I'm honestly not sure how one would go about adding XInput support on Linux/OSX. I assumed that the Linux/Mac implementations wouldn't have to change.
@ekunenuke

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: XInput support in SFML?
« Reply #3 on: April 07, 2016, 10:13:28 am »
Or differently asked, can the things XInput would bring be supported as well on OS X/Linux?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ekun

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Vagante
    • Email
Re: XInput support in SFML?
« Reply #4 on: April 07, 2016, 08:39:15 pm »
It looks like force feedback is doable cross-platform, based on this thread: http://en.sfml-dev.org/forums/index.php?topic=19665.0

Regarding detecting and having full support (fixed L2/R2 triggers) for XInput gamepads, I'm not sure if that's possible. There are cross-platform driver solutions for XInput controllers like xboxdrv and 360Controller, but I don't know how one would go about integrating that into SFML.
@ekunenuke

kukininja

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: XInput support in SFML?
« Reply #5 on: February 25, 2020, 10:26:27 pm »
Hello
So after doing some digging i was able to find "A small tutorial on how to use XInput"
https://www.codeproject.com/Articles/26949/Xbox-360-Controller-Input-in-C-with-XInput
With his sample project i was able to create a proof of concept where i had LeftTrigger and RightTrigger split into two, and vibrating. Had no time(and knowlege of xinput) to test more.

(his sources compiled without issues in Visual Studio 2019)
« Last Edit: February 25, 2020, 10:28:01 pm by kukininja »