Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How do I completely skip Mouse Axes events?

This thread is locked; no one can reply to it. rss feed Print
How do I completely skip Mouse Axes events?
AleaInfinitus
Member #18,873
December 2020

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:

#SelectExpand
1skip: 2al_wait_for_event(queue, &event); 3 4if(event.type == ALLEGRO_EVENT_MOUSE_AXES) { 5 goto skip; 6}

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?

GullRaDriel
Member #3,861
September 2003
avatar

You should get the events as fast as possible and base your logic / drawing loops on timer events, not on mouse events.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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));
   }

AleaInfinitus
Member #18,873
December 2020

My current loop layout looks like:

#SelectExpand
1while(1) { 2 al_wait_for_event(queue, &event); 3 4 switch(event.type) { 5 //buttons, clicks, etc. 6 } 7 8 sim_logic(); 9 10 if(redraw) { 11 //rendering 12 }

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.

Dizzy Egg
Member #10,824
March 2009
avatar

Put your sim logic in the switch case, under the timer event case...

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

RmBeer2
Member #16,660
April 2017
avatar

Anyone works, you just take the event and ignore it.

🌈🌈🌈 🌟 BlackRook WebSite 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈

Rm Beer for Emperor 2021!

Go to: