Delta Times | Patreon Weekly #316
Added 2025-06-23 14:00:11 +0000 UTCHey Patrons, in this weekly I’m going to go over one of the technical changes I made in v3.1.1.
There’s also a new Shattered Secrets this week! In this secrets I’m going to go over some concepting I’ve done to make sources of accuracy and evasion more visible.
Delta Times
Shattered Pixel Dungeon supports variable framerates, like most modern games. That means determining how much real time has passed between each frame drawn and updating animations accordingly. This time is usually referred to as the delta time, and using it properly means that the game naturally compensates for how fast frames are being drawn and two users at different framerates get roughly the same experience. Older or poorly written games often used a fixed delta time, which means that the whole game runs faster/slower depending on how high/low the framerate is.
Shattered is pretty lightweight, so usually devices will run it at least at 60 fps on average, but that isn’t guaranteed. In particular, if a device has lots of other work it’s doing, sometimes there can be noticeable hitches in between frames, even if the average is still pretty high.
One user reported some issues to me a couple weeks ago, which occurred while they were streaming Shattered, causing them to semi-frequently get 2+ second hitches while playing. This caused some very weird things, which as far as I can tell occurred because animations like attacking were completely processing twice within a single frame update, leading to things like double attacks!
There’s a lot of ways to get fancy with delta time if you want to be, but in this case I decided to be pretty quick about it and implemented a simple fix: delta time now cannot exceed 200ms. This means that if the device massively hitches, the game will slow itself down and only process 1/5 of a second at once. This can result in slowdown for the user, but I think it’s pretty reasonable to expect devices to be able to play the game at above 5 fps on average. Hopefully this will increase overall stability, and pre-emptively fix a variety of exceedingly rare animation issues.
Comments
It's hard to say what crashes over the years may or may not have been caused by this. Even now I'm just making some assumptions about double attacks here based on the code and the report I got, I wasn't actually able to reproduce it. Regardless though very high delta times might be the cause of lots of rare instability, and so reducing the max is definitely a good thing.
Shattered Pixel
2025-06-24 15:55:03 +0000 UTCDid you ever get double interact crashes with gnoll geomancer? I got that a few times during rkpd2 development, when I was using a lot of memory on my device, and I was wondering if that was related
Zrp200
2025-06-23 19:26:51 +0000 UTC