<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Question about Allegro 5 timers tutorial: variable timestep when dt ~= 0</title>
		<link>http://www.allegro.cc/forums/view/600021</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 24 Apr 2009 12:24:37 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was playing around with the timing method described in <a href="http://software.skoobalon.com/docs/a5_tut02.php">this Allegro 5 timers tutorial</a>, and I noticed that when I increased the rendering workload to the point where it started to lag considerably, the reported &quot;framerate&quot; would jump through the roof, up to over a million frames per second.</p><p>Looking at the code, this is because it uses the rather simplistic method of taking the reciprocal of the time delta at each step as the &quot;framerate.&quot; When the rendering takes enough time to start causing update lag, it skips rendering and just continues with the event loop, with the result being that the next update sees a delta-t very close to zero, hence the very high reciprocal.</p><p>What I&#39;m wondering is, if you&#39;re using variable timesteps, why even bother performing an update with a time delta so close to zero as to make no odds? Wouldn&#39;t it make more sense if, when lag causes a frame skip, you skip the backed-up update ticks as well, and just wait for the next scheduled tick? Just processing all the queued updates without rendering would give each one a time delta only as long as it took to process the previous update, which at least for simpler games would be negligible.</p><p>(Perhaps the tutorial example was just left that way for simplicity, since obviously skipping updates would require also accumulating the skipped deltas, since while negligible individually they might add up if a lot of frames get skipped...)</p><p>I guess in a game with more CPU-intensive logic, just the act of processing an update without rendering might take enough time for the game state to change appreciably, but as a general rule, does it make sense to just toss out updates with extremely small time delta values?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Accident)</author>
		<pubDate>Wed, 22 Apr 2009 08:28:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Howdy, I wrote the tutorial you are referencing.</p><p>I kind of had to diagram out the program&#39;s execution to remember how it goes:
</p><ul><li><p>Every 1/refresh_rate seconds, a timer event is fired.
</p></li><li><p>When the timer event is processed, update the position.
</p></li><li><p>If the timer event is processed more than 1/refresh_rate seconds after it was fired, do not draw, and hope (cross your fingers!) that the next frame&#39;s update code will execute fast enough so that the frame can be drawn.</p></li></ul><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807405#target">Mr. Accident</a> said:</div><div class="quote"><p>why even bother performing an update with a time delta so close to zero as to make no odds? Wouldn&#39;t it make more sense if, when lag causes a frame skip, you skip the backed-up update ticks as well, and just wait for the next scheduled tick?</p></div></div><p>An interesting point.  I suppose that you are correct in that it would not be necessary.  If you see a very small time step (you&#39;d have to figure out what &quot;very small&quot; is though, 1/10 of a frame?  1/100 of a frame?), it might make sense to just tack it on to the end of the next frame.</p><p>From my perspective, it is more work than it&#39;s worth, since it shouldn&#39;t affect <i>too</i> much.  That said, the &quot;cross your fingers&quot; part in my outline could cause issues on CPU-heavy programs.  I guess since I have never had issues (yet) with the way I do things, I haven&#39;t worried about that particular aspect.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (StevenVI)</author>
		<pubDate>Wed, 22 Apr 2009 09:33:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is the delta time approach just one persons view of handling speed consistency or the new A5 &#39;recommended&#39; route to using timers? I use the fixed FPS method (e.g. similar to <a href="http://wiki.allegro.cc/index.php?title=Timers">http://wiki.allegro.cc/index.php?title=Timers</a>) and have never had any problems.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 22 Apr 2009 15:23:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No. Do it the way you like more.<br />I think most a5 examples (if not all) come with fixed timing.</p><p>I&#39;m more the delta time guy <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (count)</author>
		<pubDate>Wed, 22 Apr 2009 16:15:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>No, delta time is always bad for various reasons (you need to integrate, the game will work differently depending on available CPU...) - but that&#39;s unrelated to A5. You can use whatever you want.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 22 Apr 2009 16:16:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807540#target">Elias</a> said:</div><div class="quote"><p>
the game will work differently depending on available CPU
</p></div></div><p>

Huh? How comes that?<br />If my movement for example is calculated like this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> update<span class="k2">(</span><span class="k1">float</span> delta<span class="k2">)</span>
<span class="k2">{</span>
    x <span class="k3">=</span> x <span class="k3">+</span> <span class="k2">(</span>speed_x <span class="k3">*</span> delta<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

How can that differ based on the used cpu?<br />Not trolling. I just want to learn why this could cause problems.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (count)</author>
		<pubDate>Wed, 22 Apr 2009 17:10:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, assume delta is 0.1 for player A, 0.5 for player B, a game sprite is at x = 0 at the beginning and speeding up from 0 to 10 during 1 second.</p><p>Player A:
</p><div class="source-code snippet"><div class="inner"><pre>frame <span class="n">0</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">0</span>.<span class="n">00</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">0</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">0</span>.<span class="n">00</span>
frame <span class="n">1</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">0</span>.<span class="n">00</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">1</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">0</span>.<span class="n">10</span>
frame <span class="n">2</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">0</span>.<span class="n">10</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">2</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">0</span>.<span class="n">30</span>
frame <span class="n">3</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">0</span>.<span class="n">30</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">3</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">0</span>.<span class="n">60</span>
frame <span class="n">4</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">0</span>.<span class="n">60</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">4</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">1</span>.<span class="n">00</span>
frame <span class="n">5</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">1</span>.<span class="n">00</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">5</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">1</span>.<span class="n">50</span>
frame <span class="n">6</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">1</span>.<span class="n">50</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">6</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">2</span>.<span class="n">10</span>
frame <span class="n">7</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">2</span>.<span class="n">10</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">7</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">2</span>.<span class="n">80</span>
frame <span class="n">8</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">2</span>.<span class="n">80</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">8</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">3</span>.<span class="n">60</span>
frame <span class="n">9</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">3</span>.<span class="n">60</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">9</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">10</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">4</span>.<span class="n">50</span>
</pre></div></div><p>
After one second, the sprite is at x = 4.5 pixel.</p><p>Now the very same sprite, starting at x = 0, speeding up from 0 to 10 during 1 second, for player B with delta 0.5:
</p><div class="source-code snippet"><div class="inner"><pre>frame <span class="n">0</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">0</span>.<span class="n">00</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">0</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">50</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">0</span>.<span class="n">00</span>
frame <span class="n">1</span><span class="k2">:</span> x <span class="k3">=</span> <span class="n">0</span>.<span class="n">00</span> <span class="k3">+</span> <span class="k2">(</span><span class="n">5</span>.<span class="n">00</span> <span class="k3">*</span> <span class="n">0</span>.<span class="n">50</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">2</span>.<span class="n">50</span>
</pre></div></div><p>
After one second, the sprite is at x = 2.5 pixel. So player A moved almost twice as fast.</p><p>You can of course solve this if you properly integrate... but it gets quite hard. And now assume you are actually using some kind of physics library with collision response and so on - then it&#39;s basically impossible to get it working the same for everyone when not using a fixed frequency.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 22 Apr 2009 17:49:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wicked! Thanks for that example!</p><p>Would it help doing something like this? (I mean it would help, but is it a <b>good way</b> to something like it?)<br />This would basically turn the delta timed method into a fixed timed method:</p><div class="source-code snippet"><div class="inner"><pre>total_delta <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="k1">while</span><span class="k2">(</span>game<span class="k2">)</span>
<span class="k2">{</span>
    delta_time <span class="k3">=</span> get_delta<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
    tatal_delta <span class="k3">+</span><span class="k3">=</span> delta<span class="k2">;</span>
    <span class="k1">if</span><span class="k2">(</span>tatal_delta <span class="k3">&gt;</span><span class="k3">=</span> <span class="n">0</span>.<span class="n">5</span><span class="k2">)</span> <span class="c">// 0.5 = only a value picked to show the example</span>
    <span class="k2">{</span>
        update_game<span class="k2">(</span>total_delta<span class="k2">)</span><span class="k2">;</span>
        total_delta <span class="k3">=</span> <span class="n">0</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 (count)</author>
		<pubDate>Wed, 22 Apr 2009 18:15:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes. Myself I like to use interpolation while rendering, so the game looks as smooth as possible. E.g. if the sprite is updated at a fixed rate of 30 times a second, but a monitor vsync happens 75 times a second, you can interpolate quite well where it should be at each vsync.</p><p>Like, assume the sprite was at pixel 100 at tick 0 (time 0), and it&#39;s at position 110 at tick 1 (time 0.0333 with 30 FPS). The first two renders happen at times 0 and 0.0133 (75Hz). So you can now interpolate:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a> <span class="n">0</span> <span class="k3">-</span><span class="k3">&gt;</span>  pixel <span class="n">100</span>
<a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a> <span class="n">0</span>.<span class="n">0333</span> <span class="k3">-</span><span class="k3">&gt;</span> pixel <span class="n">110</span>

so you render at: <span class="n">100</span> <span class="k3">+</span> <span class="n">0</span>.<span class="n">0133</span> <span class="k3">*</span> <span class="k2">(</span><span class="n">110</span> <span class="k3">-</span> <span class="n">100</span><span class="k2">)</span> <span class="k3">/</span> <span class="k2">(</span><span class="n">0</span>.<span class="n">0333</span> <span class="k3">-</span> <span class="n">0</span><span class="k2">)</span> <span class="k3">=</span> <span class="n">104</span>.<span class="n">000</span>
</pre></div></div><p>

So now even though the game logic only ever had the sprite at position 100 and 110, I render it at 104 (which is just the same position the delta time method would have rendered it at). So I get no visual difference, but keep all the advantages of using fixed step.</p><p>Still, this is all just preference, you can use whatever you want (also delta time).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Wed, 22 Apr 2009 18:48:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How do you interpolate between tick 0 and tick 1 when tick 1 hasn&#39;t happened yet? Or do you precompute the next scheduled tick before interpolating, or some other scheme like that? Also, couldn&#39;t assuming linear interpolation cause slightly inconsistent movement in between logical frames if the object in question is accelerating?</p><p>I&#39;m kinda curious in general about the relative advantages and drawbacks of variable vs. fixed timestep. In the past I&#39;ve always liked the fixed time approach because of its simplicity -- is the only real problem with it the fact that it might not appear as smooth if the update frequency is lower than the refresh rate?</p><p>Also, I get that updating the visual position of elements at the same frequency as the display&#39;s refresh rate provides the smoothest results, but how noticeable are the differences, generally? I don&#39;t have any high-refresh-rate monitors to test on; just LCDs that all run at 60Hz. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Accident)</author>
		<pubDate>Thu, 23 Apr 2009 04:25:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807731#target">Mr. Accident</a> said:</div><div class="quote"><p>I&#39;m kinda curious in general about the relative advantages and drawbacks of variable vs. fixed timestep</p></div></div><p>
Fixed timesteps are good and variable timesteps are bad. I hate to sound like &quot;that&#39;s the way it is and that&#39;s all there is to it,&quot; but, variable timesteps introduce a lot of problems, most of which I experienced the hard way when I was playing with variable timesteps <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>- It&#39;s difficult to get physics to behave. Even rather sophisticated numerical integrators have problems if the timestep changes too much. The kind of stupid algorithms most Allegro games use will suffer quite badly.<br /> <br />- Any sort of &quot;timer based&quot; (do this after N ticks/seconds/whatever) events will be very difficult to coordinate.</p><p>The one advantage you cited can be mitigated by just using a smaller fixed timestep. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (amber)</author>
		<pubDate>Thu, 23 Apr 2009 06:35:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807757#target">amber</a> said:</div><div class="quote"><p>Fixed timesteps are good and variable timesteps are bad.</p></div></div><p>

And that seems to be the only side we&#39;re hearing in this thread. If variable timestep is so bad then why is it even mentioned at all?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Black)</author>
		<pubDate>Thu, 23 Apr 2009 09:42:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807757#target">amber</a> said:</div><div class="quote"><p>- It&#39;s difficult to get physics to behave. Even rather sophisticated numerical integrators have problems if the timestep changes too much.</p></div></div><p>
Well, under normal circumstances, why would the timestep change considerably? It seems to me that this would only occur during, for example, sudden periods of unusually heavy load. In this case, couldn&#39;t you mitigate the problem by capping the timestep to a reasonable amount above the expected value?</p><p>The overall game speed would slow down in these (hopefully uncommon) circumstances, but that seems reasonable if the alternative is wonky integration.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807757#target">amber</a> said:</div><div class="quote"><p>- Any sort of &quot;timer based&quot; (do this after N ticks/seconds/whatever) events will be very difficult to coordinate.</p></div></div><p>

I don&#39;t see why it would be that difficult. Instead of checking for a number of ticks since the timer started, count the number of seconds. Something like this, maybe:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> timer::update<span class="k2">(</span><span class="k1">double</span> dt<span class="k2">)</span> <span class="k2">{</span>
    time_remaining <span class="k3">-</span><span class="k3">=</span> dt<span class="k2">;</span>

    <span class="k1">if</span><span class="k2">(</span>time_remaining <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
        fire_event<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div><p>


</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807757#target">amber</a> said:</div><div class="quote"><p>The one advantage you cited can be mitigated by just using a smaller fixed timestep. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p></div></div><p>
True, but some CRT monitors support pretty high refresh rates. And if I increased my logic framerate to accommodate those, I&#39;d be running way faster than necessary on most other systems.</p><p>But on the other hand, given the integration difficulties Elias pointed out, I guess you might run into considerable gameplay differences if your update logic can run anywhere from 60Hz to 120Hz or higher, depending on the hardware...</p><p>That&#39;s partly why I was asking just how noticeable the lack of smoothness really is on high refresh rate monitor, given, say, a fixed update frequency of 60 frames per second. That&#39;s what I&#39;ve always used in the past, and if it doesn&#39;t really have any noticeably deleterious effects, I&#39;d just as soon keep using that. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Accident)</author>
		<pubDate>Thu, 23 Apr 2009 10:36:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807792#target">Mr. Accident</a> said:</div><div class="quote"><p>
The overall game speed would slow down in these (hopefully uncommon) circumstances, but that seems reasonable if the alternative is wonky integration.
</p></div></div><p>
With fixed step timing you don&#39;t need to slow down, so that&#39;s the other alternative.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 23 Apr 2009 11:06:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807792#target">Mr. Accident</a> said:</div><div class="quote"><p>Well, under normal circumstances, why would the timestep change considerably? It seems to me that this would only occur during, for example, sudden periods of unusually heavy load. In this case, couldn&#39;t you mitigate the problem by capping the timestep to a reasonable amount above the expected value?</p></div></div><p>
You could. Of course, then you&#39;re very close to just putting the timestep into an &quot;accumulator&quot; when it&#39;s below an minimum value, making the minimum and maximum equal, and then you&#39;re using a fixed timestep. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I don&#39;t see why it would be that difficult. Instead of checking for a number of ticks since the timer started, count the number of seconds. Something like this, maybe:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> timer::update<span class="k2">(</span><span class="k1">double</span> dt<span class="k2">)</span> <span class="k2">{</span>
    time_remaining <span class="k3">-</span><span class="k3">=</span> dt<span class="k2">;</span>

    <span class="k1">if</span><span class="k2">(</span>time_remaining <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
        fire_event<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
    <span class="k2">}</span>
<span class="k2">}</span>
</pre></div></div></div></div><p>
Changing the unit of measurement doesn&#39;t eliminate the problem. The timer is still not firing on time-- it&#39;s firing whenever an update happens that causes the time_remaining to drop below 0. This may or may not be on time. The problem is at its worst when the time_remaining is close to but a little over the usual value of dt.  </p><p>For a timer of 0.02, if dt is 0.01, we seem safe:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k3">-</span> update <span class="n">0</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="n">0</span>.<span class="n">02</span><span class="k2">;</span> time_elapsed <span class="k3">=</span> <span class="n">0</span>.<span class="n">00</span>
<span class="k3">-</span> update <span class="n">1</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="n">0</span>.<span class="n">01</span><span class="k2">;</span> time_elapsed <span class="k3">=</span> <span class="n">0</span>.<span class="n">010</span>
<span class="k3">-</span> update <span class="n">2</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="n">0</span>.<span class="n">00</span><span class="k2">;</span> time_elapsed <span class="k3">=</span> <span class="n">0</span>.<span class="n">020</span> <span class="k3">-</span><span class="k3">-</span> right on <a href="http://www.delorie.com/djgpp/doc/libc/libc_821.html" target="_blank">time</a>
</pre></div></div><p>
If dt is a little bigger (0.011), we&#39;re late.
</p><div class="source-code snippet"><div class="inner"><pre><span class="k3">-</span> update <span class="n">0</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="n">0</span>.<span class="n">02</span><span class="k2">;</span> time_elapsed <span class="k3">=</span> <span class="n">0</span>.<span class="n">000</span>
<span class="k3">-</span> update <span class="n">1</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="n">0</span>.<span class="n">09</span><span class="k2">;</span> time_elapsed <span class="n">0</span>.<span class="n">011</span>
<span class="k3">-</span> update <span class="n">2</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="k3">-</span><span class="n">0</span>.<span class="n">002</span><span class="k2">;</span> time_elapsed <span class="n">0</span>.<span class="n">022</span> <span class="k3">-</span><span class="k3">-</span> late
</pre></div></div><p>
If dt is a little smaller (0.009), we&#39;re really late.
</p><div class="source-code snippet"><div class="inner"><pre><span class="k3">-</span> update <span class="n">0</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="n">0</span>.<span class="n">02</span><span class="k2">;</span> time_elapsed <span class="k3">=</span> <span class="n">0</span>.<span class="n">000</span>
<span class="k3">-</span> update <span class="n">1</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="n">0</span>.<span class="n">011</span><span class="k2">;</span> time_elapsed <span class="k3">=</span> <span class="n">0</span>.<span class="n">009</span>
<span class="k3">-</span> update <span class="n">2</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="n">0</span>.<span class="n">002</span><span class="k2">;</span> time_elapsed <span class="k3">=</span> <span class="n">0</span>.<span class="n">018</span>
<span class="k3">-</span> update <span class="n">3</span><span class="k2">:</span> time_remaining <span class="k3">=</span> <span class="k3">-</span><span class="n">0</span>.<span class="n">007</span><span class="k2">;</span> time_elapsed <span class="k3">=</span> <span class="n">0</span>.<span class="n">027</span> <span class="k3">-</span><span class="k3">-</span> very late
</pre></div></div><p>

</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>how noticeable the lack of smoothness really is on high refresh rate monitor, given, say, a fixed update frequency of 60 frames per second.</p></div></div><p>
At least to me, it&#39;s not usually that noticeable, except if you&#39;re moving something very fast. Things going much more than 4 pixels/tick start to look really choppy.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (amber)</author>
		<pubDate>Fri, 24 Apr 2009 04:29:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807935#target">amber</a> said:</div><div class="quote"><p>You could. Of course, then you&#39;re very close to just putting the timestep into an &quot;accumulator&quot; when it&#39;s below an minimum value, making the minimum and maximum equal, and then you&#39;re using a fixed timestep. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p></div></div><p>
Well, that would be a fixed timestep of a sort, yes, but in a situation like the tutorial example, that nominal &quot;fixed&quot; rate will still be different depending on the hardware refresh rate. I mean, in ideal circumstances, the &quot;variable&quot; timestep will be constant throughout, with dt always being 1/(refresh rate).</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/600021/807935#target">amber</a> said:</div><div class="quote"><p>Changing the unit of measurement doesn&#39;t eliminate the problem. The timer is still not firing on time-- it&#39;s firing whenever an update happens that causes the time_remaining to drop below 0. This may or may not be on time. The problem is at its worst when the time_remaining is close to but a little over the usual value of dt.</p></div></div><p>

Well, strictly speaking you have this problem even with fixed timesteps, if you try to set a timeout that isn&#39;t a multiple of the timestep. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> But I see your point; in particular if your game might conceivably be running at 60Hz, 75Hz, 80Hz, or even 100Hz or higher, this inhibits your ability to count durations with precision.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Accident)</author>
		<pubDate>Fri, 24 Apr 2009 11:06:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Physics engines like box2d use fixed time steps, in fact use sub-stepping. Don&#39;t know where I&#39;m going with this, just thought I&#39;d mention it <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Fri, 24 Apr 2009 12:24:37 +0000</pubDate>
	</item>
</rss>
