<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>I do not quite understand the custom events mentioned in the user manual</title>
		<link>http://www.allegro.cc/forums/view/617265</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 08 Feb 2018 11:03:34 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello.</p><p>My English is very bad that I can not understand some of the content on the manual. <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> <br />For example, user-defined queue, which is doing?</p><p>Another question is: If I have a lot of rendering animation, how do I submit them to the queue.</p><p>Although I try to use some machine translation, but apparently not enough.  <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /> </p><p>I need people to help me, can you help me?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (keprast)</author>
		<pubDate>Mon, 05 Feb 2018 16:13:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>User events in Allegro 5 aren&#39;t too hard.</p><p>First, you need an event source :
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_SOURCE"><span class="a">ALLEGRO_EVENT_SOURCE</span></a> evsrc<span class="k2">;</span>
<a href="http://www.allegro.cc/manual/al_init_user_event_source"><span class="a">al_init_user_event_source</span></a><span class="k2">(</span><span class="k3">&amp;</span>evsrc<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Then you need to register it with an event queue :
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>event_queue , <span class="k3">&amp;</span>evsrc<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Then when you want to emit an event, you fill in the data fields of an ALLEGRO_EVENT and use the event source to emit that event :
</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> my_event<span class="k2">;</span>
my_event.type <span class="k3">=</span> <a href="http://www.allegro.cc/manual/AL_ID"><span class="a">AL_ID</span></a><span class="k2">(</span><span class="s">'M'</span> , <span class="s">'I'</span> , <span class="s">'N'</span> , <span class="s">'E'</span><span class="k2">)</span><span class="k2">;</span>
my_event.data.user1 <span class="k3">=</span> <span class="k2">(</span>intptr_t<span class="k2">)</span>some_data_address<span class="k2">;</span><span class="c">/// Pass whatever custom data you want here</span>

<a href="http://www.allegro.cc/manual/al_emit_user_event"><span class="a">al_emit_user_event</span></a><span class="k2">(</span><span class="k3">&amp;</span>evsrc , <span class="k3">&amp;</span>my_event , <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Then during your event loop, you check for events from that source :
</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>
<a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span>q , <span class="k3">&amp;</span>ev<span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span> <span class="k2">(</span>ev.source <span class="k3">=</span><span class="k3">=</span> <span class="k3">&amp;</span>evsrc<span class="k2">)</span> <span class="k2">{</span>
   <span class="c">/// We got an event from our event source</span>
   <span class="k1">if</span> <span class="k2">(</span>ev.type <span class="k3">=</span><span class="k3">=</span> <a href="http://www.allegro.cc/manual/AL_ID"><span class="a">AL_ID</span></a><span class="k2">(</span><span class="s">'M'</span> , <span class="s">'I'</span> , <span class="s">'N'</span> , <span class="s">'E'</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
      <span class="c">/// We got an event of type MINE from evsrc</span>
      DoStuff<span class="k2">(</span>ev.data.user1<span class="k2">)</span><span class="k2">;</span>
   <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 05 Feb 2018 17:19:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>In case the Allegro functions themselves are not clear :
</p><div class="source-code snippet"><div class="inner"><pre>   <span class="c">// This allocates memory for one queue. It is empty.</span>
   event_queue <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_event_queue"><span class="a">al_create_event_queue</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p><div class="source-code snippet"><div class="inner"><pre>   <span class="c">// This tells Allegro to post keyboard events in this queue, every time the user uses the keyboard.</span>
   <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>event_queue, <a href="http://www.allegro.cc/manual/al_get_keyboard_event_source"><span class="a">al_get_keyboard_event_source</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p><div class="source-code snippet"><div class="inner"><pre>   <span class="c">// This tells Allegro to post mouse events in this queue, every time the user uses the mouse.</span>
   <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>queue, <a href="http://www.allegro.cc/manual/al_get_mouse_event_source"><span class="a">al_get_mouse_event_source</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Generally, you want to use one queue for everything. This way, when you look in the queue, you get events in the correct order : &quot;First the user pressed A, then he moved the mouse...&quot;</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/617265/1035110#target">keprast</a> said:</div><div class="quote"><p> Another question is: If I have a lot of rendering animation, how do I submit them to the queue.
</p></div></div><p>Normally, you separate in two functions :<br />LOGIC (game logic) :<br />- runs 60 times per second (for example)<br />- takes user input into account<br />- takes all decisions<br />- performs &quot;physics&quot; : Every execution of the function models what happens in 1/60 second<br />- selects the current image of animations (ex : Run loop, images 1 2 3 4 1 2 3 4...). The information needs to be stored in memory, not drawn.<br />- is the one that creates and deletes game elements (bullets,...)<br />- can start sound effects</p><p>DRAWING<br />- only needed after a logic step has run<br />- can be done after several logic steps if the computer is too slow (it is called frame skipping)<br />- only places graphic elements on the screen</p><p>When you have this separation, all the code in logic is fast. You can then use a timer event at 1/60s to run logic, and every time the event queue is empty, you can call the draw function to update the screen.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Mon, 05 Feb 2018 20:15:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>THANKS!<br />Belated thanks. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> </p><p>Some things make me unable to appear for some time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (keprast)</author>
		<pubDate>Wed, 07 Feb 2018 09:20:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I agree though even as a 1st language English user, that the docs are really confusing on that subject and I almost always have to re-lookup my old code, or grep though examples, to find the answer on how to do custom events, as well as &quot;multiple events of the same time in one queue&quot; (telling them apart).</p><p>Who is up for making an Allegro 5/A.CC FAQ? If you could come up with Q&#39;s, I&#39;ll start preparing either a Wiki or YouTube walkthrough of the answers...</p><p>I&#39;m trying to get disciplined again (::boo:: health problems) and maybe forcing myself to do one a week could help me be more productive...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Wed, 07 Feb 2018 12:08:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There&#39;s this</p><p><a href="https://wiki.allegro.cc/index.php?title=FAQ">https://wiki.allegro.cc/index.php?title=FAQ</a></p><p>and I thought there was another one... but no, I was thinking of something else.</p><div class="spoiler"><p><a href="https://www.allegro.cc/members/gideon.weems">https://www.allegro.cc/members/gideon.weems</a><span class="ref"><sup>[<a href="#">1</a>]</sup></span></p></div><p>

Alas, Tomasu is on vacation or was and doesn&#39;t have much time for the wiki anymore. I lost a bunch of pages and have been banned by his spam killers multiple times now and I lost my motivation.
</p><div class="ref-block"><h2>References</h2><ol><li>Hall of Fame</li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 07 Feb 2018 12:41:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If the manual is unclear, please do make a pull request on github with a suggestion for improvement, perhaps with examples. That should be more useful than a separate FAQ.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Thu, 08 Feb 2018 11:03:34 +0000</pubDate>
	</item>
</rss>
