<p>After working for a while developing games, I've been exposed to both variable frame rates (where you work out how much time has passed since the last tick and update actor movement accordingly) and fixed frame rates (where you work out how much time has passed and choose either to tick a fixed amount of time or sleep until the next window comes).</p>

<p>Which method works best for specific situations? Please consider:</p>

<ul>
<li>Catering to different system specifications;</li>
<li>Ease of development/maintenance;</li>
<li>Ease of porting;</li>
<li>Final performance.</li>
</ul>

[{'answer_id': 53204, 'author': 'jwarzech', 'author_id': 3111, 'author_profile': 'https://Stackoverflow.com/users/3111', 'pm_score': 0, 'selected': False, 'text': '<p>My experience is fairly limited to somewhat simple games (developed with SDL and C++) but I have found that it is quite easy just to implement a static frame rate.  Are you working with 2d or 3d games?  I would assume that more complex 3d environments would benefit more from a variable frame rate and that the difficulty would be greater.</p>\n'}, {'answer_id': 53210, 'author': 'Jacob Rigby', 'author_id': 5357, 'author_profile': 'https://Stackoverflow.com/users/5357', 'pm_score': 3, 'selected': True, 'text': "<p>It seems that most 3D developers prefer variable FPS: the Quake, Doom and Unreal engines both scale up and down based on system performance.</p>\n\n<ul>\n<li>At the very least you have to compensate for too fast frame rates (unlike 80's games running in the 90's, way too fast)</li>\n<li>Your main loop should be parameterized by the timestep anyhow, and as long as it's not too long, a decent integrator like RK4 should handle the physics smoothly  Some types of animation (keyframed sprites) could be a pain to parameterize.  Network code will need to be smart as well, to avoid players with faster machines from shooting too many bullets for example, but this kind of throttling will need to be done for latency compensation anyhow (the animation parameterization would help hide network lag too)</li>\n<li>The timing code will need to be modified for each platform, but it's a small localized change (though some systems make extremely accurate timing difficult, Windows, Mac, Linux seem ok)</li>\n<li>Variable frame rates allow for maximum performance. Fixed frame rates allow for consistent performance but will never reach max on all systems (that's seems to be a show stopper for any serious game)</li>\n</ul>\n\n<p>If you are writing a networked 3D game where performance matters I'd have to say, bite the bullet and implement variable frame rates.  </p>\n\n<p>If it's a 2D puzzle game you probably can get away with a fixed frame rate, maybe slightly parameterized for super slow computers and next years models.</p>\n"}, {'answer_id': 53217, 'author': 'theorbtwo', 'author_id': 4839, 'author_profile': 'https://Stackoverflow.com/users/4839', 'pm_score': 2, 'selected': False, 'text': "<p>One option that I, as a user, would like to see more often is dynamically changing the level of detail (in the broad sense, not just the technical sense) when framerates vary outside of a certian envelope.  If you are rendering at 5FPS, then turn off bump-mapping.  If you are rendering at 90FPS, increase the bells and whistles a bit, and give the user some prettier images to waste their CPU and GPU with.  </p>\n\n<p>If done right, the user should get the best experince out of the game without having to go into the settings screen and tweak themselves, and you should have to worry less, as a level designer, about keeping the polygon count the same across difference scenes.</p>\n\n<p>Of course, I say this as a user of games, and not a serious one at that -- I've never attempted to write a nontrivial game.</p>\n"}, {'answer_id': 59512, 'author': 'Paul', 'author_id': 5841, 'author_profile': 'https://Stackoverflow.com/users/5841', 'pm_score': 3, 'selected': False, 'text': '<p>I lean towards a variable framerate model, but internally some systems are ticked on a fixed timestep. This is quite easy to do by using a time accumulator. Physics is one system which is best run on a fixed timestep, and ticked multiple times per frame if necessary to avoid a loss in stability and keep the simulation smooth.</p>\n\n<p>A bit of code to demonstrate the use of an accumulator:</p>\n\n<pre><code>const float STEP = 60.f / 1000.f;\nfloat accumulator = 0.f;\n\nvoid Update(float delta)\n{\n    accumulator += delta;\n\n    while(accumulator &gt; STEP)\n    {\n        Simulate(STEP);\n        accumulator -= STEP;\n    }\n}\n</code></pre>\n\n<p>This is not perfect by any means but presents the basic idea - there are many ways to improve on this model. Obviously there are issues to be sorted out when the input framerate is obscenely slow. However, the big advantage is that no matter how fast or slow the delta is, the simulation is moving at a smooth rate in "player time" - which is where any problems will be perceived by the user.</p>\n\n<p>Generally I don\'t get into the graphics &amp; audio side of things, but I don\'t think they are affected as much as Physics, input and network code.</p>\n'}, {'answer_id': 75256, 'author': 'Don Neufeld', 'author_id': 13097, 'author_profile': 'https://Stackoverflow.com/users/13097', 'pm_score': 2, 'selected': False, 'text': "<p>The main problem I've encountered with variable length frame times is floating point precision, and variable frame times can surprise you in how they bite you.</p>\n\n<p>If, for example, you're adding the frame time * velocity to a position, and frame time gets very small, and position is largish, your objects can slow down or stop moving because all your delta was lost due to precision.  You can compensate for this using a separate error accumulator, but it's a pain.</p>\n\n<p>Having fixed (or at least a lower bound on frame length) frame times allows you to control how much FP error you need to take into account.</p>\n"}]
['https://Stackoverflow.com/questions/53164', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5488/']