The input response for
if (events.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN)
{
printf("Button was pressed\n");
}
else if (events.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_UP)
{
printf("Button was released\n");
}
is really bad. Sometimes it even skips that the button was released. It improved when I used al_wait_for_event(event_queue, &events);
but there are still skips when the buttons are pressed when I press the buttons too fast. Even when I press them at slow intervals it sometimes skips Button was released. I am using ALLEGRO_5.22 and have it installed using Microsoft visual studio 2015. Keyboard responses are immediate and analog response are immediate with controllers. It is just the buttons that are the issue
Please post a full program so we can better help you.
Here is a quick program I threw together to test joystick button inputs:
I'm experiencing no latency from the above. I'm curious to know what you experience when you try out the above. It could be that your controller or the adapter used with it is bad.
That sample code you posted does not have any delays at all! (Thank you for that) I'll look to see where I went wrong but I still can't find anything and I don't understand why this is still happening. Here is my code that I am using
We likely need to see the code for _input to understand what's going on here.. I don't see anything with the Allegro code that would explain this.
Append:
Correction. I wonder if repeatedly calling al_get_joystick_state every event is the culprit. I'm not familiar with the joystick API, but since that isn't event-based I bet you're using the slow method to get that data and I wouldn't be surprised if that was lagging you.
I'm glad my example worked for you. As for your code, nothing immediately jumps out at, though I'm not too sure about your use of al_get_joystick_state. I'm not too well-versed on the joystick API though, and I'm not sure what you're doing inside of the Input class either.
Why are you calling al_get_joystick_state every cycle? Try moving it just before the while-loop and see if that changes anything.
I am calling al_get_joystick_state to determine which controller is making the input but I plan on removing it because I could just use events.joystick.id to determine which controller made that action but here is the code for the input class. I did comment it out to see if that made the difference but it did not.
I have just found the problem. It is the re-sync-controller function call. Since that was the other thing that stuck out that was different with the working code. When I comment it out their is no longer any delay.
Probably you should check first if Allegro sends any events when "joysticks" / "controllers" are plugged in or unplugged. If so then you'll know more accurately when you should try to re-detect them. Worst case, limit your polls to every few seconds. That will be hundreds of frames probably and you can probably afford a bit of waste if you only do it so often. Again, that's without any knowledge of Allegro's joystick/controller APIs. But I would bank on there being events to do this most efficiently.
Append:
The documentation for al_reconfigure_joysticks says Allegro will send an event when devices change and only then should you call al_reconfigure_joysticks(). Calling it every loop is probably super inefficient because Allegro is probably doing lots of unnecessary work to figure out what changed when nothing has.
Your absolutely right I just looked at the api and found ALLEGRO_EVENT_JOYSTICK_CONFIGURATION which lets me know if a controller has been disconected or reconnected. That is when I should call al_reconfigure_joystick instead of calling it all the time like I did.
Thank you all so much!!!