<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Fix Your Timestep!</title>
	<atom:link href="http://gafferongames.com/game-physics/fix-your-timestep/feed/" rel="self" type="application/rss+xml" />
	<link>http://gafferongames.com</link>
	<description>Glenn Fiedler, an Australian Game Developer in Los Angeles</description>
	<lastBuildDate>Mon, 15 Mar 2010 23:43:56 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Glenn Fiedler</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12601</link>
		<dc:creator>Glenn Fiedler</dc:creator>
		<pubDate>Thu, 04 Mar 2010 07:37:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12601</guid>
		<description>You are correct in that the velocity does not need to be interpolated. The code interpolates the entire physics state for the object but in fact the only interpolated quantity which is actually used is the position.</description>
		<content:encoded><![CDATA[<p>You are correct in that the velocity does not need to be interpolated. The code interpolates the entire physics state for the object but in fact the only interpolated quantity which is actually used is the position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manuel Bua</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12596</link>
		<dc:creator>Manuel Bua</dc:creator>
		<pubDate>Wed, 03 Mar 2010 10:03:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12596</guid>
		<description>I forgot to mention in your sample code you are also interpolating the velocity, not only the screen position: obviously you intended to interpolate the screen state with properties like position, rotations and scaling, but this may lead other people to think they need to do the same with other forces, as well as trying to inject these lerp&#039;ed values back in their physics engine.
I was reading Box2D forums and some code around and, sadly, most of them seem to misunderstand this very important point: too bad since it&#039;s a very well-written article on a too much often undervalued subject.</description>
		<content:encoded><![CDATA[<p>I forgot to mention in your sample code you are also interpolating the velocity, not only the screen position: obviously you intended to interpolate the screen state with properties like position, rotations and scaling, but this may lead other people to think they need to do the same with other forces, as well as trying to inject these lerp&#8217;ed values back in their physics engine.<br />
I was reading Box2D forums and some code around and, sadly, most of them seem to misunderstand this very important point: too bad since it&#8217;s a very well-written article on a too much often undervalued subject.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manuel Bua</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12564</link>
		<dc:creator>Manuel Bua</dc:creator>
		<pubDate>Mon, 22 Feb 2010 23:30:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12564</guid>
		<description>Oh well, i got it fixed, i wasn&#039;t interpolating the correct values due to a bad git commit..</description>
		<content:encoded><![CDATA[<p>Oh well, i got it fixed, i wasn&#8217;t interpolating the correct values due to a bad git commit..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manuel Bua</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12560</link>
		<dc:creator>Manuel Bua</dc:creator>
		<pubDate>Mon, 22 Feb 2010 07:24:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12560</guid>
		<description>I don&#039;t know what happened with my comment, #95 is mine btw ;)</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know what happened with my comment, #95 is mine btw <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12558</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 22 Feb 2010 00:14:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12558</guid>
		<description>&lt;blockquote cite=&quot;#commentbody-1789&quot;&gt;
&lt;strong&gt;&lt;a href=&quot;#comment-1789&quot; rel=&quot;nofollow&quot;&gt;Glenn Fiedler&lt;/a&gt; :&lt;/strong&gt;
to take it even further, you can run the main physics loop entirely on a separate thread which actually runs (in real time) at the number of frames per second the physics should run (say 100hz) and the render thread just reads latest physics state and interpolates, completely independent of physics
this way you are never doing two or more physics updates per-update, so processing is more evenly distributed
in addition, if you gather the input for you simulation on the physics thread, you sample the joystick or keyboard at regular 100hz intervals, which leads to better behavior of your physics
consider this, “fix your timestep version 2.0″  
&lt;/blockquote&gt;

Hi Glenn, thank you for such a beautiful article, nicely done!
I implemented a testbed with box2d and i have the renderer running in the main thread, while the physics and input are running on another one: i&#039;m experimenting the better way of doing things and at this point i can say from my tests that a strict producer/consumer model (that is, a frameNeeded semaphore and a frameReady semaphore) make the physics thread fluctuate since it&#039;s need to wait for the render thread to signal a frameNeeded.
However, implementing it with a mutex protecting the &quot;onRender&quot; call (main thread) and the same mutex protecting the &quot;onUpdate&quot; call (in the other thread), adding &quot;usleep&quot; to avoid both threads concurring much for the lock seems to work flawlessly.
The thing i can&#039;t get to work is the render thread to do subframe interpolation: i mean, everything is fine if the update thread do the subframe interpolation/time aliasing lerp, but if it would work in the render thread as you said it may need less cpu time if vsync is on.
Anyway, let me know if i can send you my code for your own tests: i see you are planning a &quot;fix your timestep v2&quot; so i&#039;m willing to help you out, although i&#039;m running Ubuntu it shouldn&#039;t be a problem to make v2 cross-platform!</description>
		<content:encoded><![CDATA[<blockquote cite="#commentbody-1789"><p>
<strong><a href="#comment-1789" rel="nofollow">Glenn Fiedler</a> :</strong><br />
to take it even further, you can run the main physics loop entirely on a separate thread which actually runs (in real time) at the number of frames per second the physics should run (say 100hz) and the render thread just reads latest physics state and interpolates, completely independent of physics<br />
this way you are never doing two or more physics updates per-update, so processing is more evenly distributed<br />
in addition, if you gather the input for you simulation on the physics thread, you sample the joystick or keyboard at regular 100hz intervals, which leads to better behavior of your physics<br />
consider this, “fix your timestep version 2.0″
</p></blockquote>
<p>Hi Glenn, thank you for such a beautiful article, nicely done!<br />
I implemented a testbed with box2d and i have the renderer running in the main thread, while the physics and input are running on another one: i&#8217;m experimenting the better way of doing things and at this point i can say from my tests that a strict producer/consumer model (that is, a frameNeeded semaphore and a frameReady semaphore) make the physics thread fluctuate since it&#8217;s need to wait for the render thread to signal a frameNeeded.<br />
However, implementing it with a mutex protecting the &#8220;onRender&#8221; call (main thread) and the same mutex protecting the &#8220;onUpdate&#8221; call (in the other thread), adding &#8220;usleep&#8221; to avoid both threads concurring much for the lock seems to work flawlessly.<br />
The thing i can&#8217;t get to work is the render thread to do subframe interpolation: i mean, everything is fine if the update thread do the subframe interpolation/time aliasing lerp, but if it would work in the render thread as you said it may need less cpu time if vsync is on.<br />
Anyway, let me know if i can send you my code for your own tests: i see you are planning a &#8220;fix your timestep v2&#8243; so i&#8217;m willing to help you out, although i&#8217;m running Ubuntu it shouldn&#8217;t be a problem to make v2 cross-platform!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Goffredo Marocchi</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12550</link>
		<dc:creator>Goffredo Marocchi</dc:creator>
		<pubDate>Thu, 18 Feb 2010 16:28:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12550</guid>
		<description>I would like to ask your comments about the following code which was very strongly inspired by the following article: http://www.sacredsoftware.net/tutorials/Animation/TimeBasedAnimation.xhtml 

One of the problems I was facing with that idea is that the frame-rate, fluctuating, did not play too nicely with the test sprite I was trying to animate (25 frames... I thought about 0.1 ms per frame would be good...)... for a particular reason I wanted to cap the logic update at a particular frame-rate making sure that it would not be updated faster or slower than a certain rate (to make sure that the animation would run at a specified frame-rate). After a bit of thought it occurred to me too that I would need to accumulate time...

-(void) updateLogic {
	float dyDroplet = (344.0f/11.0f); //watch out for the .0f, not to make it an integer division
	
	if (frameIndex &gt; 9 &amp;&amp; frameIndex  (460 - 0.00001f) &amp;&amp; frameIndex == 24) {
		//equivalent to saying: has the object reached its target &amp;&amp; should the animation be restarted?
		frameIndex = 0;
		dropletXY.y = 52;
		drop.center = dropletXY;
		drop.image = [self.dropImageArray objectAtIndex:frameIndex];
		return;
	}
	drop.center = dropletXY;
	if ((dropletXY.y + 64) &gt; 450) CMLog (@&quot;Droplet.PaB.y = %f&quot;, (dropletXY.y + 64));
	if (frameIndex  (MAX_CPF * FRAME_TIME)) {
		dt = (MAX_CPF * FRAME_TIME); 
		//MAX_CPF = (MAX_FPS/MIN_FPS); FRAME_TIME = (1.0f / MAX_FPS); dt  FRAME_TIME) { 
		while (dt_drop &gt; (dropAnimRate - aEPS)){ 
			//I do not want the animation of the droplet to run either faster than dropAnimRate or slower than that.
			[self updateLogic];
			dt_drop -= (dropAnimRate - aEPS);
		}
		dt -= FRAME_TIME;
	}
	
	cycles_left_over = dt;
	last_time = current_time;
	
	[gamePool release];
}

-(void) drawScene {
	CMLog (@&quot;frameIndex = %d&quot;, frameIndex);
	drop.image = [self.dropImageArray objectAtIndex:frameIndex];
}


The timer that calls the runLoop method is set to FRAME_TIME:

#define MAX_FPS (120.0f)
#define MIN_FPS (10.0f)
#define FRAME_TIME (1.0 / MAX_FPS)
#define MAX_CPF (MAX_FPS / MIN_FPS)

#define aEPS (0.0001f)</description>
		<content:encoded><![CDATA[<p>I would like to ask your comments about the following code which was very strongly inspired by the following article: <a href="http://www.sacredsoftware.net/tutorials/Animation/TimeBasedAnimation.xhtml" rel="nofollow">http://www.sacredsoftware.net/tutorials/Animation/TimeBasedAnimation.xhtml</a> </p>
<p>One of the problems I was facing with that idea is that the frame-rate, fluctuating, did not play too nicely with the test sprite I was trying to animate (25 frames&#8230; I thought about 0.1 ms per frame would be good&#8230;)&#8230; for a particular reason I wanted to cap the logic update at a particular frame-rate making sure that it would not be updated faster or slower than a certain rate (to make sure that the animation would run at a specified frame-rate). After a bit of thought it occurred to me too that I would need to accumulate time&#8230;</p>
<p>-(void) updateLogic {<br />
	float dyDroplet = (344.0f/11.0f); //watch out for the .0f, not to make it an integer division</p>
<p>	if (frameIndex &gt; 9 &amp;&amp; frameIndex  (460 &#8211; 0.00001f) &amp;&amp; frameIndex == 24) {<br />
		//equivalent to saying: has the object reached its target &amp;&amp; should the animation be restarted?<br />
		frameIndex = 0;<br />
		dropletXY.y = 52;<br />
		drop.center = dropletXY;<br />
		drop.image = [self.dropImageArray objectAtIndex:frameIndex];<br />
		return;<br />
	}<br />
	drop.center = dropletXY;<br />
	if ((dropletXY.y + 64) &gt; 450) CMLog (@&#8221;Droplet.PaB.y = %f&#8221;, (dropletXY.y + 64));<br />
	if (frameIndex  (MAX_CPF * FRAME_TIME)) {<br />
		dt = (MAX_CPF * FRAME_TIME);<br />
		//MAX_CPF = (MAX_FPS/MIN_FPS); FRAME_TIME = (1.0f / MAX_FPS); dt  FRAME_TIME) {<br />
		while (dt_drop &gt; (dropAnimRate &#8211; aEPS)){<br />
			//I do not want the animation of the droplet to run either faster than dropAnimRate or slower than that.<br />
			[self updateLogic];<br />
			dt_drop -= (dropAnimRate &#8211; aEPS);<br />
		}<br />
		dt -= FRAME_TIME;<br />
	}</p>
<p>	cycles_left_over = dt;<br />
	last_time = current_time;</p>
<p>	[gamePool release];<br />
}</p>
<p>-(void) drawScene {<br />
	CMLog (@&#8221;frameIndex = %d&#8221;, frameIndex);<br />
	drop.image = [self.dropImageArray objectAtIndex:frameIndex];<br />
}</p>
<p>The timer that calls the runLoop method is set to FRAME_TIME:</p>
<p>#define MAX_FPS (120.0f)<br />
#define MIN_FPS (10.0f)<br />
#define FRAME_TIME (1.0 / MAX_FPS)<br />
#define MAX_CPF (MAX_FPS / MIN_FPS)</p>
<p>#define aEPS (0.0001f)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12548</link>
		<dc:creator>Ilya</dc:creator>
		<pubDate>Wed, 17 Feb 2010 23:00:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12548</guid>
		<description>Many thanks for writing this wonderful article!

Thanks to it physical simulation in my game now runs much smoothly than ever before!</description>
		<content:encoded><![CDATA[<p>Many thanks for writing this wonderful article!</p>
<p>Thanks to it physical simulation in my game now runs much smoothly than ever before!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glenn Fiedler</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12482</link>
		<dc:creator>Glenn Fiedler</dc:creator>
		<pubDate>Sun, 31 Jan 2010 20:25:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12482</guid>
		<description>In general, physics simulation is too complicated to solve analytically so it is solved via numerical integration. Numerical integration is an approximation to the exact solution in which the accuracy of the result depends on the size of time-step. Typically numerical integration gives more accurate results for smaller time-steps. It follows that one step of n*dt is not the same as n steps of dt.</description>
		<content:encoded><![CDATA[<p>In general, physics simulation is too complicated to solve analytically so it is solved via numerical integration. Numerical integration is an approximation to the exact solution in which the accuracy of the result depends on the size of time-step. Typically numerical integration gives more accurate results for smaller time-steps. It follows that one step of n*dt is not the same as n steps of dt.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AngleWyrm</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12480</link>
		<dc:creator>AngleWyrm</dc:creator>
		<pubDate>Sun, 31 Jan 2010 19:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12480</guid>
		<description>Could you please explain a little bit about why n steps of dt is often different from one step of n*dt?</description>
		<content:encoded><![CDATA[<p>Could you please explain a little bit about why n steps of dt is often different from one step of n*dt?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glenn Fiedler</title>
		<link>http://gafferongames.com/game-physics/fix-your-timestep/#comment-12441</link>
		<dc:creator>Glenn Fiedler</dc:creator>
		<pubDate>Thu, 21 Jan 2010 23:01:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.gaffer.org/wordpress/fix-your-timestep/#comment-12441</guid>
		<description>your solution assumes that n steps of dt is equal to one step of n*dt -- this is not generally the case</description>
		<content:encoded><![CDATA[<p>your solution assumes that n steps of dt is equal to one step of n*dt &#8212; this is not generally the case</p>
]]></content:encoded>
	</item>
</channel>
</rss>