I'm getting very inconsistent results when using allegro to get joystick inputs. Even the precompiled example program ex_joystick_events.exe demonstrates the problem. In my test programs the keyboard and mouse inputs are all very responsive and work well but the joystick is often slow. I'm using a dinput logitech controller for testing and have verified it across vista and win 7 and Allegro 5.0.4 and 5.1.8 . It works with other games and furthermore I have used joy2key to turn the joystick inputs into keyboard inputs and that eliminates the lag because allegro is processing the keyboard inputs properly. The hardware is fine.
What I have found through testing is that the joystick events are not being noticed when they happen. The delay can be in the dozens of mS to the point where it skips several frames. If the down press is delayed by a lot, and the release not very much, then they can even appear to occur with no delay. It seems like they're getting stuck in the queue even though the keyboard and mice inputs use the same format and queue but have no problems.
Am I missing something about how to handle joystick inputs? As I said the example code ex_joystick_events.exe shows this symptom. Here is a half baked demo I put together to better visualize and time it. Removing the cout portions doesn't make any difference. The keyboard arrow movements are crisp and responsive while the joystick inputs are laggy and even appear to drop altogether when the delay is really bad. For reference you can use the arrow keys and d-pad to move the block. Only moving right will display the timer number.
I don't suppose installing the joystick before creating the timer helps?
Moved both the al_install_joystick and al_register_event_source(event_queue, al_get_joystick_event_source()) above the timer creation. No change.
However, I did realize that I'm an idiot because I tested it on two vista machines. Had forgot which laptop was which. Whenever I realized this and switched over to the windows 7 laptop all the joystick functions work properly. No lag, no problem with queues, just as responsive as the keyboard and mouse. The allegro provided examples, my test code, and my game all work fine on win7.
So now I'm scratching my head about why it works with win7 but not 2 vista machines. The controller works correctly with all the games I've played on the vista computers, just not with allegro. It's a logitech dual action G-UF13A that is dinput only. Might be some weird conflict between an old OS, old controller, and allegro. I just ordered one of the newer logitech controllers that can toggle between x and d inputs to see if I can replicate the problem with a different controller and also x input mode.
In the meantime if anybody has a vista machine I'd be curious if they could replicate the problem. You can use my code or the ex_joystick_events allegro sample. I see inconsistent, delayed inputs in both.
This might be a problem in how Allegro handles dinput joysticks on vista, since I only tested the Windows joystick driver code on a virtualized Windows 7 when I developed it. If you have the time to do so, it would help us greatly if you could help debug this. XInput controllers use a different "driver" and so should not be affected.
Sure. I'm not really familiar with Allegro development so I might need some help on that end. Let me know what info you need to get started.
Hmmm, is there any way you could profile your program to see if it doesn't spend too much time in directinput or in allegro's joystick routines? It's easier for me to explain Allegro then to explain how I would debug such a problem.
Have you got any compiler optimisations turned on??
EDIT: also I noticed in your conditions if the axis is 0.9 then both conditions are me, because you use >= 0.9 and <= 0.9 - your condition to set the movement to false should be < 0.9
Beoran - I'll get on that, but I'll be traveling for most of the week so not sure when I'll work on it.
Dizzy - That code is probably a mess in terms of logic and actually doing things. I just threw in some random stuff from other examples, cut out parts, and tested to get a feel for the timing.
Also it is not related to the compiler because even the precompiled example exes that come with some Allegro binaries exhibit the problem. I just frankencoded this to better visualize and understand the problem.
Cool....also when you set left/right to true, set the other to false!