runtime

Host lifecycle and frame coordination for Garnet worlds

garnet-runtime

Add the runtime shard from your workspace or exported Garnet SDK to the host application's shard.yml. For an SDK exported to vendor/garnet:

dependencies:
  garnet-runtime:
    path: vendor/garnet/runtime

Require garnet-runtime for Garnet::Runtime, HostEvent, Diagnostics, and ECS. The host forwards lifecycle events and supplies its clock on the simulation owner thread. Once resumed with a surface, each call to frame advances the world's schedule. Use one frame driver per world.

require "garnet-runtime"

world = Garnet::World.new
runtime = Garnet::Runtime.new(world)
registration = world.schedule.add(:fixed_update) { |_, seconds| puts seconds }
runtime.handle(:resume)
runtime.handle(:surface_available)
runtime.frame
registration.close

Run scripts/check-portable-runtime from the workspace to export the portable SDK, install its dependencies offline, and exercise a host frame.

Drivers, lifecycle and frame pacing

World#run hands control to a Garnet::Driver. Garnet::HostDriver drives any Garnet::Host (a window or screen adapter that implements poll, close_requested?, focused? and drawable?, plus optional wait, before_frame and after_frame). App plugins such as Garnet::App::Desktop install one for you.

Each iteration polls the host, maps focus to Resume/Suspend and visibility to SurfaceAvailable/SurfaceLost, and advances one frame while active. A close request or World#exit ends the loop with Close.

  • Garnet::Lifecycle (resource) tracks foreground, surface, audio interruption and close. lifecycle.subscribe(world) { |event| } runs synchronously when the host reports an event, even between frames, so services like audio can stop immediately. The same events are emitted into the world as HostEvent for systems.
  • Garnet::FramePolicy (resource) holds max_frame (delta clamp, 100 ms), fixed_delta (exact per-frame delta for captures and replays), pause_when_unfocused, frame_limit and idle_wait. Drivers read it every frame.

Runtime#step(delta) advances an exact delta while active, alongside Runtime#frame, which measures the host clock. Runtime and the raw hosts stay usable directly for custom loops.

Repository

runtime

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 2
  • 1 day ago
  • November 30, 2026
License

MIT License

Links
Synced at

Wed, 02 Dec 2026 02:09:04 GMT

Languages