<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Clearing a queue except fro mouse clicks</title>
		<link>http://www.allegro.cc/forums/view/617303</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 08 Mar 2018 20:47:42 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The program I writing is lagging a little and seemed to be ignoring mouse input. Right now I&#39;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.</p><p>I&#39;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.</p><p>my logic looks like this now 
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_is_event_queue_empty"><span class="a">al_is_event_queue_empty</span></a><span class="k2">(</span>mouseQueue<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span> <span class="k1">return</span><span class="k2">(</span><span class="n">0</span><span class="k2">)</span><span class="k2">;</span> <span class="k2">}</span>
<span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_next_event"><span class="a">al_get_next_event</span></a><span class="k2">(</span>mouseQueue, <span class="k3">&amp;</span>master_event<span class="k2">)</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="k1">if</span> <span class="k2">(</span>master_event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_MOUSE_BUTTON_DOWN<span class="k2">)</span>
  <span class="k2">{</span>
  <span class="c">//...button down stuff goes here</span>
  <span class="k2">}</span>
  <span class="k1">if</span> <span class="k2">(</span>master_event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_MOUSE_BUTTON_UP<span class="k2">)</span>
  <span class="k2">{</span>
  <span class="c">//...button up stuff goes here</span>
  <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

maybe something like peek_next_event() and drop events in a while loop? I&#39;m not quite sure how to architecture this. Maybe like this?</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_peek_next_event"><span class="a">al_peek_next_event</span></a><span class="k2">(</span>mouseQueue, <span class="k3">&amp;</span>master_event<span class="k2">)</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="k1">while</span><span class="k2">(</span>master_event.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_MOUSE_AXES<span class="k2">)</span>
  <span class="k2">{</span>
    <a href="http://www.allegro.cc/manual/al_drop_next_event"><span class="a">al_drop_next_event</span></a><span class="k2">(</span>mouseQueue<span class="k2">)</span><span class="k2">;</span>
  <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

I&#39;m pretty sure this will hang on the while() loop
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nshade)</author>
		<pubDate>Wed, 07 Mar 2018 21:05:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This will filter all ALLEGRO_EVENT_MOUSE_AXES events from a queue. Just use getNextEvent instead of al_get_next_event.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">bool</span> getNextEvent<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> q , <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a><span class="k3">*</span> ev<span class="k2">)</span> <span class="k2">{</span>
   <span class="k1">if</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_next_event"><span class="a">al_get_next_event</span></a><span class="k2">(</span>q , <span class="k3">&amp;</span>ev<span class="k2">)</span> <span class="k3">&amp;</span><span class="k3">&amp;</span> ev-&gt;type <span class="k3">!</span><span class="k3">=</span> ALLEGRO_EVENT_MOUSE_AXES<span class="k2">)</span> <span class="k2">{</span>
      <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span>
   <span class="k2">}</span>
   <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

</p><div class="source-code snippet"><div class="inner"><pre>   <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> ev<span class="k2">;</span>
   <span class="k1">if</span> <span class="k2">(</span>getNextEvent<span class="k2">(</span>q , <span class="k3">&amp;</span>ev<span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
      <span class="c">// do something</span>
   <span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 08 Mar 2018 02:19:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>&quot;move 10 pixels left then click&quot; is not the same as &quot;click here then move 10 pixels left&quot;, 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.</p><p>If you want to &quot;combine&quot; several ALLEGRO_EVENT_MOUSE_AXES events into one, when you process one of them, you can use <span class="source-code"><a href="http://www.allegro.cc/manual/al_peek_next_event"><span class="a">al_peek_next_event</span></a><span class="k2">(</span><span class="k2">)</span></span> to get a look at the next event in the queue, and if it is of the same type, get the data, and then <span class="source-code"><a href="http://www.allegro.cc/manual/al_drop_next_event"><span class="a">al_drop_next_event</span></a><span class="k2">(</span><span class="k2">)</span></span> to remove it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 08 Mar 2018 15:15:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Because I&#39;m porting a DOS program, I&#39;m kind of at the mercy of what the game expects. I was able to purge with a peek/drop while loop.</p><p>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&#39;m sort of emulating how the old INT 33h (subfunction 5) interrupt did things. That&#39;s why I&#39;m mixing the queue/state functions
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (nshade)</author>
		<pubDate>Thu, 08 Mar 2018 20:47:42 +0000</pubDate>
	</item>
</rss>
