Macro ecstatic::define_world[][src]

macro_rules! define_world {
    ($(#[$meta:meta])*
     $v:vis world {
        components {
            $($component:ident : $($component_storage:ident) :: + < $component_type:ty >),* $(,)*
        }
        resources {
            $($resource:ident : $resource_type:ty),* $(,)*
        }
    }) => { ... };
}
Expand description

Defines the set of data structures necessary for using ecstatic.

Generates the following structs:

  • Resources
    • All of the components and resources
  • World
    • Wraps Resources and contains entity metadata
  • EntityBuilder
    • Helper for World::new_entity()
  • ComponentSet
    • Used by EntityBuilder. Basically just all of the components wrapped in an Option.

Example

#[derive(Default, Debug)]
struct Data {
    info: String,
}

define_world!(
    // You can apply trait derivations to the output structs. Whatever is specified here will
    // apply to both the `World` struct and the `Resources` struct.
    #[derive(Default, Debug)]
    // The visibility specifier is optional. It applies to all of the types defined by the
    // macro.
    pub(crate) world {
        // Components must all go in collections that implement `ComponentStorage`. They are
        // addressed by type, so you can only have one field per type.
        components {
            strings: BasicVecStorage<Data>,
        }
        // Resources are just stored bare, but the same restriction on unique fields per type
        // applies (but only within resources -- you can have a resource of the same type as a
        // component).
        resources {
            data: Data,
        }
    }
);