SDL_AddTimerNS(3)
β¨ SDL_AddTimerNS(3) β¨
okay bestie, we're in the SDL3 FUNCTIONS section today and this one is literally so fun β it's giving "set an alarm for future me" energy π«Ά
πΈ NAME πΈ
SDL_AddTimerNS β call a callback function at a future time. no cap, that's the whole vibe π
π SYNOPSIS π
#include <SDL3/SDL_timer.h>
SDL_TimerID SDL_AddTimerNS(Uint64 interval, SDL_NSTimerCallback callback, void *userdata);
π¦ DESCRIPTION π¦
so here's the tea β β your callback function gets handed the current timer interval and the userdata pointer you passed in when you called SDL_AddTimerNS(). and then it has to return the next timer interval. and if the value it returns is 0? yeah, the timer is canceled and will be removed. gone. bye. π
the callback runs on a separate thread, which is iconic of it. and heads up: for short timeouts, it can potentially be called before this function even returns. like it's that fast, she's an overachiever π§
now, timers take into account how long the callback itself took to execute. for example β if the callback took 250 ns to execute and returned 1000 (ns), the timer would only wait another 750 ns before its next iteration. math ate that one, fr fr π₯
timing may be inexact due to OS scheduling. so be sure to note the current time with SDL_GetTicksNS() or SDL_GetPerformanceCounter() in case your callback needs to adjust for variances. iykyk π
π FUNCTION PARAMETERS π
intervalβ the timer delay, in nanoseconds, passed to callback. β±οΈcallbackβ theSDL_TimerCallbackfunction 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 π β and if it fails you gotta call SDL_GetError() for more information, that's where the lore lives.
π THREAD SAFETY π
it is safe to call this function from any thread. go off, multitasking queen π
π AVAILABILITY π
this function is available since SDL 3.2.0. vintage-ish but still fresh β¨
π SEE ALSO π
and that's the whole page bestie!! π brought to you by Simple Directmedia Layer, version SDL 3.4.18, dated SDL_AddTimerNS(3) β mwah, slay, periodt πβ¨π«Ά
π¦ 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