class
Termisu::Event::Source::SystemTimer
- Termisu::Event::Source::SystemTimer
- Termisu::Event::Source
- Reference
- Object
Overview
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.
-
#stop_required? : Bool
A retained run still needs reaping even after its worker finishes.
Instance methods inherited from class Termisu::Event::Source
name : String
name,
running? : Bool
running?,
start(output : Channel(Event::Any)) : Nil
start,
stop : Nil
stop,
stop_required? : Bool
stop_required?
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.
Poller instances are not thread-safe, so a running timer applies the change on its owning fiber before this method returns.
Starts generating tick events to the output channel.
The owning fiber creates and manages the Poller. Startup remains synchronous so acquisition failures are still reported to the caller.
Stops generating tick events and releases resources.
Stop only invalidates and wakes the run. The owning fiber closes its Poller before this method returns, preventing a stale run from touching descriptors acquired by a restart.