class Termisu::Event::Source::SystemTimer

Overview

System timer event source using kernel-level timing.

Uses the platform-specific Poller for high-precision timer events:

Advantages over sleep-based Timer

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.cr

Constant Summary

DEFAULT_INTERVAL = 16.milliseconds

Default tick interval (~60 FPS).

Log = Termisu::Logs::Event

Constructors

Instance Method Summary

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

def self.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)

[View source]

Instance Method Detail

def interval : Time::Span #

Returns the current interval between ticks.


[View source]
def interval=(value : Time::Span) #

Sets the interval between ticks.

If the timer is running, updates the system timer's interval.


[View source]
def name : String #

Returns the source name for identification.


[View source]
def running? : Bool #

Returns true if the timer is currently running.


[View source]
def 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.


[View source]
def stop : Nil #

Stops generating tick events and releases resources.


[View source]