<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[Allegro] Timer Problem</title>
		<link>http://www.allegro.cc/forums/view/554042</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 21 Dec 2005 17:04:05 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m having a very odd problem. I&#39;m wanting to do a fps check, something very simple, my problem is when I do <span class="source-code"><a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span>fpsControl, SECS_TO_TIMER<span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span>to get 1 tick per second, it just doesn&#39;t work, fpsControl is never called, what&#39;s wrong with this? Is allegro bugged or what? If so, why isn&#39;t it on the manual?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felipe Maia)</author>
		<pubDate>Tue, 20 Dec 2005 00:01:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
fpsControl is never called
</p></div></div><p>
What&#39;s your fpsControl function do?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Tue, 20 Dec 2005 00:05:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Change 2 volatile int variables, it is never called, really, I&#39;ve debugged and it never get&#39;s there, never at least in less than a minute.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felipe Maia)</author>
		<pubDate>Tue, 20 Dec 2005 00:07:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Could you show me a small snippet of your code.  From what I&#39;ve seen so far, it should be working.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Tue, 20 Dec 2005 00:09:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="k1">volatile</span> <span class="k1">int</span> countFPS<span class="k2">;</span></td></tr><tr><td class="number">2</td><td><span class="k1">volatile</span> <span class="k1">int</span> lastFPS<span class="k2">;</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td><span class="k1">void</span> fpsControl<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">5</td><td>  lastFPS <span class="k3">=</span> countFPS<span class="k2">;</span></td></tr><tr><td class="number">6</td><td>  countFPS <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></td></tr><tr><td class="number">7</td><td><span class="k2">}</span></td></tr><tr><td class="number">8</td><td><a href="http://www.allegro.cc/manual/END_OF_FUNCTION" target="_blank"><span class="a">END_OF_FUNCTION</span></a><span class="k2">(</span>fpsControl<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td><span class="k1">void</span> drawFrame<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">11</td><td><span class="c">//draw stuff</span></td></tr><tr><td class="number">12</td><td>  countFPS<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td><span class="k2">}</span></td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td><span class="k1">void</span> init<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">16</td><td>  <a href="http://www.allegro.cc/manual/LOCK_VARIABLE" target="_blank"><span class="a">LOCK_VARIABLE</span></a><span class="k2">(</span>lastFPS<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>  <a href="http://www.allegro.cc/manual/LOCK_VARIABLE" target="_blank"><span class="a">LOCK_VARIABLE</span></a><span class="k2">(</span>countFPS<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>  <a href="http://www.allegro.cc/manual/LOCK_FUNCTION" target="_blank"><span class="a">LOCK_FUNCTION</span></a><span class="k2">(</span>fpsControl<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">19</td><td>  <a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span>fpsControl, SECS_TO_TIMER<span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>That&#39;s all it touches, I think the problem is the library and not the code, I&#39;m gonna recompile everything and see.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felipe Maia)</author>
		<pubDate>Tue, 20 Dec 2005 00:12:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Everything looks good to me.  However, I usually put the LOCK functions after the install_int_ex.  Don&#39;t know if that&#39;d make a difference.  Did recompiling work?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Tue, 20 Dec 2005 00:17:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I need to recompile allegro, delete everything and recompile from scratch, haven&#39;t got the time to do that now since I have to do a lot of things. I&#39;ll let you know when I do so.</p><p>EDIT: No, still not working, I&#39;ve recompiled everything. Something odd happened though, the debug version did not self install and the lib is small than the release one, how is that possible???</p><p>EDIT2: Very very odd: if I do </p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span>fpsControl, BPS_TO_TIMER<span class="k2">(</span><span class="n">80</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p> it works ok, the function beeing called every now and then, but if I do <span class="source-code"><a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span>fpsControl, BPS_TO_TIMER<span class="k2">(</span><span class="n">60</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span> It doesn&#39;t, it get&#39;s very odd.</p><p>EDIT3: I figured it out the problem, finally, the problem was that I was adding the function and then removing and then adding again.<br />something like </p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span>fpsControl, BPS_TO_TIMER<span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/remove_int" target="_blank"><span class="a">remove_int</span></a><span class="k2">(</span>fpsControl<span class="k2">)</span><span class="k2">;</span>
fpsControl, BPS_TO_TIMER<span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p> I was removing it when the player would pause the game. Anyone know why this?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felipe Maia)</author>
		<pubDate>Tue, 20 Dec 2005 01:33:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try: </p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/install_int_ex" target="_blank"><span class="a">install_int_ex</span></a><span class="k2">(</span>fpsCounter, BPS_TO_TIMER<span class="k2">(</span><span class="n">1</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 (scriptX)</author>
		<pubDate>Tue, 20 Dec 2005 01:38:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I was removing it when the player would pause the game.
</p></div></div><p>

You were manually removing it?  I don&#39;t see why you would need to do that...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Tue, 20 Dec 2005 01:49:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t bother removing it. Just place something like this at the start of the timer routine:</p><div class="source-code snippet"><div class="inner"><pre>
If<span class="k2">(</span>flags.paused<span class="k2">)</span> <span class="k2">{</span> <span class="k1">return</span><span class="k2">;</span> <span class="k2">}</span>
</pre></div></div><p>

That way you don&#39;t have to muck about with installing/removing timers unnecessarily.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Sirocco)</author>
		<pubDate>Tue, 20 Dec 2005 01:57:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
You were manually removing it? I don&#39;t see why you would need to do that...
</p></div></div><p> Not the fps, but the mainCounter needs to be removed on pauses, I think Sirocco&#39;s idea is good.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felipe Maia)</author>
		<pubDate>Tue, 20 Dec 2005 02:25:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Seems obvious but nobody else seems to have asked - do you have install_timer() anywhere in your code? You should call that before install_int_ex or else expect undefined results.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Tue, 20 Dec 2005 04:22:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thomas: Allegro calls install_timer() automatically for you if you don&#39;t call it before installing any timers, so that shouldn&#39;t be a problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (zer0)</author>
		<pubDate>Tue, 20 Dec 2005 04:40:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Thomas: Allegro calls install_timer() automatically for you if you don&#39;t call it before installing any timers, so that shouldn&#39;t be a problem.
</p></div></div><p>
To directly quote the manual:
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
int install_timer()</p><p>Installs the Allegro timer interrupt handler. You <b>must do this before installing any user timer routines</b>
</p></div></div><p>
(emphasis added)</p><p>So even if it says elsewhere that you don&#39;t need to then the best you can say is that there is no clear line and in my opinion you should err on the side of caution.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Tue, 20 Dec 2005 04:50:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, I agree that it is better coding practice to make a call to install_timer() first and &quot;err on the side of caution&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (zer0)</author>
		<pubDate>Tue, 20 Dec 2005 04:55:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I do, of course, the first call after allegro_init. I don&#39;t know exactly the problem the more obvious to me is that the library is not working as it should.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Felipe Maia)</author>
		<pubDate>Tue, 20 Dec 2005 07:37:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
However, I usually put the LOCK functions after the install_int_ex. Don&#39;t know if that&#39;d make a difference.
</p></div></div><p>
You&#39;re doing it wrong, and it will make a difference in DOS. In windows (and AFAIK linux and OSX too) it doesn&#39;t matter since the timers don&#39;t really run in an interrupt context, but rather in a separate thread. In DOS, however, they are interrupt routines, which means no virtual memory swap may occur while you&#39;re executing the code, hence the LOCK (which basically makes sure that all timer code and data are always in physical RAM). If you don&#39;t LOCK, and the timer code is swapped out, then the next time it is called you will crash.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I do, of course, the first call after allegro_init. I don&#39;t know exactly the problem the more obvious to me is that the library is not working as it should.
</p></div></div><p>
Have you tried installing the timer api <i>after</i> setting a gfx mode? It is possible that allegro needs a window handle before doing anything useful with timers and threads and whatnot.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I was removing it when the player would pause the game. Anyone know why this?
</p></div></div><p>
Since the timer runs in its own thread; maybe removing and installing it in a very short time doesn&#39;t give the other thread enough time to terminate, messing things up? Threads aren&#39;t my strong side, though, so I better STFU.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Tue, 20 Dec 2005 16:28:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
You&#39;re doing it wrong
</p></div></div><p>
Really?  I went back and looked closer at the manual and noticed you are definitely right.  The first time I read it, I mainly got &quot;you need to lock your handler functions and variables&quot; and &quot;it should go in your init routine&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Tue, 20 Dec 2005 22:25:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Think about it: From the moment on when you install a timer &quot;interrupt&quot;, it is possible that such an interrupt occurs. Even if the very next statement is the lock statement, the interrupt can occur before that. That&#39;s why you need to make sure that everything is locked <i>before</i> you use it in an interrupt context. Again, this only applies to interrupt-driven timers like the ones used in the DOS version.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Wed, 21 Dec 2005 17:04:05 +0000</pubDate>
	</item>
</rss>
