<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Delta Timing - what exactly is it?</title>
		<link>http://www.allegro.cc/forums/view/597295</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 08 Aug 2008 01:21:46 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What exactly <i>is</i> Delta Timing? I know it has something to do with changing how fast something thing goes (in the case of a moving object) based on how long it took to run the logic loop, but I&#39;m not sure how to implement it, or even exactly how it works. I couldn&#39;t really understand the articles I found very well.</p><p>Thanks in advance!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kikaru)</author>
		<pubDate>Fri, 08 Aug 2008 00:13:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It is the measurement of time between to points in time.<br />Between 75ms and 100 ms is 25ms. 25ms is the delta time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blargmob)</author>
		<pubDate>Fri, 08 Aug 2008 00:23:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Delta timing is basically variable time logic step timing.</p><p>First, you need a very accurate timer to keep the time. I do not think you can make a good delta timing based loop using allegro&#39;s timers for example.</p><p>Then you do this:</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="k1">float</span> old_time <span class="k3">=</span> GetTime<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">2</td><td><span class="k1">while</span><span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span></td></tr><tr><td class="number">3</td><td><span class="k2">{</span></td></tr><tr><td class="number">4</td><td>  <span class="k1">float</span> new_time <span class="k3">=</span> GetTime<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">5</td><td>  <span class="k1">float</span> delta <span class="k3">=</span> new_time <span class="k3">-</span> old_time<span class="k2">;</span></td></tr><tr><td class="number">6</td><td>  old_time <span class="k3">=</span> new_time<span class="k2">;</span></td></tr><tr><td class="number">7</td><td>  </td></tr><tr><td class="number">8</td><td>  <span class="k1">if</span><span class="k2">(</span>delta <span class="k3">&gt;</span> <span class="n">0</span>.<span class="n">1</span><span class="k2">)</span><span class="c">//&gt;0.1 sec</span></td></tr><tr><td class="number">9</td><td>  <span class="k2">{</span></td></tr><tr><td class="number">10</td><td>    delta <span class="k3">=</span> <span class="n">0</span>.<span class="n">1</span><span class="k2">;</span><span class="c">//you need this to keep your game from becoming numerically unstable</span></td></tr><tr><td class="number">11</td><td>  <span class="k2">}</span></td></tr><tr><td class="number">12</td><td>  </td></tr><tr><td class="number">13</td><td>  player-&gt;x <span class="k3">+</span><span class="k3">=</span> player-&gt;vx <span class="k3">*</span> delta<span class="k2">;</span></td></tr><tr><td class="number">14</td><td>  player-&gt;sprite.time_passed <span class="k3">+</span><span class="k3">=</span> delta<span class="k2">;</span></td></tr><tr><td class="number">15</td><td>  </td></tr><tr><td class="number">16</td><td>  <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>buffer, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span>,<span class="n">100</span>,<span class="n">100</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>  </td></tr><tr><td class="number">18</td><td>  RestUntilDeltaIsAtLeastSomeInterval<span class="k2">(</span>old_time, <span class="n">1</span> <span class="k3">/</span> <span class="n">60</span>.<span class="n">0</span><span class="k2">)</span><span class="k2">;</span><span class="c">//60 frames per second max</span></td></tr><tr><td class="number">19</td><td><span class="k2">}</span></td></tr></tbody></table></div></div><p>

Basically, you measure the amount of time passed between each logic update, and do then base your logic things on that time interval. In the example above, for example, I move the player by multiplying his speed in units per second by the time passed in seconds. Also, I update some sprite time counter by the same interval. Then I blit to the screen as usual, and then do a frame limiting step. This last step is optional and most games don&#39;t do it, but it is nice to have for the laptop users.</p><p>You shouldn&#39;t use this method though for a couple of reasons: depending on the speed of the computer the results of the game might be dependent on the FPS, because Euler integration is like that. Also, you need a high quality timer, which you may not have.</p><p>At the same time this method is nice to have for this one reason: you can do &#39;bullet-time&#39; effects trivially, just multiply the delta by some factor and automatically everything in the game is slowed down (or even sped up). This can be done in a fixed time step timing (the usual kind suggested on these forums) but it needs planning. With delta timing you get the ability automatically.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 08 Aug 2008 00:46:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s a bit better explanation then mine <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (blargmob)</author>
		<pubDate>Fri, 08 Aug 2008 00:47:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks. So it&#39;s basically what I thought it was.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kikaru)</author>
		<pubDate>Fri, 08 Aug 2008 01:21:46 +0000</pubDate>
	</item>
</rss>
