I'm testing Allegro 5 joystick code using three controllers. With two of them, there are frequently random delays in input changes being recognised – delays of up to about a second. The other works flawlessly all the time. I have tested them with Windows 10's "set up USB game controllers" , and they all respond immediately with no lag.
Here's the relevant part of my code:
while (al_get_next_event(eventQueue, &e))
for(auto& a : actors)
if (e.joystick.id == a->joy)
a->vel.x = js.stick.axis * 100;
a->vel.y = js.stick.axis * 100;
What does the rest of your event loop look like?
Like this, with the code above inside Advance.
float deltaTime = m_timingManager->GetDeltaTime();
So, you're loping forever as long as there are new joystick events, then rendering. As long as the joystick is held down, you're going to get new events. Maybe just look for 1 event of each type.
This isn't a case of getting stuck in the event loop, because when this lag problem occurs, the rest of the game carries on running normally. I can also see that if I output the number of events per frame, events only occur when the stick position has changed.
The joystick state is not guaranteed to be current. If an event has occurred since the state was asked for, then it is no longer current. Use the event fields in the ALLEGRO_EVENT_JOYSTICK_AXIS event.
Code now looks like this, but the lag is still there (always with the same two controllers, and not the other).
for(auto& a : actors)
if (e.joystick.id == a->joy)
case 0: a->vel.x = e.joystick.pos * 100; break;
case 1: a->vel.y = e.joystick.pos * 100; break;
The problem does not occur with Allegro 4.
I'm a bit high and all that, and not really a master when it comes to allegro5 events, but it's not a mutex/re-entry thing with the auto for loop is it? Do things improve if you do this?
ALLEGRO_JOYSTICK_STATE js; al_get_joystick_state(actor[e.joystick.id].joy, &js); actor[e.joystick.id].vel.x = js.stick.axis * 100; actor[e.joystick.id].vel.y = js.stick.axis * 100; }
or somehing similar....etc
Please post the specific type of joysticks that you are using. Brand, model, etc...
Also, are you seeing delays in axis reporting or button presses or what?
The lag occurs with both axis movement and button presses.
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 same 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". The controller has an 'ANALOG' button - with this disabled, analog stick input is received as digital input. The state of the ANALOG button makes no difference to the lag issue.
The last controller is where things get even weirder. It's a genuine PS4 controller, connected via USB and operating via DS4Windows. In my test game, this is recognised as two separate controllers, named "XInput Joystick" and "Wireless Controller". The left analog stick controls two players. The former does not exhibit the lag issue, although does have an issue with the player position creeping a small amount when the stick is supposedly centred. The latter does exhibit the lag issue, but does not have the same issue when the stick is centred. In the Game Controllers control panel, it is listed under both "Controller (Xbox 360 for Windows)" and "Wireless Controller".
It's interesting to note that the two controllers which don't exhibit the lag issue are both reported by Allegro as being named "XInput Joystick". The second and third controllers appear to only support DirectInput, so I was going to suggest that it's an issue with DirectInput. Regarding the PS4 controller, I wondered if the it was being recognised both as an XInput and DirectInput controller. But it also shows up twice in a separate game controller tester application which only supports XInput controllers. And finally, in an Allegro 4 game, the PS4 controller is also recognised as two controllers. As in my Allegro 5 test app, the left stick controls two players once – the only difference being that each player recognises a different bus and as being button 1.
I suggest filing a bug report on the issue tracker on github here :
I can't really help much. I have a joystick I can try with allegro and see what it does.
Can you post code for a simple program that I can compile and test that exhibits the issue described?
beoran is our local joystick guru wonder if he's hanging about somewhere.
Try ex_joystick_events and see if it works for those sticks.
The lag issue also happens with both of the joystick example programs. I will file a report on Github.
The issue with the PS4 controller being recognised as two controllers has been resolved by closing the DS4Windows application.
UPDATE: The problem does not occur with my two other PCs. All PCs are on Windows 10.
UPDATE: Issue opened here: https://github.com/liballeg/allegro5/issues/1026
I did some investigation and found some possible leads.