[][src]Trait async_ecs::component::Component

pub trait Component: Any + Sized {
    type Storage: Storage<Self> + Any + Send + Sync;
}

Abstract component type. Doesn't have to be Copy or even Clone.

Storages

Components are stored in separated collections for maximum cache efficiency. The Storage associated type allows to specify which collection should be used. Depending on how many entities have this component and how often it is accessed, you will want different storages.

The most common ones are VecStorage (use if almost every entity has that component), DenseVecStorage (if you expect many entities to have the component) and HashMapStorage (for very rare components).

Examples

use async_ecs::*;

pub struct Position {
    pub x: f32,
    pub y: f32,
}

impl Component for Position {
    type Storage = VecStorage<Self>;
}
use async_ecs::*;

pub enum Light {
    // (Variants would have additional data)
    Directional,
    SpotLight,
}

impl Component for Light {
    type Storage = DenseVecStorage<Self>;
}
use async_ecs::*;

pub struct Camera {
    // In an ECS, the camera would not itself have a position;
    // you would just attach a `Position` component to the same
    // entity.
    matrix: [f32; 16],
}

impl Component for Camera {
    type Storage = HashMapStorage<Self>;
}

Associated Types

type Storage: Storage<Self> + Any + Send + Sync[src]

Associated storage type for this component.

Loading content...

Implementors

Loading content...