Smoothing Delta Timing

Miscellaneous Forums/General Discussion/Smoothing Delta Timing

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Grey:
What my code does keep track of the frame times for all frames over the last 125 milliseconds, and then delay the current frame so that it takes as long to render as the longest time a frame took to render in that timespan.

In other words, if the current frame took 20ms to render, and five frames were rendered over the last 125 milliseconds, and the last five frames had times of [25, 20, 20, 20, 20] then the current frame would be delayed for 5 milliseconds, and the array of frame times would be updated to read [20, 25, 20, 20, 20].

Note that that 25 there has to move off the right side before any frame will take less than 25ms to complete, and the times stored in the array are the actual real times each frame took to render.

So with this setup, the system reponds instantly to drops in framerates, and speeds back up after 125ms if the framerate goes back up. This keeps the framerate smooth, but doesn't cause the action to go all choppy for a really long period of time if there's a framerate glitch and one frame takes a really long time to render. (Note that with my timing loop, any frame that takes over a quarter of a second is ignored, to handle alt-tabbing and other things that cause framerate glitches.)