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

Author Topic: SFML 2.0 Joystick Identification  (Read 3866 times)

0 Members and 1 Guest are viewing this topic.

TestSubject06

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML 2.0 Joystick Identification
« on: August 11, 2014, 05:42:16 pm »
My project is still using SFML 2.0, and I was wondering if there was a way to identify if a joystick that's connected is an XInput device. I can poll all of the XInput devices, and all of the other devices, but I can't find any way to make a connection so that they aren't counted as separate devices.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 Joystick Identification
« Reply #1 on: August 11, 2014, 08:48:22 pm »
I'm not quite sure what you're trying to separate. What are "XInput" devices in your opinion? And what are "the other devices"?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TestSubject06

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML 2.0 Joystick Identification
« Reply #2 on: August 11, 2014, 09:16:43 pm »
An XInput device is a controller that is designed for use with the DirectX XInput driver. 'The other devices' are legacy devices that are not designed for use with the XInput driver.

Running a loop of sf::Joystick::isConnected(index) will get me up to 8 supported game controller devices. Running a loop of
bool isXInputControllerConnected(int _index){
   XINPUT_STATE state;
   ZeroMemory(&state, sizeof(XINPUT_STATE));
   DWORD result = XInputGetState(_index, &state);
   if(result == ERROR_SUCCESS){
      return true;
   }
}
will return a list of connected XInput devices. The problem I'm having is that those devices in the XInput list are also in SFML's Joystick list. I have no way to determine if a controller in the XInput device list and a controller in SFML's list are the same controller. I want to use XInput if a controller is compatable, but fall back on legacy support if it is not. The reason for this is because legacy drivers don't allow Xbox 360 controller triggers to properly be independent, which is super lame.
« Last Edit: August 11, 2014, 09:19:05 pm by TestSubject06 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 Joystick Identification
« Reply #3 on: August 11, 2014, 09:21:13 pm »
So you want to use SFML to check whether you should use your own XInput or Legacy support code?
Why do you need write your own Joystick code, or rather why can't you just go with SFML's sf::Joystick class?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TestSubject06

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML 2.0 Joystick Identification
« Reply #4 on: August 11, 2014, 09:32:13 pm »
Because by default in SFML 2.0, it APPEARS (I haven't dug too deeply) that the default behavior on windows is to use DirectInput. And while DirectInput is compatable with XInput devices, the triggers register as a single axis, one in the negative direction, and one in the positive direction. This was apparently by design on Microsoft's end, for whatever reason. SFML's (in version 2.0) built in code works perfectly fine for devices that aren't XInput devices.

http://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx

(Regardless of whether it uses DirectInput internally on a windows machine or not, the behavior is wrong by default, so I want to use XInput where appropriate.)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 Joystick Identification
« Reply #5 on: August 11, 2014, 09:38:01 pm »
I guess, I'm not the right person for this then, since I don't know enough about anything on this topic. :D

Anyways there's been some changes with the joystick class, did you ever try the current master branch?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TestSubject06

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML 2.0 Joystick Identification
« Reply #6 on: August 11, 2014, 09:39:45 pm »
I've been attempting to update to it, but I've got all sorts of entry point errors in dlls. Font rendering issues, ugh.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML 2.0 Joystick Identification
« Reply #7 on: August 11, 2014, 09:51:21 pm »
Since you are using platform-specific code anyway to access XInput devices, why do you need SFML for the recognition?

In any case, we recently introduced a new API for joystick identification; you should check the master branch. This concerns only name and vendor information, but maybe some of it is useful for you.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

TestSubject06

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML 2.0 Joystick Identification
« Reply #8 on: August 11, 2014, 10:09:54 pm »
Well I actually planned on putting the platform specific code in some #if stuff, that way when it's built for not-windows it would just use SFML for all of the controllers. I don't 100% know how that works yet, or if it will continue to properly support XInput devices on other platforms. (They aren't officially supported on those platforms anyways, so I can't be too worried about it if there's undefined or incorrect behavior.)

And yes, Vendor ID and Product ID should be exactly what I need.