|
Scarab
A thin, game-agnostic 2D engine host built on the sunlight tile-map engine
|
Background-thread periodic/delayed callback Lua primitives (set_timer/reset_timer), backed by SunLight::Concurrent::Timer. See LuaEngineUtil::s_LuaMutex's own comment for the thread-safety invariant every timer callback depends on. More...
#include <luatimerapi.h>
Static Public Member Functions | |
| static void | Register (lua_State *pLuaState) |
| Register the timer Lua-callable functions. | |
Background-thread periodic/delayed callback Lua primitives (set_timer/reset_timer), backed by SunLight::Concurrent::Timer. See LuaEngineUtil::s_LuaMutex's own comment for the thread-safety invariant every timer callback depends on.
Backed by SunLight::Concurrent::Timer. Unlike sp_wait (which only pauses the ScriptProcessor queue), a timer fires its callback repeatedly on its own schedule, independent of the queue, from a background thread — see the important thread-safety note below.
A timer's callback runs on its own background thread, not the main game thread. The engine already serializes every one of its own Lua entry points (per-frame update, wave dispatch, etc.) against timer callbacks internally, so calling ordinary engine primitives (sound_play, sprite_get_pos, ...) from inside a timer callback is safe.
What isn't automatically safe: don't call reset_timer on a timer's own id from inside that same timer's callback — behavior in that specific case isn't gracefully handled and this pattern hasn't been exercised. If you need a one-shot timer, prefer a plain counter guard inside the callback (do the work only once, then leave the timer running idle, or cancel it from the main-thread on_update instead of from within the callback itself):
|
static |
Register the timer Lua-callable functions.