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 with SDL_GetTicksNS() or SDL_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 to callback. ⏱️
  • callback β€” the SDL_TimerCallback function to call when the specified interval elapses. πŸ“ž
  • userdata β€” a pointer that is passed to callback. 🫢

πŸ’… 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