SDL Wiki
(This is the legacy documentation for SDL2, the previous stable version; SDL3 is the current stable version.)

SDL_TICKS_PASSED

Compare 32-bit SDL ticks values, and return true if A has passed B.

Header File

Defined in SDL_timer.h

Syntax

#define SDL_TICKS_PASSED(A, B)  ((Sint32)((B) - (A)) <= 0)

Remarks

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).


CategoryAPI, CategoryAPIMacro, CategoryTimer


[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.