SDL_AddTimer(3)
π SDL_AddTimer(3) π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual β this is the page for SDL_AddTimer, and it's literally the "hey can you come back and do this again later" function. group chat energy: it's giving β° scheduled callback realness β°.
β¨ NAME β¨
SDL_AddTimer β Call a callback function at a future time.
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_timer.h>
SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *userdata);
π¦ DESCRIPTION π¦
So here's the tea π: the callback function gets handed the current timer interval and the user-supplied parameter you passed into the SDL_AddTimer() call, and it's supposed to return the next timer interval. And if the value the callback returns is 0? π that's the signal β the timer is canceled and will be removed. bye girl π.
The callback runs on a separate thread, and for short timeouts it can potentially be called before this function even returns. yes fr fr, it's that fast. no cap.
Timers take into account the amount of time it took to execute the callback. For example, if the callback took 250 ms to execute and returned 1000 (ms), the timer would only wait another 750 ms before its next iteration. math queen behavior π.
Timing may be inexact due to OS scheduling. Be sure to note the current time withSDL_GetTicksNS()orSDL_GetPerformanceCounter()in case your callback needs to adjust for variances. β οΈ don't skip this part bestie, the OS is out here vibing on its own schedule.
π FUNCTION PARAMETERS π
intervalβ the timer delay, in milliseconds, passed tocallback. β±οΈcallbackβ theSDL_TimerCallbackfunction to call when the specifiedintervalelapses. πuserdataβ a pointer that is passed tocallback. π«Ά
π RETURN VALUE π
Returns a timer ID, or 0 on failure. if it flops, call SDL_GetError() for more information. π
π₯ THREAD SAFETY π₯
It is safe to call this function from any thread. iconic, no notes β¨
π AVAILABILITY π
This function is available since SDL 3.2.0. β
π SEE ALSO π
mwah π that's the whole page, you ate it, periodt. This lil manual moment came to you from Simple Directmedia Layer, running SDL 3.4.18, and the page itself goes by SDL_AddTimer(3) β go forth and schedule something cute π§π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms