class Opal::Game::Loop

Overview

High-performance 60Hz fixed-timestep game loop implementing Glenn Fiedler's "Fix Your Timestep" architecture. Decouples physics/simulation updates from variable-rate terminal frame rendering with interpolation.

Defined in:

opal/game/loop.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(target_fps : Int32 = 60, tick_rate : Int32 = 60) #

[View source]

Instance Method Detail

def fps : Float64 #

[View source]
def frame_time_ms : Float64 #

[View source]
def on_render(&block : UI::Buffer, Float64 -> Nil) : self #

[View source]
def on_update(&block : Float64 -> Nil) : self #

[View source]
def pause : Nil #

[View source]
def paused=(paused : Bool) #

[View source]
def paused? : Bool #

[View source]
def resume : Nil #

[View source]
def run(buffer : UI::Buffer, max_frames : Int32 | Nil = nil) : Nil #

Runs the main loop synchronously until stop is invoked or max_frames is reached


[View source]
def running=(running : Bool) #

[View source]
def running? : Bool #

[View source]
def stop : Nil #

[View source]
def target_fps : Int32 #

[View source]
def target_fps=(target_fps : Int32) #

[View source]
def tick_once(dt : Float64 | Nil = nil) : Nil #

Performs a single fixed-timestep update tick (useful for headless testing and step debugging)


[View source]
def tick_rate : Int32 #

[View source]
def tick_rate=(tick_rate : Int32) #

[View source]
def total_frames : UInt64 #

[View source]
def ups : Float64 #

[View source]