XInput

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

Post Reply
User avatar
Kjell
Posts: 1911
Joined: Sat Feb 23, 2008 11:15 pm

XInput

Post by Kjell »

8)

For people that also want / need to support XInput* gamepads. Attached is a small wrapper & demo .. the left & right rumble motors are tied to the left & right analog triggers ( for demonstration purposes ).

*XInput only supports XInput compatible devices, while the build-in joystick functions don't support XInput-only devices.

K
Attachments
XInput.zgeproj
(56.32 KiB) Downloaded 696 times
User avatar
Ats
Posts: 716
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: XInput

Post by Ats »

Nice. Does it detect digital pad and shoulders buttons too? Those were not working before.
I'll try that this afternoon :)
User avatar
Kjell
Posts: 1911
Joined: Sat Feb 23, 2008 11:15 pm

Re: XInput

Post by Kjell »

Hi Ats,
Ats wrote: Mon Aug 03, 2020 11:17 amDoes it detect digital pad and shoulders buttons too?
I haven't tested it with every XInput compatible controller in existence .. but no problems ( for me ) so far :wink:

Image
Ats wrote: Mon Aug 03, 2020 11:17 amThose were not working before.
You have a controller that works with the built-in joystick functions except for the D-Pad and shoulder buttons? That's pretty strange.

K
User avatar
Ats
Posts: 716
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: XInput

Post by Ats »

Time flies by so quickly... But I'm finally playing with your XInput example :lol:
And I have two questions:

I tried making an apk out of the example, but it crashes right from the start. Is it because the Android gamepad isn't an XInput? I'd like to detect if the gamepad is an XInput or not, so it could redirect to the basic gamepad detection.

As it is the first time I see the rumble working, I have a noob question: are the two rumbles you activate using the trigger buttons supposed to be left and right? Or a different kind of rumbling? Because mine is doing a slow "wom wom wom" for left, and a quick "bzzzzzzz" for right. Is it normal or is it because my gamepad felt a few times since I bought it ten years ago? :roll:
User avatar
Kjell
Posts: 1911
Joined: Sat Feb 23, 2008 11:15 pm

Re: XInput

Post by Kjell »

Hi Ats,
Ats wrote: Mon Nov 02, 2020 4:54 pmI tried making an apk out of the example, but it crashes right from the start.
XInput is Windows only ( it's part of DirectX ) .. although unofficial drivers exist for Linux and Mac.
Ats wrote: Mon Nov 02, 2020 4:54 pmI have a noob question: are the two rumbles you activate using the trigger buttons supposed to be left and right?
Correct, left trigger controls the left motor & right trigger controls the right motor.
Ats wrote: Mon Nov 02, 2020 4:54 pmOr a different kind of rumbling? Because mine is doing a slow "wom wom wom" for left, and a quick "bzzzzzzz" for right. Is it normal or is it because my gamepad felt a few times since I bought it ten years ago? :roll:
Image

That's normal, the left motor has a much bigger weight attached than the right motor. Just like most speakers have a "woofer" and a "tweeter".

K
User avatar
Ats
Posts: 716
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: XInput

Post by Ats »

Thanks for the explanations :wink:

On Linux, the vibration stops if the trigger is fully pressed. I fixed it by clamping to 0.99 instead of 1:

Code: Select all

int XInputSetVibration(int gamepad, float left, float right)
{
  int l, r, v;
  l = clamp( left, 0, 0.99)*65535;
  r = clamp(right, 0, 0.99)*65535;
  v = l+(r<<16);
  XInputSetState(gamepad, v);
}
And in order to launch on Android without crash, I added that to BeforeInitExp. Not sure if it's the right thing to do, but it's working:

Code: Select all

if(ANDROID)
{
  this.ModuleName = "";
}
else
{
  this.ModuleName = "XInput9_1_0";
}
(and obviously, I don't rely on XInput functions if I'm on Android)
User avatar
Ats
Posts: 716
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: XInput

Post by Ats »

Years later, some players could not launch the game on Linux and I couldn't find why.
After reinstalling Linux on my laptop, I discovered that it was not crashing for me because, at some point, I installed some weird XInput libraries for Linux. But with a fresh install, the game is crashing like everyone else.
Since I don't know how to detect if the library is installed or not, I simply deactivated the XInput on Linux.

By the way, do you know something about XInput9_1_0 and XInput1_3?
DirectX seems to have XInput1_3 nowadays: https://www.microsoft.com/fr-fr/downloa ... aspx?id=35
(which is a weird version number, compared to XInput9_1_0)

Edit:
Never mind, XInput1_3 is for Windows Server 2008; Windows XP Service Pack 3; Windows Server 2003 Service Pack 1; Windows Server 2003 Service Pack 2; Windows 7; Windows XP Service Pack 2; Windows Vista
So it is older.
User avatar
Kjell
Posts: 1911
Joined: Sat Feb 23, 2008 11:15 pm

Re: XInput

Post by Kjell »

Hi Ats,
Ats wrote: Mon Jan 02, 2023 11:41 amAfter reinstalling Linux on my laptop, I discovered that it was not crashing for me because, at some point, I installed some weird XInput libraries for Linux. But with a fresh install, the game is crashing like everyone else.
Right, calling external functions of which the DLL isn't present will crash your executable. I guess Ville could add a property on ZExternalLibrary that represents if the DLL has been found or not, but that's typically a situation you want to avoid anyway.
Ats wrote: Mon Jan 02, 2023 11:41 amBy the way, do you know something about XInput9_1_0 and XInput1_3?
You can read more about the different versions of XInput here. And as far as i know XInput 9.1.0 was named / numbered that because it first shipped with DirectX 9. They dropped the DirectX version prefix with subsequent releases, so 9.1.0 is actually version 1.0.

K
Post Reply