Termisu::Event::Source::SystemTimer
Inherits Termisu::Event::Source / Reference / Object
Advantages over sleep-based Timer
- Kernel schedules ticks at exact intervals regardless of processing time
timer_expirationsdetects missed ticks for frame drop compensation- More consistent frame times for smooth animations
Usage
timer = Termisu::Event::Source::SystemTimer.new(interval: 16.milliseconds)
loop = Termisu::Event::Loop.new
loop.add_source(timer)
loop.start
while event = loop.output.receive?
case event
when Termisu::Event::Tick
if event.missed_ticks > 0
# Compensate for dropped frames
end
render_frame(event.delta)
end
end
Constants
DEFAULT_INTERVAL = 16.milliseconds
Default tick interval (~60 FPS).
Log = Termisu::Logs::Event
Constructors
new(interval : Time::Span = DEFAULT_INTERVAL)
Creates a new system timer with the specified interval.
interval- Time between tick events (default: 16ms for ~60 FPS)
Instance methods
interval=(value : Time::Span)
Sets the interval between ticks.
If the timer is running, updates the system timer's interval.
start(output : Channel(Event::Any)) : Nil
Starts generating tick events to the output channel.
Creates a platform-specific Poller and timer, then spawns a fiber to wait on timer events and emit Tick events to the channel.