Anyone have information on the resolution of the d...
# coroutines
p
Anyone have information on the resolution of the delay() function? I'm trying to make a game loop (needs sub 16ms precision) but seems it is not deterministic when providing low values like delay(10) is it even a per platform thing on KMP depending on resolution capabilities of OS ?
e
it is platform-dependent
for windows specifically, https://github.com/io7m-com/timehack6435126 tries to trick the JVM into using higher-resolution timers
p
Ah i see... Is there like a common approach for this use case on KMP? I mean idling with more precissionor should i relay on busy waiting?
At the moment wathever delay(3 to 16) gives always >30 ms delays
e
not as far as I know. you'll probably have to use platform-specific APIs to get more accurate timers
also increasing timer resolution on Windows changes it system-wide, causing all apps to use more power, and also triggers a bug in earlier versions which causes the system clock to run too fast… it's a mess
k
Note that delay will delay for at least the specified amount of time
You're probably reaching for the wrong tool if you need high precision timing
e
it will delay for at least that amount of time, but it's not necessarily synchronized with currentTimeMillis or any other clock, so it's possible to observe what appear to be shorter delays
p
ok thank for the info!
k
It might be worth researching how other game engines tick. For example, I doubt Godot or Unity use thread parking to govern their game loop (but also I don't know anything about game Dev)
e
I assume games will use WinMM (they need to handle audio anyway)
k
I do vaguely remember from watching someone create super Mario world in Godot that the game loop gives you a delta amount of time that occurred from the last tick and you use that in all of your physics calculations
p
quite interesting you mention mario world hehe... Its precisely what the emulator have loaded...
just (land)
imagen.png
Anyway... i will try to fine tune my main loop thanks for all the info!
k
Just poking around it looks like it uses delay for one reason — if the current frame was rendered faster than 16.66ms then delay for the remainder. There’s a few issues with this code I can notice immediately: notably it’s using
Clock.System
instead of a monotonic TimeSource, and I’m still wary that delay would provide the amount of precision necessary for a game loop.
p
yeah it doesnt its precisely the problem im having