Logging & timeSDL 3.2
SDL_DelayNS
Sleeps for at least the given number of nanoseconds.
Signature
void SDL_DelayNS(Uint64 ns);
How it works
The thread gives the CPU back to the system for that long. "At least": the operating system wakes it when it gets around to it, which can be a millisecond or more late on some systems.
Use it to cap the frame rate when vsync is off, or to wait politely in a tool. SDL_Delay takes milliseconds; SDL_DelayPrecise spins for the last bit to be more exact, at the cost of some CPU.
Parameters
nsUint64
How long to sleep, in nanoseconds (1 ms = 1'000'000 ns). SDL_MS_TO_NS(ms) converts.
Example
example.cpp
1// cap at 120 fps without vsync
2const Uint64 frameNS = 1'000'000'000 / 120;
3Uint64 used = SDL_GetTicksNS() - frameStart;
4if (used < frameNS) SDL_DelayNS(frameNS - used);