mirage-engine 0.2.0

Mirage, an immediate-mode 3D engine for simple games on desktop and the browser
Documentation
//! What `#[derive(Catalog)]` enumerates, seen the way a game sees it.

use mirage_engine::prelude::*;

/// A vocabulary of every shape the derive handles: fieldless variants, a named
/// one of two values, and a tuple wrapping an engine primitive.
#[derive(Catalog, Clone, Debug, Eq, Hash, PartialEq)]
enum Shape {
    Ship,
    Beacon,
    #[catalog(Self::Asteroid { seed: 1 }, Self::Asteroid { seed: 7 })]
    Asteroid {
        seed: u32,
    },
    #[catalog(Self::Block(Cube))]
    Block(Cube),
}

/// A mesh type whose every value is its own mesh, two of which it names.
#[derive(Catalog, Clone, Debug, Eq, Hash, PartialEq)]
#[catalog(Self { seed: 0 }, Self { seed: 1 })]
struct Boulder {
    seed: u32,
}

/// A vocabulary of exactly one mesh, which needs no attribute at all.
#[derive(Catalog, Clone, Debug, Eq, Hash, PartialEq)]
struct Marker;

impl Mesh for Shape {
    fn build(&self, assets: &Assets) -> MeshData {
        match self {
            Shape::Ship | Shape::Beacon | Shape::Asteroid { .. } => {
                Sphere { subdivisions: 0 }.build(assets)
            }
            Shape::Block(cube) => cube.build(assets),
        }
    }
}

#[test]
fn fieldless_variants_catalog_themselves_and_the_rest_the_values_they_name() {
    assert_eq!(
        Shape::catalog(),
        vec![
            Shape::Ship,
            Shape::Beacon,
            Shape::Asteroid { seed: 1 },
            Shape::Asteroid { seed: 7 },
            Shape::Block(Cube),
        ]
    );
}

#[test]
fn a_struct_catalogs_every_value_its_one_attribute_names() {
    assert_eq!(
        Boulder::catalog(),
        vec![Boulder { seed: 0 }, Boulder { seed: 1 }]
    );
}

#[test]
fn a_unit_struct_catalogs_itself() {
    assert_eq!(Marker::catalog(), vec![Marker]);
}