<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Limit of usage of the timers</title>
		<link>http://www.allegro.cc/forums/view/456146</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 21 Feb 2005 19:59:07 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>By the post you can think that i&#39;m asking about how many timers a can use in a certain moment, but no, don&#39;t care.</p><p>My question is that i need a timer routine that must be executed each milisecond. The routine is very simple, it only increases a var (very tipical). It&#39;s done for animation speed stuff. </p><p>Well, i&#39;ve implemented it and i don&#39;t noticed any slow of perfomance, but, there are risks to happen what i say? <br />Thinking in the code, the game logic routines could be done in one microsecond (more or less) in the worst of cases, i think. Drawing routine should be done in various microseconds, so, at first, looks like there isn&#39;t problems.</p><p>Am I wrong? </p><p>Thanks in advance.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CascoOscuro)</author>
		<pubDate>Tue, 01 Feb 2005 20:44:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Your timer routine will most likely not be executed each milisecond. Instead it will be executed ten times in a row once every 10 miliseconds...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (miran)</author>
		<pubDate>Tue, 01 Feb 2005 20:57:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Depends on the platform I would say. On Windows, you can improve accuracy of the timers by calling timeBeginPeriod(1); when the program is starting and timeEndPeriod(1); when the program is ending.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Tue, 01 Feb 2005 21:10:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">tobing said:</div><div class="quote"><p>Depends on the platform I would say. On Windows, you can improve accuracy of the timers by calling timeBeginPeriod(1); when the program is starting and timeEndPeriod(1); when the program is ending.</p></div></div><p>It isn&#39;t the first time i hear this and it seems to work; if it&#39;s so simple why isn&#39;t it added to allegro?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (FMC)</author>
		<pubDate>Tue, 01 Feb 2005 22:06:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The platform is for now windows, but i want to port it to Linux, (if fblend lets me do it).<br />For this purpose i could do the timer routine after every end of main loop execution, because frame rate is limited.<br />thank you for all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CascoOscuro)</author>
		<pubDate>Tue, 01 Feb 2005 23:10:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Mithrandir said:</div><div class="quote"><p>It isn&#39;t the first time i hear this and it seems to work; if it&#39;s so simple why isn&#39;t it added to allegro?</p></div></div><p>
I have submitted that as a change request for the next version. Until now I don&#39;t know if they will add it or not...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Wed, 02 Feb 2005 00:02:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>My question is that i need a timer routine that must be executed each milisecond. The routine is very simple, it only increases a var (very tipical). It&#39;s done for animation speed stuff. </p></div></div><p>
Actually, I fail to see how you would need a millisecond-accurate timer for <i>animation</i>...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Wed, 02 Feb 2005 01:13:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You might not use such a fast counter for doing animations. I&#39;m using counters of that type for internal performance measurements of certain code sections (and for that I&#39;m acutally using a timer which counts 10000 per sec).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Wed, 02 Feb 2005 01:15:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
It isn&#39;t the first time i hear this and it seems to work; if it&#39;s so simple why isn&#39;t it added to allegro?
</p></div></div><p>
Because as far as I&#39;ve heard, it isn&#39;t reliable.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Wed, 02 Feb 2005 02:25:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
hy must a trip to Europe be so expensive?
</p></div></div><p>

to slow down animations speed applying modular mathematics.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CascoOscuro)</author>
		<pubDate>Wed, 02 Feb 2005 02:50:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Because as far as I&#39;ve heard, it isn&#39;t reliable.</p></div></div><p>
Can you elaborate?<br />I was planning on adding it, but I&#39;d like to know what I&#39;m adding if there are possible problems with it...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 02 Feb 2005 02:55:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Because as far as I&#39;ve heard, it isn&#39;t reliable.</p></div></div><p>
That&#39;s something I would also like to know. My experiences don&#39;t second that...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Wed, 02 Feb 2005 03:09:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You probably want to call timeGetDevCaps() first, to get the range of periods that are supported on the OS.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Wed, 02 Feb 2005 03:17:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>First I thought that would be a good idea. Then, why not simply calling timeBeginPeriod(1); ? If the capabilities are not sufficient (which is not very probable on modern PCs) then the result will be what is closest to timer precision of 1ms. So there&#39;s no need to check capabilities. Of course this is different if the application actually depends on precision, but then it&#39;s the applications&#39; responsibility to check for that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Wed, 02 Feb 2005 13:25:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">CascoOscuro&#39;s quote said:</div><div class="quote"><p>
hy must a trip to Europe be so expensive?
</p></div></div><p>
What does that have to do with anything??? <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> And what program are you making that involves modular mathematics?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ron Ofir)</author>
		<pubDate>Wed, 02 Feb 2005 14:09:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, sorry! I forgot the &quot;copy&quot; before &quot;paste&quot;:-/. That&#39;s a quote from another post.</p><p>The quote was about gnolam said above. </p><p>Well... imagine that you want a run animation for a enemy, and game has bullet time (for example), with a limited frames.</p><p>So the animation routine is such as:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> CCharacter::anim<span class="k2">(</span><span class="k2">)</span>
<span class="k2">{</span>
   <span class="k1">if</span><span class="k2">(</span><span class="k3">!</span><span class="k2">(</span>Timer % SlowDowner<span class="k2">)</span><span class="k2">)</span>
     Frame<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

Of course it&#39;s more complex than this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CascoOscuro)</author>
		<pubDate>Wed, 02 Feb 2005 19:09:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>First I thought that would be a good idea. Then, why not simply calling timeBeginPeriod(1); ?</p></div></div><p>
It probably effects other apps too. I would imagine it&#39;d make them less responsive if your program is &quot;checked on&quot; more often.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 02 Feb 2005 19:52:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I would imagine it&#39;d make them less responsive if your program is &quot;checked on&quot; more often. </p></div></div><p>
I think I don&#39;t understand. What do you mean with that? </p><p>BTW my proposed change would only affect the rest()-function to be more precise. In other cases the application could call timeBeginTime(1) as needed or applicable. One could think about calling timeBeginTime(1) only if rest() is called with value 1 - or something like rest(n) internally calls timeBeginPeriod(n) and only if n is nonzero. I would think that Evert is already trying this out and playing around with such things...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Wed, 02 Feb 2005 20:42:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I would think that Evert is already trying this out and playing around with such things...</p></div></div><p>
Evert doesn&#39;t use Windows though, so he can&#39;t really do much experimentation...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 02 Feb 2005 20:47:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok. So then I&#39;ll do some more investigations, maybe I&#39;ll send you some modification then.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Wed, 02 Feb 2005 20:54:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I think I don&#39;t understand. What do you mean with that?</p></div></div><p>
When you call rest/Sleep normally, Windows puts the process to sleep and waits until the next time the scheduler would get back to your program before waking back up. However, by setting timeBeginPeriod(1), it checks your program more often, which means other programs would get interrupted more often. If the scheduler granularity could be more than 10ms, I think it would be.. but it&#39;s not for a reason.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 03 Feb 2005 09:57:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I see. Well, my experiments so far haven&#39;t shown any difference wrt to this behaviour, calling timeBeginPeriod(1) or not. Only, if I call it, then my own program needs less CPU in total, so there&#39;s actually more CPU available for other applications.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Thu, 03 Feb 2005 12:56:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Only, if I call it, then my own program needs less CPU in total</p></div></div><p>
That contradicts what it does, though. To check on your app more often requires more CPU. Especially as it relates to rest, where I made the analogy about a person waking up every hour for 8 hours while in bed, instead of doing the 8 hours all in one shot.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 03 Feb 2005 15:08:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t know -  the rest() call is not using the CPU. It is the remainder of my game loop, but I don&#39;t know why this is so. The observation is that adding a call to timeBeginTime(1) within the implementation of rest(1) makes the complete loop smoother, and overall less CPU is used. I think it might be because of smoother checking timers, so when timers are not accurate you might spend more time in some loop than required. So this might be some side-effect of calling those functions...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Thu, 03 Feb 2005 15:35:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Well... imagine that you want a run animation for a enemy, and game has bullet time (for example), with a limited frames.
</p></div></div><p>
Still, you won&#39;t need timers faster than a few times the frame rate. 1ms is just insane. If you want to alter the game speed, don&#39;t alter the timer rate, but rather the timer delta. Example:<br />Say, in &quot;normal&quot; time, you have a timer running at 100Hz (10 ms). This is still roughly twice the frequency needed for smooth animation. With each tick, the timer is increased by 10. For each screen update, you update your logic according to the timer delta (either use variable-delta logic, or keep calling the logic update function until the timer delta is back to 0). To produce bullet time, say, with a factor of 10, you increase the timer by 1 instead of 10. The rest of the program remains unchanged. Your logic will now update at 1/10 the speed, without the need for insanely high timer rates.<br />The thing is, even if all you do in the timer function is increase a variable by 1, calling it 1000 times per second <i>does</i> induce unneeded overhead.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Thu, 03 Feb 2005 17:01:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The overhead from these function calls is so small that I can&#39;t measure it. </p><p>I don&#39;t use these high precision timers for game speed, but to give some time back to the OS, more precisely the time remaining to the next frame when all the work has been done for this frame. In that context it is very reasonable to ask for precision of 1ms.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Thu, 03 Feb 2005 17:32:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>In that context it is very reasonable to ask for precision of 1ms.</p></div></div><p>
Not really.. not unless your game is running at more than 100LPS (log frames per second). 0.01th of a second for jitter isn&#39;t that big of a deal.</p><p>That said, you don&#39;t even <i>have</i> to rest at all for a CPU intensive game.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 03 Feb 2005 17:40:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>True, but for a CPU intensive game only. My game is expected to use only very little CPU, even at higher logical speed. I just like to be nice with my game, and I like to save my laptop from using power when it is not really necessary.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Thu, 03 Feb 2005 19:11:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Usually when a game isn&#39;t CPU intensive, it doesn&#39;t need that extra precision. The time jitter is reduced/removed by the speedy execution.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 03 Feb 2005 20:36:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Theoretically, yes. That&#39;s what I thought before. Then I just saw that my program would use much more CPU than expected, and that&#39;s where I started my investigations. So my finding is that calling timeBeginPeriod(1) when using rest(1) solved the problem essentially.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Thu, 03 Feb 2005 20:50:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How about using something equivalent to
</p><div class="source-code snippet"><div class="inner"><pre>timeBeginPeriod<span class="k2">(</span>n<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/rest" target="_blank"><span class="a">rest</span></a><span class="k2">(</span>n<span class="k2">)</span><span class="k2">;</span>
timeEndPeriod<span class="k2">(</span>n<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
or perhaps something like timeBeginPeriod((n+1)/2)? In that way, you don&#39;t increase the granularity of the timer to more than it needs to be and keep the benefits that it offers... I think. Of course, the most common case would be rest(1), where this wouldn&#39;t actually change anything.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 04 Feb 2005 14:37:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t know what other side effects the timeBeginPeriod(n) would have. I would definitely not like to have it influence other timers around. So I think that calling timeBeginPeriod(1) only increases precision, so it doesn&#39;t harm. Calling it with other values might decrease precision in case the application has called timeBeginPeriod(1) before. I would not appreciate such a behaviour... </p><p>Edit: Before calling timeBeginPeriod you have to use timeGetDevCaps to determine valid values. The following code is from MSDN:
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define TARGET_RESOLUTION 1         // 1-millisecond target resolution</span>

TIMECAPS tc<span class="k2">;</span>
UINT     wTimerRes<span class="k2">;</span>

<span class="k1">if</span> <span class="k2">(</span>timeGetDevCaps<span class="k2">(</span><span class="k3">&amp;</span>tc, <span class="k1">sizeof</span><span class="k2">(</span>TIMECAPS<span class="k2">)</span><span class="k2">)</span> <span class="k3">!</span><span class="k3">=</span> TIMERR_NOERROR<span class="k2">)</span> 
<span class="k2">{</span>
    <span class="c">// Error; application can't continue.</span>
<span class="k2">}</span>

wTimerRes <span class="k3">=</span> min<span class="k2">(</span>max<span class="k2">(</span>tc.wPeriodMin, TARGET_RESOLUTION<span class="k2">)</span>, tc.wPeriodMax<span class="k2">)</span><span class="k2">;</span>
timeBeginPeriod<span class="k2">(</span>wTimerRes<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
I haven&#39;t looked into how timers are created in allegro, but if it is using timeSetEvent it will be affected by timeBeginPeriod also. So it might also be a good idea to put a call of timeBeginPeriod(1) into allegro&#39;s init_timer() function?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Fri, 04 Feb 2005 18:58:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I don&#39;t know what other side effects the timeBeginPeriod(n) would have. I would definitely not like to have it influence other timers around.</p></div></div><p>
It shouldn&#39;t affect other applications at any rate... I&#39;m not sure about other threads though, but that&#39;s something that would have to be tested.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>So I think that calling timeBeginPeriod(1) only increases precision, so it doesn&#39;t harm. Calling it with other values might decrease precision in case the application has called timeBeginPeriod(1) before. I would not appreciate such a behaviour...</p></div></div><p>
Remember that this is for rest() only though. If you call rest(10), does it really make sense to set the resolution to 1 if 10 (or 5) would probably do just as well for that case?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>but if it is using timeSetEvent it will be affected by timeBeginPeriod also. So it might also be a good idea to put a call of timeBeginPeriod(1) into allegro&#39;s init_timer() function?</p></div></div><p>
Probably, yes. I don&#39;t know how this is done in Windows though... I can probably look at the code (but not test it) this evening.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 04 Feb 2005 19:22:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ll look into the code this weekend, and I&#39;ll test calling timeBeginPeriod(1) from within init_timer(). </p><p>OK. So here&#39;s my findings: </p><p>When I call timebeginPeriod(1) in the beginning of my program, or inside install_timer() then overall CPU usage increases (sometimes drastically). So some objections made are valid: requesting higher accuracy does cost something. </p><p>So then I tried some other places to put this call, but the only place where it does good - and really decreases CPU usage - is inside of the implementation of rest(), which is exactly what I requested some time ago. </p><p>Evert: Should I send you the code again, this time with some improved error handling? It is not much, only checking the return value of timeBeginPeriod() to decide if timeEndPeriod() has to be called or not.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Mon, 07 Feb 2005 14:24:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Evert: Should I send you the code again, this time with some improved error handling? It is not much, only checking the return value of timeBeginPeriod() to decide if timeEndPeriod() has to be called or not.</p></div></div><p>
Please do!<br />Also, if you could check if Allegro uses timeSetEvent and would be affected by calling timeBeginPeriod()?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Mon, 14 Feb 2005 04:23:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The function &#39;timeSetEvent&#39; is not used in allegro. What is used is a call to &#39;SetEvent&#39; using &#39;timer_stop_event = CreateEvent(...)&#39; in wtimer.c:222. As far as my program has shown, the call to timeBeginPeriod(1); added in tim_win32_rest(...) does not affect that. Well, calling timeBeginPeriod(1); from my main program has some effects, so that might have undesirable influence here. </p><p>This is the updated code section in wtimer.c:</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="c">/* tim_win32_rest:</span></td></tr><tr><td class="number">2</td><td><span class="c"> *  Rests the specified amount of milliseconds.</span></td></tr><tr><td class="number">3</td><td><span class="c"> */</span></td></tr><tr><td class="number">4</td><td><span class="k1">static</span> <span class="k1">void</span> tim_win32_rest<span class="k2">(</span><span class="k1">unsigned</span> <span class="k1">int</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a>, AL_METHOD<span class="k2">(</span><span class="k1">void</span>, callback, <span class="k2">(</span><span class="k1">void</span><span class="k2">)</span><span class="k2">)</span><span class="k2">)</span></td></tr><tr><td class="number">5</td><td><span class="k2">{</span></td></tr><tr><td class="number">6</td><td>   <span class="k1">unsigned</span> <span class="k1">int</span> start<span class="k2">;</span></td></tr><tr><td class="number">7</td><td>   <span class="k1">unsigned</span> <span class="k1">int</span> ms <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a><span class="k2">;</span></td></tr><tr><td class="number">8</td><td>&#160;</td></tr><tr><td class="number">9</td><td>   <span class="k1">const</span> MMRESULT rc <span class="k3">=</span> timeBeginPeriod<span class="k2">(</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">10</td><td>   <span class="k1">if</span> <span class="k2">(</span>callback<span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">11</td><td>      start <span class="k3">=</span> timeGetTime<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>      <span class="k1">while</span> <span class="k2">(</span>timeGetTime<span class="k2">(</span><span class="k2">)</span> <span class="k3">-</span> start <span class="k3">&lt;</span> ms<span class="k2">)</span></td></tr><tr><td class="number">13</td><td>         <span class="k2">(</span><span class="k3">*</span>callback<span class="k2">)</span><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>   <span class="k2">}</span></td></tr><tr><td class="number">15</td><td>   <span class="k1">else</span> <span class="k2">{</span></td></tr><tr><td class="number">16</td><td>      Sleep<span class="k2">(</span>ms<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>   <span class="k2">}</span></td></tr><tr><td class="number">18</td><td>   <span class="k1">if</span><span class="k2">(</span> rc <span class="k3">=</span><span class="k3">=</span> TIMERR_NOERROR <span class="k2">)</span></td></tr><tr><td class="number">19</td><td>     timeEndPeriod<span class="k2">(</span><span class="n">1</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>

Maybe I should also send this to the mailing list (AD)?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Tue, 15 Feb 2005 17:37:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Maybe I should also send this to the mailing list (AD)?</p></div></div><p>
Please do. Or, you can use the tracker on Allegro&#39;s sourceforge page.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 15 Feb 2005 18:31:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Done.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Tue, 15 Feb 2005 18:45:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why not just put time_begin_period into allegro_init? Surely calling it only once at startup would cause less overhead than calling it everytime rest() is called.. or am I missing something?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 15 Feb 2005 19:26:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have tried that. The overall performance decreases actually, which surprised me of course. Explanantion is probably that the call does have some side effects, which cause more overhead in other functions. So that&#39;s the reason I have left it at putting the calls into rest() only.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Tue, 15 Feb 2005 19:29:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah, makes sense then. Probably should add a comment telling about that..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Tue, 15 Feb 2005 19:34:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Finally I got some test project together, which contains my current game framework including the game loop. This can serve as performance benchmark (how many balls do use how much cpu time), but also as an example of a game framework and a game loop. Basically, the game loop is taken from Lennart Steinke&#39;s book &#39;Spieleprogrammierung&#39; in bhv Verlag. </p><p>There&#39;s a MSVC7.1 project file included, but no makefile (the last makefile I have written is 8 years ago...), and you have to include the allegro library to the linker statement (because I&#39;m using my allegro project file, which inplies automatic linkage in the Visual Studio). If someone has a working makefile, you might post it here, so I can include it in the archive eventually...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Mon, 21 Feb 2005 19:59:07 +0000</pubDate>
	</item>
</rss>
