Xinput emulation (for Xbox360 games ported to Windows)

Discussion on the upcoming major revision of 3Dconnexion 3DxWare

Moderator: Moderators

Xinput emulation (for Xbox360 games ported to Windows)

Postby Hypersonic » Mon Jul 11, 2011 12:57 am

Although Microsoft has a page showing how game developers can support both DirectInput and Xinput
http://msdn.microsoft.com/en-us/library/ee417014%28v=vs.85%29.aspx
Some game developers might not end up adding it, or not adding it correctly. Maybe Xinput can be emulated, for these games?
Like Joystick X -> sThumbLX, Joystick Y -> sThumbLY, Joystick Rx -> sThumbRX, Joystick Ry -> sThumbRY
The LONGs rounded down to SHORTs.

Just to support games made for both Windows and the Xbox 360 console.
http://en.wikipedia.org/wiki/List_of_XInput_games

Taking a look at the structures of the APIs, I can see that Xinput really means XboxController Input (limited to 4 axis, 2bytes each)

XINPUT_STATE Structure
http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.xinput_state%28v=vs.85%29.aspx
XINPUT_GAMEPAD structure containing the current state of an Xbox 360 Controller.

XINPUT_GAMEPAD Structure
http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.xinput_gamepad%28v=vs.85%29.aspx

Code: Select all
typedef struct _XINPUT_GAMEPAD {
    WORD wButtons;
    BYTE bLeftTrigger;
    BYTE bRightTrigger;
    SHORT sThumbLX;
    SHORT sThumbLY;
    SHORT sThumbRX;
    SHORT sThumbRY;
} XINPUT_GAMEPAD, *PXINPUT_GAMEPAD;

Xinput has only 1/2 of the axis as DirectInput's DIJOYSTATE.
Each with only half the resolution (SHORT-2 bytes, LONG-4 bytes.)

DIJOYSTATE Structure
http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.dijoystate%28v=VS.85%29.aspx

Code: Select all
typedef struct DIJOYSTATE {
    LONG lX;
    LONG lY;
    LONG lZ;
    LONG lRx;
    LONG lRy;
    LONG lRz;
    LONG rglSlider[2];
    DWORD rgdwPOV[4];
    BYTE rgbButtons[32];
} DIJOYSTATE, *LPDIJOYSTATE;

DIJOYSTATE2 Structure
http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.reference.dijoystate2%28v=VS.85%29.aspx

8 position axis, 8 velocity axis, 8 acceleration axis, 8 force axis all LONGs
DIJOYSTATE2 is like having 4 simultaneous DIJOYSTATE Structures!
(too long to post the structure here!)

I just don't see how Direct Input would be considered legacy? I'd much rather have 65536 levels of input per direction than merely 256 levels of input per direction, and 8 axis.
Hypersonic
 
Posts: 125
Joined: Mon Jul 12, 2010 5:58 pm

analog triggers

Postby Hypersonic » Tue Jul 12, 2011 1:13 pm

Apparently the triggers BYTE bLeftTrigger; BYTE bRightTrigger;
are like one directional axis, that work independently of each other.

Perhaps if an emulation mode were made, one side of axis Joystick Z could be mapped to bLeftTrigger, and one side of Joystick Rz to bRightTrigger. Some games may use these triggers for car accelerators and brakes, for example.

Or perhaps use the whole axis for a trigger, and have it act as a slider for the trigger. So you don't have to continuously press it to keep the gas down while driving. Press the axis down would be like putting more pressure on the trigger, pressing up would be like putting less pressure on the trigger.

In some cases both triggers could be put on opposite sides of the same axis (like accel and brake), although it would make scenarios like pressing the brake while revving the engine impossible.
Hypersonic
 
Posts: 125
Joined: Mon Jul 12, 2010 5:58 pm

correcting faulty math

Postby Hypersonic » Wed Jul 13, 2011 9:59 am

Correcting faulty math (sorry for the extra reply, I'd just use edit if available)

I incorrectly split the number of bits in half for each side of an axis, but the actual number is much greater than this.

Dinput
4bytes or 32bits, take away one bit to signify the direction, so 31bits, which equates to 2,147,483,647 levels (in decimal) per direction. Now that's future proof!

Xinput
2bytes or 16bits, take away one bit to signify direction, so 15bits, which equates to 32,767 levels (in decimal) per direction. Not bad, but not future proof (perhaps one day controllers could exceed this many levels of input!)

However, it should allow more axis than it currently does.
Hypersonic
 
Posts: 125
Joined: Mon Jul 12, 2010 5:58 pm


Return to 3DxWare 10 Beta Forum

Who is online

Users browsing this forum: No registered users and 4 guests