Documentation
¶
Overview ¶
Package timer provides countdowns as Timer components. NewSystem advances them on fixed ticks and records completions in Timer.CompletedOn; it emits no events and does not remove timers.
Index ¶
Constants ¶
const SystemName = "engine.timer"
SystemName is the name used to register the timer system in the fixed schedule.
Variables ¶
This section is empty.
Functions ¶
func NewSystem ¶
NewSystem returns the fixed-tick system that advances running Timer components and records completions in Timer.CompletedOn.
The game constructor registers this system under SystemName when `castrum.WithTimer` is enabled. Otherwise, register it yourself.
Types ¶
type Timer ¶
type Timer struct {
// Duration is the length of each interval and must be positive.
Duration time.Duration
// Elapsed is the time accumulated in the current interval.
Elapsed time.Duration
// Repeating starts a new interval after each completion and carries over
// excess elapsed time. Otherwise, the timer stops at Duration.
Repeating bool
// Running controls whether elapsed time accumulates. Setting it false
// pauses an unfinished timer; restart a completed one-shot with
// [Timer.Restart].
Running bool
// CompletedOn is the fixed tick of the most recent completion. Zero means
// no completion has been recorded because game ticks start at one.
// [Timer.Restart] clears it.
CompletedOn uint64
}
Timer tracks a countdown on an entity. NewSystem advances it on fixed ticks.
An entity can hold only one Timer. Give each timer its own entity to track multiple timers for one actor.
func NewTimer ¶
NewTimer returns a running timer with the given duration and repeat setting. Timer.Validate rejects a non-positive duration when the timer enters storage.
func (Timer) HasCompleted ¶
HasCompleted reports whether a one-shot timer has completed. It remains true until Timer.Restart. It always returns false for repeating timers; use Timer.JustCompleted to observe each completion.
func (Timer) JustCompleted ¶
JustCompleted reports whether the timer's most recent completion occurred on tick. Pass core.Context.Tick to detect a completion during the current fixed update.
func (*Timer) Restart ¶
func (t *Timer) Restart()
Restart clears Elapsed and CompletedOn, then marks the timer as Running. To restart a timer stored on an entity, call it inside core.Entity.Update.