Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Clearing a queue except fro mouse clicks

This thread is locked; no one can reply to it. rss feed Print
Clearing a queue except fro mouse clicks
nshade
Member #4,372
February 2004

The program I writing is lagging a little and seemed to be ignoring mouse input. Right now I'm only collecting input every half second (This will be fixed later). The issue is my mouse queue is being flooded with ALLEGRO_EVENT_MOUSE_AXES (event type 20) and my program is processing those before it get to any mouse clicks, which is the actual data I need.

I'm trying to figure out a way to purge all the events that are ALLEGRO_EVENT_MOUSE_AXES until hits a mouse button event or until the queue is empty.

my logic looks like this now

if (al_is_event_queue_empty(mouseQueue)) { return(0); }
if (al_get_next_event(mouseQueue, &master_event))
{
  if (master_event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
  {
  //...button down stuff goes here
  }
  if (master_event.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
  {
  //...button up stuff goes here
  }
}

maybe something like peek_next_event() and drop events in a while loop? I'm not quite sure how to architecture this. Maybe like this?

if (al_peek_next_event(mouseQueue, &master_event))
{
  while(master_event.type == ALLEGRO_EVENT_MOUSE_AXES)
  {
    al_drop_next_event(mouseQueue);
  }
}

I'm pretty sure this will hang on the while() loop

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

This will filter all ALLEGRO_EVENT_MOUSE_AXES events from a queue. Just use getNextEvent instead of al_get_next_event.

bool getNextEvent(ALLEGRO_EVENT_QUEUE* q , ALLEGRO_EVENT* ev) {
   if (al_get_next_event(q , &ev) && ev->type != ALLEGRO_EVENT_MOUSE_AXES) {
      return true;
   }
   return false;
}

   ALLEGRO_EVENT ev;
   if (getNextEvent(q , &ev)) {
      // do something
   }

Audric
Member #907
January 2001

"move 10 pixels left then click" is not the same as "click here then move 10 pixels left", so even if you later check the queue more frequently, your program will be more accurate if it can process the events instead of discarding them.

If you want to "combine" several ALLEGRO_EVENT_MOUSE_AXES events into one, when you process one of them, you can use al_peek_next_event() to get a look at the next event in the queue, and if it is of the same type, get the data, and then al_drop_next_event() to remove it.

nshade
Member #4,372
February 2004

Because I'm porting a DOS program, I'm kind of at the mercy of what the game expects. I was able to purge with a peek/drop while loop.

when the mouse click is read from the queue, the game will then ask for the mouse state with al_get_mouse_state() to get the X and Y position at that point. I'm sort of emulating how the old INT 33h (subfunction 5) interrupt did things. That's why I'm mixing the queue/state functions

Go to: