<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Generating timer event</title>
		<link>http://www.allegro.cc/forums/view/609714</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 08 Mar 2012 17:50:35 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi, I wanted to know, whether there&#39;s a way to generate timer event on my own. The thing is that I have something like:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">while</span> <span class="k2">(</span>ti-&gt;run<span class="k2">)</span><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>queue, <span class="k3">&amp;</span>ev<span class="k2">)</span><span class="k2">;</span>
  <span class="k1">if</span> <span class="k2">(</span>ti-&gt;run<span class="c">/* &amp;&amp; (!*(ti-&gt;suspended))*/</span><span class="k2">)</span><span class="k2">{</span>
    <span class="k1">if</span> <span class="k2">(</span>ti-&gt;updater-&gt;update<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k3">*</span><span class="k2">(</span>ti-&gt;refresh<span class="k2">)</span> <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
  <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>

This code runs in separate thread. Now when I need to close the application, I just set ti-&gt;run to false and wait for the thread to exit (actually it is Win32 thread, I do not use allegro wrapper for this one, but I don&#39;t think that matters). The point is, that in the worst case I have to wait for the whole timer interval till the thread closes (because of it waiting for the event). So after setting ti-&gt;run from sepparate thread, I would also like to escape the al_wait_for_event (by generating the event on my own for example...). Now I suppose I could create my own event type (somehow - I know Allegro supports it but I haven&#39;t found out any tutorial on that...), but I really do not want to compliate things, so fireing the timer event on my own would suffice.</p><p>Thanks
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (APrince)</author>
		<pubDate>Thu, 08 Mar 2012 05:37:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I doubt Allegro provides such a feature. I&#39;d just use a user event, they are easy enough (see ex_user_events for more ideas). Just create your own source, register it and fire off a user event:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_SOURCE"><span class="a">ALLEGRO_EVENT_SOURCE</span></a> my_source<span class="k2">;</span>
<span class="number">  2</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>my_source<span class="k2">)</span><span class="k2">;</span>
<span class="number">  3</span>
<span class="number">  4</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a><span class="k3">*</span> 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>
<span class="number">  5</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, <span class="k3">&amp;</span>my_source<span class="k2">)</span><span class="k2">;</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="p">#define EVENT_QUIT ALLEGRO_GET_EVENT_TYPE('q', 'u', 'i', 't')</span>
<span class="number">  8</span>
<span class="number">  9</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> my_event<span class="k2">;</span>
<span class="number"> 10</span>my_event.user.type <span class="k3">=</span> EVENT_QUIT<span class="k2">;</span>
<span class="number"> 11</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>my_source, <span class="k3">&amp;</span>my_event, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>
<span class="number"> 13</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> event<span class="k2">;</span>
<span class="number"> 14</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>queue, <span class="k3">&amp;</span>event<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>
<span class="number"> 16</span><a href="http://www.allegro.cc/manual/al_destroy_user_event_source"><span class="a">al_destroy_user_event_source</span></a><span class="k2">(</span><span class="k3">&amp;</span>my_source<span class="k2">)</span><span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 08 Mar 2012 06:48:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>OK, I&#39;ll try that out...<br />Thanks.</p><p>//edit: Works perfectly!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (APrince)</author>
		<pubDate>Thu, 08 Mar 2012 17:50:35 +0000</pubDate>
	</item>
</rss>
