Compare 32-bit SDL ticks values, and return true if A
has passed B
.
Defined in SDL_timer.h
#define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0)
This should be used with results from SDL_GetTicks(), as this macro attempts to deal with the 32-bit counter wrapping back to zero every ~49 days, but should not be used with SDL_GetTicks64(), which does not have that problem.
For example, with SDL_GetTicks(), if you want to wait 100 ms, you could do this:
const Uint32 timeout = SDL_GetTicks() + 100;
while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) {
// ... do work until timeout has elapsed
}
Note that this does not handle tick differences greater than 2^31 so take care when using the above kind of code with large timeout delays (tens of days).