Skip to main content

Crate optic_loop

Crate optic_loop 

Source
Expand description

The game loop and runtime — drives the winit event loop and owns the GPU, camera, windows, and timing.

This crate provides two ergonomic levels for running an Optic application:

§High-level API: Game + Runtime

The Game struct owns all engine subsystems (GPU, camera, window, events, time, gamepad). You implement the Runtime trait and pass it to Game::run:

use optic_loop::{Game, Runtime};

struct App;
impl Runtime for App {
    fn start(&mut self, _game: &mut Game) {}
    fn update(&mut self, game: &mut Game) {
        game.renderer.clear();
        // render things...
    }
    fn end(&mut self, _game: &mut Game) {}
}

Game::run(App);

§Low-level API: GameLoop + closure

GameLoop takes a FnMut(&mut FrameState) closure and gives you more control over setup. Use run for a quick single-window start:

use optic_loop::run;

run("My Window", (800, 600).into(), |frame| {
    frame.gpu.clear();
    // render things...
});

§Frame timing

Both APIs update Time automatically each frame. Access delta time and FPS through the FrameState (low-level) or game.time (high-level).

Structs§

FrameState
A snapshot of per-frame mutable state, passed to the user’s closure.
Game
The primary game object — aggregates the renderer, camera, window, events, timing, gamepad, and user-provided Runtime.
GameLoop
A low-level game loop that drives a closure once per frame.
Time
Frame timing data — delta time, smoothed FPS, and elapsed wall-clock time.
WindowState
A single window and its associated event sink and GPU surface index.

Traits§

Runtime
The lifecycle trait for game logic.

Functions§

run
Runs a single-window application with a per-frame closure.