Skip to main content

Game

Trait Game 

Source
pub trait Game: Sized + 'static {
    type Meshes: Meshes + 'static;
    type Sounds: Sounds + 'static;
    type InputActions: InputActions + 'static;
    type SurfaceStyles: SurfaceStyles + 'static;
    type Skyboxes: Skyboxes + 'static;
    type PostEffects: PostEffects + 'static;

    // Required methods
    fn tick(&mut self, ctx: &mut TickContext<'_, Self>);
    fn frame(&mut self, ctx: &mut FrameContext<'_, Self>);
}
Expand description

A game driven by the engine, which owns it for the whole run.

A vocabulary is a type of the game’s own, usually an enum, whose values name everything of one kind the game may use; the contexts are typed by it. Six of them state what this game may draw, play, read, set its sky, style, and pass its frame through, and each has an empty one for a game with none of that kind, so every call in a tick or a frame takes a value of this game’s own vocabulary and no other.

use mirage_engine::prelude::*;

meshes! { enum Shape { Cube } }

struct Hello;

impl Game for Hello {
    type Meshes = Shape;
    type Sounds = NoSounds;
    type InputActions = NoInputActions;
    type Skyboxes = NoSkyboxes;
    type SurfaceStyles = ();
    type PostEffects = ();

    fn tick(&mut self, _ctx: &mut TickContext<'_, Self>) {}

    fn frame(&mut self, ctx: &mut FrameContext<'_, Self>) {
        ctx.draw(Cube.at(Vec3::ZERO));
    }
}

Required Associated Types§

Source

type Meshes: Meshes + 'static

The set of every mesh this game draws — the enum meshes! writes, one variant per mesh type — or () for a game that draws nothing.

Startup builds every value the set’s types catalog, and FrameContext::draw takes a mesh the set holds and no other.

Source

type Sounds: Sounds + 'static

The values naming the sounds this game plays, usually an enum, or NoSounds for a game with none.

Startup builds every value of it, and the contexts are typed by it, so FrameContext::play takes a value of this type and no other.

Source

type InputActions: InputActions + 'static

The three vocabularies naming what the player can do, usually enums, or NoInputActions for a game that reads no input; Key for a prototype that binds each key to itself.

Startup materializes these into the table a player rebinds, and their names are what a rebind is kept under. The contexts are typed by the set, so FrameContext::down and every other query take an action it seats and no other.

Source

type SurfaceStyles: SurfaceStyles + 'static

The set of every style this game draws with — the enum surface_styles! writes — or () for a game that draws with the built-in look alone.

Startup compiles each of them into a pipeline of its own, and stops the game where any of their WGSL does not compile.

Source

type Skyboxes: Skyboxes + 'static

The values naming the skies this game draws and is lit by, usually an enum, or NoSkyboxes for a game under the default sky.

Startup builds every value of it, and the contexts are typed by it, so FrameContext::set_skybox takes a value of this type and no other.

Source

type PostEffects: PostEffects + 'static

The set of every post effect this game passes its frame through — the enum post_effects! writes — or () for a game that draws the frame as the post chain leaves it.

The post chain is the passes that take a drawn frame to the window, and EffectStage states where in it an effect runs. Startup compiles each effect into a pipeline of its own, and stops the game where any of their WGSL does not compile.

Required Methods§

Source

fn tick(&mut self, ctx: &mut TickContext<'_, Self>)

Moves the simulation by one fixed step.

Called zero or more times per drawn frame, one per Config::tick_interval of elapsed time.

Source

fn frame(&mut self, ctx: &mut FrameContext<'_, Self>)

Runs the game’s logic for one drawn frame, drawing as it goes.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§