XInput

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

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

XInput

Post by Kjell » Sun Aug 02, 2020 5:02 pm

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 126 times

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

Re: XInput

Post by Ats » Mon Aug 03, 2020 11:17 am

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: 1770
Joined: Sat Feb 23, 2008 11:15 pm

Re: XInput

Post by Kjell » Mon Aug 03, 2020 11:50 am

Hi Ats,
Ats wrote:
Mon Aug 03, 2020 11:17 am
Does 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 am
Those 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: 438
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: XInput

Post by Ats » Mon Nov 02, 2020 4:54 pm

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: 1770
Joined: Sat Feb 23, 2008 11:15 pm

Re: XInput

Post by Kjell » Tue Nov 03, 2020 12:13 am

Hi Ats,
Ats wrote:
Mon Nov 02, 2020 4:54 pm
I 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 pm
I 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 pm
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:
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: 438
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: XInput

Post by Ats » Thu Nov 05, 2020 6:52 pm

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)

Post Reply