Fixed Rate Logic and Delta Time Combo

Someone asked on the Blitz forum how I run my game logic and as I’ve been asked a few times I thought it made sense to post it here:

So I’m drawing with VSync and after the draw I take a time reading in BlitzMax with Millisecs() and compare it with the previous time reading (before the last logic/draw cycle). Then I work out how many fixed rate logic iterations to call based on the time reading (normally about 3 as I run logic at 200Hz). However there is always a fractional component e.g. Time Difference = 16.67ms, logic iteration time = 5m, so that’s 3.34 logic iterations needing doing. I run the first three logic iterations with a Delta of 1 (whole number) and the last with a delta of 0.34. All my objects/counters/anims etc move by delta. Then I draw it. Simple really.

The high resolution logic works great for collisions and receiving input snappily and gives very smooth animations with VSync on or off, and it allows me to do slow motion by tweaking the params. If people play to level 7 in my new game (due Feb 6th 2009) they’ll see it in action.

4 Responses to “Fixed Rate Logic and Delta Time Combo”

  1. JC Says:

    This is weird that your logic is running as such a high rates. Usually, we have the game logic running at something like 10FPS and rendering running has at much as possible. So, we might have to interpolate object position between 2 frame logic. But it looks like your are doing the exact opposite. Why does your logic has to run as such a high frequency?


  2. Grey Alien Games Says:

    So you are doing Render Tweening right? I’m just taking part in a big thread about this on the Blitzmax forums. I’m using the high FPS to make collisions really reliable (don’t need special path tracing at that rate) and input very responsive and to simplify my rendering code (simply draw at x,y, no tweening required). I got the idea from an old thread on the Dexterity Forums where several people (including Steve Pavlina and Mike Boeh of Retro64) were using the high logic method. It works for me as my games are not logic intensive. If I did render tweening I’d need to rethink a whole load of things and also I’d probably run that at least 30fps.

  3. JC Says:

    Well, if it works for you… No reason to change it. But if your games in the future becomes AI intensive, like 1000’s of people running around… You might want to change it 😉

    While I was working on retail AAA games like B&W and the Movies (witch are very logic intensive), We did render the logic at 10FPS. The physics & collision at 100FPS and what was possible (and left) for the rendering. The input was on high FPS too. It is not more complicated than what you are doing now, just different….


  4. Grey Alien Games Says:

    Very interesting thanks. Yeah if I make a sim game or something I may well have to alter it.