4#include <SDL3/SDL_timer.h>
5#include "SDL3pp_stdinc.h"
33 return SDL_NS_TO_SECONDS(m_time.count());
51 return std::chrono::nanoseconds(SDL_GetTicksNS());
113 return SDL_GetPerformanceFrequency();
149inline void Delay(std::chrono::nanoseconds duration)
151 SDL_DelayNS(duration.count());
210 SDL_DelayPrecise(duration.count());
305 template<std::invocable<TimerID, std::chrono::nanoseconds> F>
312 template<std::invocable<TimerID, std::chrono::nanoseconds> F>
315 return func(timerID, std::chrono::nanoseconds(interval)).count();
357 return SDL_AddTimer(
Uint32(interval.count()), callback, userdata);
399 return CheckError(SDL_AddTimerNS(interval.count(), callback, userdata));
441 return SDL_AddTimerNS(interval.count(), callback.
wrapper, callback.
data);
static constexpr Time FromNS(Sint64 time)
Create from a nanoseconds Sint64.
Definition SDL3pp_stdinc.h:402
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:296
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:281
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:311
constexpr Sint64 ToPosix() const
Convert nanoseconds to seconds.
Definition SDL3pp_timer.h:31
Uint32(SDLCALL *)(void *userdata, TimerID timerID, Uint32 interval) MSTimerCallback
Function prototype for the millisecond timer callback function.
Definition SDL3pp_timer.h:244
std::chrono::nanoseconds GetTicks()
Get the time elapsed since SDL library initialization.
Definition SDL3pp_timer.h:49
Uint64 GetPerformanceFrequency()
Get the count per second of the high resolution counter.
Definition SDL3pp_timer.h:111
Uint64 GetPerformanceCounter()
Get the current value of the high resolution counter.
Definition SDL3pp_timer.h:98
void RemoveTimer(TimerID id)
Remove a timer created with AddTimer().
Definition SDL3pp_timer.h:456
SDL_TimerID TimerID
Definition of the timer ID type.
Definition SDL3pp_timer.h:218
void DelayNS(Uint64 ns)
Wait a specified number of nanoseconds before returning.
Definition SDL3pp_timer.h:169
Uint64 GetTicksMS()
Get the number of milliseconds that have elapsed since the SDL library initialization.
Definition SDL3pp_timer.h:68
void DelayPrecise(Uint64 ns)
Wait a specified number of nanoseconds before returning.
Definition SDL3pp_timer.h:188
Uint64 GetTicksNS()
Get the number of nanoseconds since SDL library initialization.
Definition SDL3pp_timer.h:80
void Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
Definition SDL3pp_timer.h:132
Uint64(SDLCALL *)(void *userdata, TimerID timerID, Uint64 interval) NSTimerCallback
Function prototype for the nanosecond timer callback function.
Definition SDL3pp_timer.h:272
static constexpr Time FromPosix(Sint64 time)
Convert seconds to nanoseconds.
Definition SDL3pp_timer.h:26
TimerID AddTimer(std::chrono::milliseconds interval, MSTimerCallback callback, void *userdata)
Call a callback function at a future time.
Definition SDL3pp_timer.h:353
Main include header for the SDL3pp library.
void * data
The wrapped data.
Definition SDL3pp_callbackWrapper.h:114
LightweightCallbackT(const F &func)
Definition SDL3pp_callbackWrapper.h:118
R(* wrapper)(void *, PARAMS...)
The wrapper function.
Definition SDL3pp_callbackWrapper.h:111
Function prototype for the nanosecond timer callback function.
Definition SDL3pp_timer.h:303
TimerCB(const F &func)
ctor
Definition SDL3pp_timer.h:306