<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx</link><description>Time can be a surprisingly slippery concept to get to grips with. Back when I was working on Allegro it caused the most common question from new programmers , and even though XNA does more than Allegro to handle time for you, it appears some people are</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4052743</link><pubDate>Thu, 26 Jul 2007 04:23:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4052743</guid><dc:creator>JLarkin</dc:creator><description>&lt;p&gt;I saw that there was an &amp;quot;IsRunningSlowly&amp;quot; property, but could never really figure out its use. Now I know!&lt;/p&gt;
&lt;p&gt;Also, on MotoGP, how would running the physics system twice work? Did you update positions/speeds and then do the same again just so that the deltas were smaller? Was it something like what follows?&lt;/p&gt;
&lt;p&gt;physSim.Update();&lt;/p&gt;
&lt;p&gt;physSim.Update();&lt;/p&gt;
&lt;p&gt;I'm curious to see how something like that would work... Nice post, btw, thanks.&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4053778</link><pubDate>Thu, 26 Jul 2007 06:37:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4053778</guid><dc:creator>Björn</dc:creator><description>&lt;p&gt;The default 60Hz-because-of-TV-refresh makes me wonder: does this change to 50Hz when the XBox is connected to a PAL TV? Or - from a not too serious POV - is this just another default chosen in the spirit of &amp;quot;We are Americans and deal with i18n issues in v.Next&amp;quot;? :]&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4055147</link><pubDate>Thu, 26 Jul 2007 08:20:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4055147</guid><dc:creator>bohemanja</dc:creator><description>&lt;p&gt;Shawn.. You're awesome..&lt;/p&gt;
&lt;p&gt;Thanks for your article.&lt;/p&gt;
&lt;p&gt;This is exactly what I am looking in the past few days. This is by far the best and most comprehensive I can find regarding game timing.. :)&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4066857</link><pubDate>Thu, 26 Jul 2007 18:15:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4066857</guid><dc:creator>Rim</dc:creator><description>&lt;p&gt;Hmmm... In our DBP entry we opted for a fixed timestep at some 33 updates per second to keep CPU load low *and* enabled VSyncing to prevent tearing. Fraps indicated a steady 75 FPS, while examining the gameTime.ElapsedTime in the Update method shows it is called at the fixed timestep (33 FPS). So it would seem Draw can be called more often than Update.&lt;/p&gt;
&lt;p&gt;I don't know if I'm misreading your post, but the scenarios you described only seem to mention &amp;quot;x calls to Update + one call to Draw()&amp;quot; (i.e. Draw is always limited by Update frequency), so I thought I'd point this out. &lt;/p&gt;
&lt;p&gt;Please drop a line if this is horrible abuse of the fixed timestep :)&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4067132</link><pubDate>Thu, 26 Jul 2007 18:28:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4067132</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;&amp;gt; I don't know if I'm misreading your post, but &amp;gt; the scenarios you described only seem to &lt;/p&gt;
&lt;p&gt;&amp;gt; mention &amp;quot;x calls to Update + one call to Draw&lt;/p&gt;
&lt;p&gt;&amp;gt; ()&amp;quot; (i.e. Draw is always limited by Update &lt;/p&gt;
&lt;p&gt;&amp;gt; frequency), so I thought I'd point this out. &lt;/p&gt;
&lt;p&gt;At the moment we sometimes call draw more often than we really should (there's not really any point calling it twice if we didn't do an update in between, since it will just be drawing the same thing again!). This is likely to change in future versions.&lt;/p&gt;
</description></item><item><title>GameTime outside America</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4069140</link><pubDate>Thu, 26 Jul 2007 21:05:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4069140</guid><dc:creator>Shawn Hargreaves Blog</dc:creator><description>&lt;p&gt;Bj&amp;#246;rn comments on my previous post : The default 60Hz-because-of-TV-refresh makes me wonder: does this&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4070961</link><pubDate>Fri, 27 Jul 2007 00:56:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4070961</guid><dc:creator>PaulCunningham</dc:creator><description>&lt;p&gt;Shawn says...&lt;/p&gt;
&lt;p&gt;&amp;gt; If a particular frame happens to take unusually &lt;/p&gt;
&lt;p&gt;&amp;gt; long, we automatically call Update some extra &lt;/p&gt;
&lt;p&gt;&amp;gt; times to catch up, after which everything carries &lt;/p&gt;
&lt;p&gt;&amp;gt; on as normal. The player may notice a slight&lt;/p&gt;
&lt;p&gt;&amp;gt; glitch, but we automatically correct for this&lt;/p&gt;
&lt;p&gt;&amp;gt; to minimize the impact. &lt;/p&gt;
&lt;p&gt;Does this mean you keep a list of the last x frame times and pass us the average?&lt;/p&gt;
&lt;p&gt;Currently I'm setting Game.IsFixedTimeStep = false and handling the fixed physics myself. &amp;nbsp;I have to do some interpolation between last state and current state in Draw to get smooth animation. &amp;nbsp;It all works but I'm not sure if it's overkill. &amp;nbsp;It does isolate me from monitor frequencies, syncing to refresh, etc though.&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4074635</link><pubDate>Fri, 27 Jul 2007 07:32:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4074635</guid><dc:creator>Rim</dc:creator><description>&lt;p&gt;&amp;gt; At the moment we sometimes call draw more &lt;/p&gt;
&lt;p&gt;&amp;gt; often than we really should (there's not &lt;/p&gt;
&lt;p&gt;&amp;gt; really any point calling it twice if we &lt;/p&gt;
&lt;p&gt;&amp;gt; didn't do an update in between, since it will&lt;/p&gt;
&lt;p&gt;&amp;gt; just be drawing the same thing again!). This &lt;/p&gt;
&lt;p&gt;&amp;gt; is likely to change in future versions.&lt;/p&gt;
&lt;p&gt;Well, there actually is, if you consider VSyncing to prevent tearing a good reason. I always thought this was an exaggerated problem, but VSync does seem to make a difference in quality on my crappy Dell monitor.&lt;/p&gt;
&lt;p&gt;Regardless, in my not-so-humble opinion I don't think it would be a good idea to change this behavior. As the need for your post indicates, the time handling is complicated enough as is. If the actual drawing frequency would be limited by the update interval, this might lead to more confusion (VSync already spawned countless topics of &amp;quot;I can't get my FPS above 60&amp;quot;) and it would effectively render DX VSync useless in most fixed timestep scenarios.&lt;/p&gt;
&lt;p&gt;Not drawing if nothing changed might be the smart thing to do, but it should make little difference as long as you can maintain your target rendering framerate anyway. If I can afford to draw at 75 FPS, why would I want to be limited by a fixed timestep that I typically only want to apply to the simulation/update? &lt;/p&gt;
&lt;p&gt;Just my 2 cents though :)&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4082432</link><pubDate>Fri, 27 Jul 2007 18:54:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4082432</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;&amp;gt; Not drawing if nothing changed might be the &lt;/p&gt;
&lt;p&gt;&amp;gt; smart thing to do, but it should make little &lt;/p&gt;
&lt;p&gt;&amp;gt; difference as long as you can maintain your &lt;/p&gt;
&lt;p&gt;&amp;gt; target rendering framerate anyway. If I can &lt;/p&gt;
&lt;p&gt;&amp;gt; afford to draw at 75 FPS, why would I want to &lt;/p&gt;
&lt;p&gt;&amp;gt; be limited by a fixed timestep that I typically&lt;/p&gt;
&lt;p&gt;&amp;gt; only want to apply to the simulation/update?&lt;/p&gt;
&lt;p&gt;Little difference, yes (the implementation in the framework today works fine in practice) but even a little difference is still a difference, and if it is possible to make even a little improvement, surely that's worth doing? :-)&lt;/p&gt;
&lt;p&gt;Think of it this way: if an Update + Draw cycle completes within the alloted timespan, you have the choice of calling Draw again, or waiting doing nothing for the timespan to expire. What difference does this choice make to anything?&lt;/p&gt;
&lt;p&gt;On the surface, nothing. Calling Draw twice without an Update in between should (if the game is programmed correctly) render exactly the same thing again, so the user will see no visible difference at all (the only time this could render something different is if the game was doing some kind of clever interpolation in their Draw method, but in that case they really ought to be using variable timestep mode in the first place).&lt;/p&gt;
&lt;p&gt;There are in fact exactly two ways in which calling Draw again can make a difference:&lt;/p&gt;
&lt;p&gt;1: This may affect the figures reported by framerate measuring programs. I think this is kind of a bogus argument, though, because giving yourself a fake FPS boost by calling Draw without Update is really cheating! If people are trying to measure their game performance using these FPS counters, they have other problems because FPS isn't really a suitable way to measure such things in the first place (that's a whole other topic :-)&lt;/p&gt;
&lt;p&gt;2: Waiting is interruptible, but Draw is not. This is the biggie. Consider a game that runs just over 60 fps. Update + Draw completes, and there are a few milliseconds left over, so we call Draw again. Now the timespan expires, but the game is in the middle of Draw, so we have to wait for Draw to complete before we can go back to Update. This could put us significantly behind where we want to be (although always less than an entire frame). The error will be corrected over the next couple of frames as we call Update + Draw in sequence, using the leftover time to make up for what we lost by the extra Draw. There is no actual dropped frame here (we never have to call Update twice in a row without a Draw) but there is a lack of smoothness in our Update calls: we have a biggish gap between two of them, followed by a sequence closer together, then another biggish gap, etc. This is why it would be better to just wait: that way Update can be called at exactly the right time, and will always be perfectly evenly spaced.&lt;/p&gt;
&lt;p&gt;Does this actually make a noticeable difference? Probably not. But I'm a perfectionist.&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4100850</link><pubDate>Sat, 28 Jul 2007 15:56:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4100850</guid><dc:creator>zygote</dc:creator><description>&lt;p&gt;Awesome work as usual Shawn :)&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4101860</link><pubDate>Sat, 28 Jul 2007 17:28:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4101860</guid><dc:creator>X-Tatic</dc:creator><description>&lt;p&gt;Some good points covered here Shawn. Keep 'em coming, good stuff.&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4104783</link><pubDate>Sat, 28 Jul 2007 21:58:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4104783</guid><dc:creator>Ultrahead</dc:creator><description>&lt;p&gt;&amp;quot;Running some parts of your update logic less often than others is a great way to make games more efficient. For instance pathfinding and AI often only need to be updated a couple of times a second. Once you have found a good path or made the decision to attack, you can follow that decision without having to repeat the entire original calculation on each update.&amp;quot;&lt;/p&gt;
&lt;p&gt;Great advice.&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4108097</link><pubDate>Sun, 29 Jul 2007 00:09:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4108097</guid><dc:creator>Zingam</dc:creator><description>&lt;p&gt;It would be great if you write also about proper performance counters like FPS counter, frame time counter etc... in the context of the above text.&lt;/p&gt;
&lt;p&gt;Thank you!&lt;/p&gt;
</description></item><item><title>re: Understanding GameTime</title><link>http://blogs.msdn.com/shawnhar/archive/2007/07/25/understanding-gametime.aspx#4126941</link><pubDate>Mon, 30 Jul 2007 10:12:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4126941</guid><dc:creator>Rim</dc:creator><description>&lt;p&gt;Allow me to respond :)&lt;/p&gt;
&lt;p&gt;&amp;gt; 1: This may affect the figures reported by &lt;/p&gt;
&lt;p&gt;&amp;gt; framerate measuring programs. I think this is &lt;/p&gt;
&lt;p&gt;&amp;gt; kind of a bogus argument, though, because &lt;/p&gt;
&lt;p&gt;&amp;gt; giving yourself a fake FPS boost by calling &lt;/p&gt;
&lt;p&gt;&amp;gt; Draw without Update is really cheating!&lt;/p&gt;
&lt;p&gt;I beg to differ. This may hold true if you knowingly rig your update scheme to do this, but who in their right minds is going to cheat themselves to get a fictive performance boost? The main reasons I like this behavior is:&lt;/p&gt;
&lt;p&gt;1. It's predictable&lt;/p&gt;
&lt;p&gt;2. It helps budget your draw performance&lt;/p&gt;
&lt;p&gt;During development we disable VSync so the drawing runs at max speed and we can get a better idea of how the performance of the rendering code is holding up. By chaining the drawing together with the updating, it seems to me it gets harder to get a straightforward idea of the performance. Yes, yes, you might argue we should profile (and not use the hyperbolically distrubted framerate anyway), but I think a profiler is no excuse for introducing needlessly complex behavior.&lt;/p&gt;
&lt;p&gt;&amp;gt; 2: Waiting is interruptible, but Draw is not. &lt;/p&gt;
&lt;p&gt;&amp;gt; This is the biggie. Consider a game that runs &lt;/p&gt;
&lt;p&gt;&amp;gt; just over 60 fps. Update + Draw completes, &lt;/p&gt;
&lt;p&gt;&amp;gt; and there are a few milliseconds left over, &lt;/p&gt;
&lt;p&gt;&amp;gt; so we call Draw again. Now the timespan &lt;/p&gt;
&lt;p&gt;&amp;gt; expires, but the game is in the middle of &lt;/p&gt;
&lt;p&gt;&amp;gt; Draw, so we have to wait for Draw to complete &lt;/p&gt;
&lt;p&gt;&amp;gt; before we can go back to Update. This could &lt;/p&gt;
&lt;p&gt;&amp;gt; put us significantly behind&lt;/p&gt;
&lt;p&gt;True, but isn't this already an unfortunate side-effect of the current smart update/draw scheme? I appreciate the efforts put into XNA to keep the game running smoothly, but at some point you'll have to draw the line and give up on trying to fix unperformant code. It might be a better idea to confront XNA coders straight up when their performance is going down the drain instead of keeping them in the dark with smart tricks until they hit a wall.&lt;/p&gt;
&lt;p&gt;&amp;gt; Does this actually make a noticeable &lt;/p&gt;
&lt;p&gt;&amp;gt; difference? Probably not. But I'm a &lt;/p&gt;
&lt;p&gt;&amp;gt; perfectionist.&lt;/p&gt;
&lt;p&gt;Commendable, but why sacrifice transparency and predictability for the sake of unnoticable perfection? :)&lt;/p&gt;
</description></item></channel></rss>