21 #include <SDL2/SDL_timer.h>
46 static std::map<std::size_t, timer>* ptimers =
new std::map<std::size_t, timer>();
99 DBG_GUI_E <<
"Pushing timer event in queue.";
106 auto itor =
get_timers().find(
reinterpret_cast<std::size_t
>(
id));
110 result = itor->second.interval;
117 event.user.data1 =
id;
118 event.user.data2 =
nullptr;
120 SDL_PushEvent(&event);
128 const std::function<
void(std::size_t
id)>& callback,
131 static_assert(
sizeof(std::size_t) ==
sizeof(
void*),
"Pointer and std::size_t are not the same size");
148 WRN_GUI_E <<
"Failed to create an sdl timer.";
170 DBG_GUI_E <<
"Removing timer " <<
id <<
".";
176 LOG_GUI_E <<
"Can't remove timer since it no longer exists.";
185 if(!SDL_RemoveTimer(itor->second.sdl_id)) {
195 DBG_GUI_E <<
"The timer is already out of the SDL timer list.";
203 DBG_GUI_E <<
"Executing timer " <<
id <<
".";
205 std::function<void(
size_t)> callback =
nullptr;
211 LOG_GUI_E <<
"Can't execute timer since it no longer exists.";
215 callback = itor->second.callback;
217 if(itor->second.interval == 0) {
Helper to make removing a timer in a callback safe.
Define the common log macros for the gui toolkit.
std::string id
Text to match against addon_info.tags()
static std::size_t executing_id
The id of the event being executed, 0 if none.
std::size_t add_timer(const uint32_t interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
static bool executing_id_removed
Did somebody try to remove the timer during its execution?
static std::size_t next_timer_id
Ids for the timers.
static uint32_t timer_callback(uint32_t, void *id)
bool remove_timer(const std::size_t id)
Removes a timer.
bool execute_timer(const std::size_t id)
Executes a timer.
static std::map< std::size_t, timer > & get_timers()
The active timers.
std::function< void(std::size_t id)> callback
Contains the gui2 timer routines.