New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smoothed Delta times on Android and overall improvements #6228
Comments
I agree that it doesn't make any sense to have this on Android only, and that the current smoothing algorithm could be improved. I would prefer a simple clamping of the delta time, a common suggestion for libgdx games (related: #6093, but there was also a lot of forum and discord talk on this because such a clamp is needed on desktop if the window is resized). Given the problem that many internal methods use |
Yep, I think we should remove the smoothing in the Android backend and change the javadoc accordingly. It should also be mentioned that clamping may happen (at least on mobile platforms).
That sounds like a good idea that allows for minimal changes in libGDX. |
Graphics
has 2 different methods to get delta time,float getDeltaTime()
andfloat getRawDeltaTime();
. According to java docs, the difference is thatgetDeltaTime()
"Might be smoothed over n frames.".Checking all backend
Graphics
implementations, the only backend that does smoothing on the delta is the Android backend, that applies a simple size 5 window mean. This is probably due to legacy reasons when libGDX was created some Android devices were really unrealiable (we're talking Android 1.5 or 1.6) and my guess is that this was a workaround for those old devices with very inconsistent delta times.Averaging the delta over 5 frames has a significant impact on how the game behaves during lag spikes. Let me show with an example.
Imagine we have the following sequence of Raw delta times
1/60 1/60 1/60 1/60 1/60 1/5 1/60 1/60 1/60 1/60 1/60
In every backend except from Android, in a typical setup in which delta is capped to 1/30 (Scene2D does that by default) the resulting deltas used by the game would be
1/60 1/60 1/60 1/60 1/60 1/30 1/60 1/60 1/60 1/60 1/60 1/60
In which only the 1/30 frame would have a "slow motion" distortion caused due to real elapsed time being higher than delta time
On Android, on the other hand, we would get
1/60 1/60 1/60 1/60 1/60 1/30 1/30 1/30 1/30 1/30 1/60
In which the first 1/30 frame would be distorted exactly like before but the next 4 1/30 ones they would be "fast forward" (as if it was catching up).
Understanding that
I think there are several things of this design decision that are worth revisiting:
getDeltaTime()
is used across libGDX code base by different systems to get the delta time (with calls toGdx.graphics.getDeltaTime()
). This means that, even if a user didn't want the smoothed delta to be used on his game, some parts of libGDX (from Scene2D to particles among others) would still use the smoothed one causing unpredictable issues.getDeltaTime()
to return raw delta time and add agetSmoothedDeltaTime()
(Unity has something on these lines).The text was updated successfully, but these errors were encountered: