Documentation
¶
Overview ¶
Command timer demonstrates the timer component as observable state. Five timers run side by side: a one-shot that fires once and stays readable, a repeating timer that restarts itself, a timer created paused and started by a key press, and two grouped timers whose sets are paused and resumed together by the P key - the combat bar freezes while the ui bar keeps counting.
Timers advance on their own each fixed tick; a game never calls an update function on them. Completions are read straight from the component - timer.Timer.JustCompleted against the current tick is the completion edge, and timer.Timer.CompletedOn keeps the tick of the last fire for as long as it is useful. There are no events and no callbacks.
Group state lives in the timer.Groups resource, provided by castrum.WithTimer alongside the timer system. A group pause never writes the timers it holds: their Running fields stay as they were, and only their accumulation stops.
Each timer is its own entity, so any number of them can run for the same game: this program keeps five handles and reads them.
Run from the repository root:
go run ./examples/timer