I'm making a circuit simulator, but I'm running into an issue with oscillator inconsistency. When the mouse is left alone, the oscillator is fairly stable, but when moving the mouse, Allegro starts pushing a bunch of Mouse Axes events into the event queue and causing the "speed" of the simulation to go way up.
This seems to completely destabilize the sim (for reasons beyond my understanding). Thus I tried skipping mouse axes events via:
Checking for mouse axes events in the while loop did show that none were getting through, but the simulation was still speeding up. Anyone know why?
You should get the events as fast as possible and base your logic / drawing loops on timer events, not on mouse events.
Here is a basic loop :
while (!quit) { if (redraw) { //... al_flip_display(); redraw = false; } do { ALLEGRO_EVENT ev; al_wait_for_event(queue , &ev); if (ev.type == EAGLE_EVENT_MOUSE_AXES) {continue;} } while (!al_is_event_queue_empty(queue)); }
My current loop layout looks like:
My sim logic is outside of the event switch, so I don't really know how else to make it rely on the timer exclusively, but I'll try Edgar's design.
Put your sim logic in the switch case, under the timer event case...
Anyone works, you just take the event and ignore it.