I'm currently trying to make a simulation with a few variables that I should be able to change while the program is running. To do that, I made a slider class that can be controlled trough the mouse, whereas my character is controlled trough the arrow keys. Here's some code(cut out the non-important stuff):
Now the problem I'm having is that this LAGS... When I move the mouse and then press a key, my player starts to move two/three seconds later 
Any ideas?
You should probably process all existing events before doing a redraw, probably using al_peek_next_event
I thought I'd seen this on the wiki... I'm a dumb ass...
Added this:
if(redraw && al_event_queue_is_empty(event_queue))
And it worked like a charm ^^
I wonder if a better model is to make a new event source that comes from a timer so you redraw only when a new tick comes by.
In your current model if there are a billion events in the queue you won't see the screen updated for a while.
Well, processing a billion events hopefully takes little time compared to doing game logic and redrawing so it should be fine.
I haven't put it in my example, but I already have a timer to have the player update its position... I would want another timer for the drawing, but I don't know how to distinguish between them... there's only one ALLEGRO_EVENT_TIMER
You need to use timer.source (ALLEGRO_TIMER *)
no wait... let me think, I already did that, but I can't remember it .. dammit!
I don't know how to distinguish between them...
Use the source field from the ALLEGRO_EVENT struct.
Now I can remember, this is what I did:
You can't just check the event fields like that. You have to make sure the event is the correct type before you read the event type specific fields. Otherwise you are reading garbage produced by the event union.
al_wait_for_event(event_queue , &ev); if (ev.type == ALLEGRO_EVENT_TIMER) { if (ev.timer.source == LPS) { // LOGIC } }
Oh I didn't know that, Thanks man.
For common fields it doesn't actually matter whether you do this or not (in fact, you access event.any.source instead). But it's probably good practice to do it as indicated.
Thanks to all