module lib.sdl2.timer

Code Map

module lib.sdl2.timer;


//! Function prototype for the timer callback function.
alias SDL_TimerCallback = fn (Uint32, void*) (Uint32);
//! Definition of the timer ID type.
alias SDL_TimerID = i32;

//! \brief Get the number of milliseconds since the SDL library
//! initialization.
fn SDL_GetTicks() Uint32;
//! \brief Get the current value of the high resolution counter
fn SDL_GetPerformanceCounter() Uint64;
//! \brief Get the count per second of the high resolution counter
fn SDL_GetPerformanceFrequency() Uint64;
//! \brief Wait a specified number of milliseconds before returning.
fn SDL_Delay(ms: Uint32);
//! \brief Add a new timer to the pool of timers already running.
fn SDL_AddTimer(interval: Uint32, callback: SDL_TimerCallback, param: void*) SDL_TimerID;
//! \brief Remove a timer knowing its ID.
fn SDL_RemoveTimer(id: SDL_TimerID) SDL_bool;
fn SDL_GetTicks() Uint32

\brief Get the number of milliseconds since the SDL library initialization.

\note This value wraps if the program runs for more than ~49 days.

fn SDL_GetPerformanceCounter() Uint64

\brief Get the current value of the high resolution counter

fn SDL_GetPerformanceFrequency() Uint64

\brief Get the count per second of the high resolution counter

fn SDL_Delay(ms: Uint32)

\brief Wait a specified number of milliseconds before returning.

alias SDL_TimerCallback

Function prototype for the timer callback function.

The callback function is passed the current timer interval and returns the next timer interval. If the returned value is the same as the one passed in, the periodic alarm continues, otherwise a new alarm is scheduled. If the callback returns 0, the periodic alarm is cancelled.

alias SDL_TimerID

Definition of the timer ID type.

fn SDL_AddTimer(interval: Uint32, callback: SDL_TimerCallback, param: void*) SDL_TimerID

\brief Add a new timer to the pool of timers already running.

\return A timer ID, or NULL when an error occurs.

fn SDL_RemoveTimer(id: SDL_TimerID) SDL_bool

\brief Remove a timer knowing its ID.

\return A boolean value indicating success or failure.

\warning It is not safe to remove a timer multiple times.