<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Multiple timers in Allegro 5</title>
		<link>http://www.allegro.cc/forums/view/617209</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 16 Jan 2018 23:28:38 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey guys,</p><p>First I want to say, that I already posted my question on Stackoverflow. So I will link to it, so that I don&#39;t have to write novels here. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> But to describe my problem, here some introducing words.</p><p>I watched multiple tutorials about using multiple timers in Allegro, but that way of programming doesn&#39;t work for me. The problem is that the source adress never matches to the timer adress i want to watch.</p><p>I use multiple classes/instances to encapsulate my code, because it will be very complex in the future. The main loop of my game is located in the Game class/instance. The timers and the events are encapsulated in an Engine class/instance, that is a member of the Game instance.</p><p>You can see the code by following the link to my Stackoverflow-question.</p><p>Thanks in advance for your help <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p><a href="https://stackoverflow.com/questions/47993289/using-multiple-timers-in-allegro-5">https://stackoverflow.com/questions/47993289/using-multiple-timers-in-allegro-5</a></p><p>P.S.: If this linking is not welcome here, i can recreate my thread.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BanditBloodwyn)</author>
		<pubDate>Mon, 08 Jan 2018 12:59:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Actually, I had this problem before. I did this to tell timers apart:</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>
<span class="number">  2</span><a href="http://www.allegro.cc/manual/ALLEGRO_TIMER"><span class="a">ALLEGRO_TIMER</span></a> <span class="k3">*</span>fps_timer<span class="k2">;</span>
<span class="number">  3</span><a href="http://www.allegro.cc/manual/ALLEGRO_TIMER"><span class="a">ALLEGRO_TIMER</span></a> <span class="k3">*</span>other_timer<span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="c">//...</span>
<span class="number">  6</span>  <span class="k1">while</span><span class="k2">(</span><span class="k3">!</span>time_to_exit <span class="k2">)</span>
<span class="number">  7</span>    <span class="k2">{</span>
<span class="number">  8</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> ev<span class="k2">;</span>
<span class="number">  9</span>  
<span class="number"> 10</span>    <span class="k1">if</span><span class="k2">(</span><span class="k3">!</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>queue<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 11</span>      <span class="k2">{</span>
<span class="number"> 12</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>queue, <span class="k3">&amp;</span>ev<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span><span class="c">// important part:</span>
<span class="number"> 15</span><span class="k1">if</span><span class="k2">(</span>ev.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_TIMER<span class="k2">)</span> 
<span class="number"> 16</span>    <span class="k2">{</span>
<span class="number"> 17</span>    <span class="k1">if</span><span class="k2">(</span>ev.timer.source <span class="k3">=</span><span class="k3">=</span> fps_timer<span class="k2">)</span><span class="k2">{</span><span class="k2">}</span>
<span class="number"> 18</span>    <span class="k1">if</span><span class="k2">(</span>ev.timer.source <span class="k3">=</span><span class="k3">=</span> other_timer<span class="k2">)</span><span class="k2">{</span><span class="k2">}</span>
<span class="number"> 19</span>    <span class="k2">}</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="c">//end</span>
<span class="number"> 22</span>                         <span class="k2">}</span>
<span class="number"> 23</span>                <span class="k2">}</span>
</div></div><p>

[edit] I didn&#39;t realize your SO post was so long. There may be something else going on...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Mon, 08 Jan 2018 13:05:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks Chris for your quick answer, but yeah, as you see I tried it exactly like you did, but the adresses don&#39;t match and I don&#39;t know why.</p><p>Sorry that my SO question is so long, but I wanted to describe my situation as detailed as possible/necessary
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BanditBloodwyn)</author>
		<pubDate>Mon, 08 Jan 2018 13:20:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t see an evident mistake, but you need to be sure that you have only one instance of Engine. Are there any compilation warnings ? These may point to the real issue.</p><p>You should probably pull LoopTimerEvent off your class : Such piece of data is normally only used inside the function that performs <span class="source-code"><a href="http://www.allegro.cc/manual/al_wait_for_event"><span class="a">al_wait_for_event</span></a><span class="k2">(</span><span class="k2">)</span></span>, and you don&#39;t need it afterwards, so a local variable is fine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Mon, 08 Jan 2018 17:11:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Audric:</p><p>No, I don&#39;t get any compiler warnings and I&#39;m sure I have only one instance of Engine (I will change it to be a singleton to be 110% sure, but it already is unique).</p><p>I will try to solve it by pull out my events to the gameloop itself, whereby I would prefer not to have to do that, because I like to encapsulate elements that belong to each other. But maybe it&#39;s the only way without creating a completely own timer-event-concept.</p><p>Btw: sorry if my English is not the best. I&#39;m not a native speaker <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BanditBloodwyn)</author>
		<pubDate>Mon, 08 Jan 2018 19:09:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t see how a rewrite / reorganization would fix it.</p><p>Wait, maybe the timer event you&#39;re getting is from something else, and you only have to ignore these events when you find them in the queue : maybe a keyboard handler, or music system ?<br />To quickly test, &quot;don&#39;t start&quot; your 3 timers, and see if you still find such events.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Mon, 08 Jan 2018 19:43:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I thought that too, but somehow late last night it didn&#39;t occur to me to just remove the three timers completely and check. Good idea.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Mon, 08 Jan 2018 20:39:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Edit<br />Didn&#39;t read close enough.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><div class="source-code snippet"><div class="inner"><pre>TimerEvent: <span class="n">031A0D80</span> <span class="n">0326AF30</span> <span class="n">0326A380</span> <span class="n">0326B090</span>
</pre></div></div></div></div><p>
The second three addresses look right - they are all close together, like you would expect from a sequential memory assignment. The first ALLEGRO_TIMER* looks like it was allocated from an earlier part of the program.</p><p>Can you post a github link or a zip file?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 08 Jan 2018 23:47:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is Allegro initialized before timers are created and the timer is installed (in a constructor)? Is Allegro init&#39;d twice by accident?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 09 Jan 2018 06:47:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have multiple timers in my Deluxe Pacman 2 game (below) and after I initialize allegro, I call:</p><p><span class="source-code">pacman.timer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_timer"><span class="a">al_create_timer</span></a><span class="k2">(</span><span class="n">1</span>.<span class="n">0f</span> <span class="k3">/</span> pacman.ts<span class="k2">)</span><span class="k2">;</span></span></p><p><span class="source-code">pacman.ts</span> being the speed I want for that timer.  I have a global struct for my main character, Pacman that has <span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_TIMER"><span class="a">ALLEGRO_TIMER</span></a> <span class="k3">*</span>timer<span class="k2">;</span></span></p><p>I do the same for my ghosts and I even have a third redraw timer.  All works well, but then, I program in C, not C++, so no hassles with classes and junk. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>In my events loop I check with <span class="source-code"><span class="k1">if</span><span class="k2">(</span>event.timer.source <span class="k3">=</span><span class="k3">=</span> pacman.timer<span class="k2">)</span> <span class="k2">{</span></span> as usual.  Works just fine.</p><p>Follow your code, put a watch on your timer variables and check when they change.  Maybe do a search for all instances of your timer variables being assigned anything and maybe do a simple console printout of the the line number and what the variable equals when done etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Tue, 09 Jan 2018 11:42:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Guys, you are my heroes! <img src="http://www.allegro.cc/forums/smileys/kiss.gif" alt=":-*" /><img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> I found the mistake:<br />I accidentally initialized the timers instance twice, which created new timers with (of course) different adresses. But in the event queue the OLD ones were registered, because of my stupid organization. I fixed that by putting the queue registration to the InitTimer function and fixed the bug with the double timer initialization.<br />Now everything works perfectly!</p><p>Thanks a lot, my friends <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /><img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /><img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BanditBloodwyn)</author>
		<pubDate>Mon, 15 Jan 2018 23:10:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Awesome!  Glad you got it working.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Tue, 16 Jan 2018 02:42:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>One last question off topic:<br />How was my English? <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (BanditBloodwyn)</author>
		<pubDate>Tue, 16 Jan 2018 09:55:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Good! <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Tue, 16 Jan 2018 19:38:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>How was my English? <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p></div></div><p>

That was English?!?! <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /></p><p>You were fine actually. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Tue, 16 Jan 2018 23:28:38 +0000</pubDate>
	</item>
</rss>
