class
Termisu::Event::Source::SystemTimer
- Termisu::Event::Source::SystemTimer
- Termisu::Event::Source
- Reference
- Object
Overview
System timer event source using kernel-level timing.
Uses the platform-specific Poller for high-precision timer events:
- Linux: timerfd with epoll
- macOS/BSD: kqueue EVFILT_TIMER
- Fallback: monotonic clock with poll
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
Defined in:
termisu/event/source/system_timer.crConstant Summary
-
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.
Instance Method Summary
-
#interval : Time::Span
Returns the current interval between ticks.
-
#interval=(value : Time::Span)
Sets the interval between ticks.
-
#name : String
Returns the source name for identification.
-
#running? : Bool
Returns true if the timer is currently running.
-
#start(output : Channel(Event::Any)) : Nil
Starts generating tick events to the output channel.
-
#stop : Nil
Stops generating tick events and releases resources.
Instance methods inherited from class Termisu::Event::Source
name : String
name,
running? : Bool
running?,
start(output : Channel(Event::Any)) : Nil
start,
stop : Nil
stop
Constructor Detail
Creates a new system timer with the specified interval.
#interval- Time between tick events (default: 16ms for ~60 FPS)
Instance Method Detail
Sets the interval between ticks.
If the timer is running, updates the system timer's interval.
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.