lime icon indicating copy to clipboard operation
lime copied to clipboard

SDL_GetTicks Noticeably Imprecise

Open steviegt6 opened this issue 2 years ago • 41 comments

SDL_GetTicks is only accurate to the millisecond, which results in deltaTime values being rather imprecise. This is immediately observable in the FPS display, which is inaccurate by a couple frames: image

In other words, if you have an application running at 60 fps, you would expect a delta time of roughly 1666 (1000 / 60 = 16.66667) at least, but you're instead just given 16.

A piece of the relevant code (SDL_GetTicks is used in several relevant places in this file): https://github.com/openfl/lime/blob/862fe55b1cf567bdfb4ada7d5bc78be36353f9e6/project/src/backend/sdl/SDLApplication.cpp#L132

steviegt6 avatar Jul 26 '22 10:07 steviegt6

How interesting, I might fix this in a private repository of mine

EyeDaleHim avatar Jul 26 '22 10:07 EyeDaleHim

For reference: In Flash, which OpenFL is based on, the only option for timing is flash.utils.getTimer(), which also has millisecond accuracy.

joshtynjala avatar Jul 26 '22 15:07 joshtynjala

I thought this only affected the frame rate counter, but the event loop delta is actually wrong due to this. Perhaps we should implement the timing for the main loop like Starling and use a float. I will look into this more.

Dimensionscape avatar Jul 26 '22 16:07 Dimensionscape

I will look into this more.

Sounds good. I hope that you'll wait to commit until after OpenFL 9.2 is released. This sounds like something that should be in dev builds for a while, just to ensure that there aren't any unintended side effects.

joshtynjala avatar Jul 26 '22 16:07 joshtynjala

No worries there. The event loop is a critical, core component obviously and any changes should be carefully considered and well tested. There's not enough time to even attempt to fit it into the next release even if I wanted to try. 😂

Dimensionscape avatar Jul 26 '22 16:07 Dimensionscape