Skip to main content

Generator

Trait Generator 

Source
pub trait Generator: Send {
    // Required methods
    fn meta(&self) -> &'static Meta;
    fn resize(&mut self, size: Size, ctx: &mut Ctx);
    fn update(&mut self, dt: f64, ctx: &mut Ctx);
    fn render(&self, canvas: &mut Canvas);

    // Provided methods
    fn prepare(&mut self) { ... }
    fn caption(&self) -> Option<&'static str> { ... }
}
Expand description

A scene (CORE-R14). Call protocol (CORE-R15), guaranteed by the runtime: resize before the first update/render and on every size change; render receives a cleared canvas of the last resized size.

Contract (GEN-R4..R10): never panic for any size >= 1x1, rebuild size-dependent state in resize, use only ctx.rng and dt/ctx.time().

Required Methods§

Source

fn meta(&self) -> &'static Meta

Source

fn resize(&mut self, size: Size, ctx: &mut Ctx)

Source

fn update(&mut self, dt: f64, ctx: &mut Ctx)

Source

fn render(&self, canvas: &mut Canvas)

Provided Methods§

Source

fn prepare(&mut self)

Called by Stage::render exactly once right before every render (CORE-R101): the place to rasterise simulation state into the scene’s buffers once per drawn frame rather than once per step (the runtime takes about two 60 Hz steps per 30 FPS frame; GEN-R20). Must not advance the simulation or draw from ctx.rng, and must not allocate (GEN-R11). Default: nothing.

Source

fn caption(&self) -> Option<&'static str>

The live act’s caption, which replaces the title’s mechanism; an entry of meta().captions (CORE-R71).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§