Improved implementation of SDL_DelayPrecise() (thanks @nightmareci!)

Fixes https://github.com/libsdl-org/SDL/issues/10592
This commit is contained in:
Sam Lantinga 2024-10-11 20:31:28 -07:00
parent 25251a9405
commit c5904d8710
2 changed files with 65 additions and 14 deletions

View file

@ -213,7 +213,7 @@ int main(int argc, char *argv[])
Uint64 total_overslept = 0;
start = SDL_GetTicksNS();
SDL_DelayNS(1);
SDL_DelayPrecise(1);
now = SDL_GetTicksNS();
actual_delay = (now - start);
SDL_Log("Minimum precise delay: %" SDL_PRIu64 " ns\n", actual_delay);
@ -221,7 +221,7 @@ int main(int argc, char *argv[])
SDL_Log("Timing 100 frames at 60 FPS\n");
for (i = 0; i < 100; ++i) {
start = SDL_GetTicksNS();
SDL_DelayNS(desired_delay);
SDL_DelayPrecise(desired_delay);
now = SDL_GetTicksNS();
actual_delay = (now - start);
if (actual_delay > desired_delay) {