Log In  

Cart #52208 | 2018-05-01 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

An example implementation of automatically-calculated delta time in Pico-8, allowing for framerate-independent game logic.
It's not much to look at, but a detailed description is available in the code comments.

Example use case:
You've built a project targeting 30FPS, but it turns out to be optimized enough to run at 60FPS.

Normally, switching from using _update to _update60 after the fact would be a painful job involving a lot of manual number editing, and you'd be screwed. However, if you had built your project with delta time in mind from the start, you could simply rename and everything will continue to move at the 'correct' rate.

P#52209 2018-04-30 20:19 ( Edited 2018-05-01 19:30)

:: Davbo

Nice! I nver know which I should use when I start then get parranoyed through the whole of development I should be using the other so the ability to change after the fact is invaluable. Will defo use for my next project!

P#52218 2018-05-01 04:14 ( Edited 2018-05-01 08:14)
:: Felice

This is a very useful tool to have in your arsenal, but I do want to point out a gotcha which is sometimes overlooked in specific cases:

When you go variable-DT, you lose the ability to be repeatably deterministic. This is fine for most games, but any game with a replay system or, perhaps, a multiplayer game that assumes both ends are computing the same derived values from the small amount of data that's communicated across a network, it can be an issue. It's very common for math applied two times to be different from math applied twice as hard, due to precision issues.

I'm only bringing this up so you're all aware of this gotcha IF you're writing such a game. Otherwise, this is definitely something you wan to be familiar with. Even in a deterministic game where, say, you have replays, you'll still have tons of non-critical systems that can run on variable DTs, e.g. particles, weather, sfx, etc.

It can be especially important to pay attention to random seeds. Most people just call an API function like rnd() without thinking twice, but if the pattern of calls to rnd() change due to variable DT, that's another possible source of deviation from the expected behavior of, say, a replay. So it's common to have separate random seeds for the deterministic stuff and the variable stuff.

P#52220 2018-05-01 08:15 ( Edited 2018-05-01 12:20)

This is fantastic, thank you! I have a delta time implementation but it doesn't work when switching update functions ... this will be great!

P#52238 2018-05-01 15:30 ( Edited 2018-05-01 19:30)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-06-04 06:07 | 0.017s | 2097k | Q:32