Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joystick lag #1026

arganoid opened this Issue Feb 24, 2019 · 1 comment


None yet
2 participants
Copy link

arganoid commented Feb 24, 2019

The following problems are exhibited in both the example joystick programs, as well as my own code.

I have three controllers. One exhibits no problems. With two of them, there are frequent random delays in input changes (axes and button presses) being recognised – delays of about half a second. I will write more about the fourth controller later. I have tested all the controllers with Windows 10's "Set up USB game controllers", and they all respond immediately with no lag. They all also work fine in Allegro 4. I have not yet found another game which exhibits the delay.

The only controller which operates with no lag 100% of the time is this:
It's a clone of the Xbox 360 controller and uses the Xbox 360 driver. In the Game Controllers control panel, it is listed as "Controller (Inno GamePad..)". In my test game, the name is reported as "XInput Joystick".

The second controller, which does have the random lag, is this:
The brand name shown on Amazon is CSL. It is listed in Device Manager as "USB Input Device". In the game controllers control panel, and in my test game, it is listed as "USB Joystick".

The third controller, which also has the lag, is:
The brand name is Kabalo. As with the device above, the names in Device Manager and Game Controllers/test game are "USB Input Device" and "USB Joystick".

I did some investigation and found a connection with joydx_scan. Changing the frequency by which joysticks are re-scanned changes the interval between each incident of lag. I did some profiling and found that IDirectInput8_EnumDevices always takes about 0.4 seconds (regardless of which controller is attached). If I unplug my keyboard, mouse and graphics tablet, that number drops to about 0.2s, and the lag seems noticeably better. But this doesn't explain why the XInput controller shows no lag at all. On a different PC, which doesn't show the lag issue, that number is around 0.03s.

I have confirmed that the time taken by IDirectInput8_EnumDevices is not due to any code in joystick_enum_callback. Each controller returns from that function near the top (either in the 'Filtered out XInput device' block or the 'Device still exists' block.

I have three questions:

  1. Does anyone know why this happens and it could be fixed?

  2. If not, could there be an option to rescan controllers on demand, rather than automatically?

  3. A supplementary question, not directly related to this specific issue but still to do with the performance of recognising and processing controllers. Does anyone have any idea what would be the performance impact of raising MAX_CONTROLLERS to a much higher number and playing a game with that many controllers attached? When I say a much higher number, I'm thinking 30, 50, even 100.


This comment has been minimized.

Copy link

beoran commented Feb 25, 2019

Allegro 5 uses a different driver for XInput joysticks on Windows. That is why you don't get any lag for the XInput joystick. I happen to have written that driver ;) Unfortunately I can't help you with problems in the DirectX driver since I don't know that one too well...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.