Trait amethyst::ecs::prelude::Component[]

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

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 specs::prelude::*;

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

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

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

impl Component for Light {
    type Storage = DenseVecStorage<Self>;
}
use specs::prelude::*;
use specs::storage::HashMapStorage;

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

Associated storage type for this component.

Implementations on Foreign Types

impl<I, T> Component for AnimationSet<I, T> where
    I: Eq + Hash + Send + Sync + 'static,
    T: AnimationSampling
[src]

impl<T> Component for SamplerControlSet<T> where
    T: AnimationSampling
[src]

impl<T> Component for AnimationHierarchy<T> where
    T: AnimationSampling
[src]

impl<T> Component for RestState<T> where
    T: AnimationSampling
[src]

impl<I, T> Component for AnimationControlSet<I, T> where
    I: Send + Sync + 'static,
    T: AnimationSampling
[src]

impl Component for Joint
[src]

impl<T> Component for AnimationControl<T> where
    T: AnimationSampling
[src]

impl Component for Skin
[src]

impl<A> Component for Handle<A> where
    A: Asset
[src]

impl Component for Transform
[src]

impl Component for GlobalTransform
[src]

impl Component for Parent
[src]

impl Component for Light
[src]

impl Component for Camera
[src]

impl Component for Material
[src]

impl Component for Transparent
[src]

impl Component for JointTransforms
[src]

impl Component for AudioListener
[src]

impl Component for AudioEmitter
[src]

impl Component for FlyControlTag
[src]

impl Component for ArcBallControlTag
[src]

impl Component for TextEditing
[src]

impl Component for UiTransform
[src]

impl Component for UiResize
[src]

impl Component for MouseReactive
[src]

impl Component for UiText
[src]

impl Component for UiImage
[src]

impl<T> Component for Tag<T> where
    T: Send + Sync + 'static, 
[src]

Implementors