6#include <SDL3/SDL_timer.h>
7#include "SDL3pp_callbackWrapper.h"
8#include "SDL3pp_error.h"
9#include "SDL3pp_stdinc.h"
61 return SDL_NS_TO_SECONDS(m_value.count());
76 return std::chrono::nanoseconds{SDL_GetTicksNS()};
111 return SDL_GetPerformanceFrequency();
126inline void Delay(std::chrono::nanoseconds duration)
128 SDL_DelayNS(duration.count());
149 SDL_DelayPrecise(duration.count());
210 std::function<std::chrono::nanoseconds(
TimerID, std::chrono::nanoseconds)>;
250 return CheckError(SDL_AddTimerNS(interval.count(), callback, userdata));
294 auto cb = Wrapper::Wrap(std::move(callback));
296 if (
TimerID id = SDL_AddTimerNS(
298 [](
void* userdata,
TimerID timerID, Uint64 interval) -> Uint64 {
299 auto& f = *static_cast<TimerCB*>(userdata);
300 auto next = f(timerID, std::chrono::nanoseconds(interval)).count();
302 if (next == 0) delete Store::release(timerID);
306 Store::Wrap(
id, std::move(cb));
An exception that returns GetError()
Definition SDL3pp_error.h:167
SDL times are signed, 64-bit integers representing nanoseconds since the Unix epoch (Jan 1,...
Definition SDL3pp_stdinc.h:261
static constexpr Time FromNS(Sint64 time)
Create from a nanoseconds Sint64.
Definition SDL3pp_stdinc.h:291
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
constexpr Sint64 ToPosix() const
Convert nanoseconds to seconds.
Definition SDL3pp_timer.h:59
void Delay(std::chrono::nanoseconds duration)
Wait a specified duration before returning.
Definition SDL3pp_timer.h:126
TimerID AddTimer(std::chrono::nanoseconds interval, TimerCallback callback, void *userdata)
Call a callback function at a future time.
Definition SDL3pp_timer.h:246
void DelayPrecise(std::chrono::nanoseconds duration)
Wait a specified duration before returning.
Definition SDL3pp_timer.h:147
std::function< std::chrono::nanoseconds(TimerID, std::chrono::nanoseconds)> TimerCB
Function prototype for the nanosecond timer callback function.
Definition SDL3pp_timer.h:210
std::chrono::nanoseconds GetTicks()
Get the time elapsed since SDL library initialization.
Definition SDL3pp_timer.h:74
Uint64 GetPerformanceFrequency()
Get the count per second of the high resolution counter.
Definition SDL3pp_timer.h:109
SDL_TimerID TimerID
Definition of the timer ID type.
Definition SDL3pp_timer.h:156
Uint64 GetPerformanceCounter()
Get the current value of the high resolution counter.
Definition SDL3pp_timer.h:96
void RemoveTimer(TimerID id)
Remove a timer created with AddTimer().
Definition SDL3pp_timer.h:325
SDL_NSTimerCallback TimerCallback
Function prototype for the nanosecond timer callback function.
Definition SDL3pp_timer.h:182
static constexpr Time FromPosix(Sint64 time)
Convert seconds to nanoseconds.
Definition SDL3pp_timer.h:43
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
Definition SDL3pp_callbackWrapper.h:66
Wrapper key to value result callbacks.
Definition SDL3pp_callbackWrapper.h:145
static ValueType release(KeyType key)
Return unwrapped value associated by key and remove association.
Definition SDL3pp_callbackWrapper.h:183