optic-loop 0.0.1

Game loop, Runtime trait, and Game builder for Optic engine
Documentation

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