SFML community forums
Help => Window => Topic started by: TestSubject06 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.
-
I'm not quite sure what you're trying to separate. What are "XInput" devices in your opinion? And what are "the other devices"?
-
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.
-
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?
-
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.)
-
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?
-
I've been attempting to update to it, but I've got all sorts of entry point errors in dlls. Font rendering issues, ugh.
-
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.
-
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.