1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
use mopa::Any;
use storage::UnprotectedStorage;
/// 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>;
/// }
/// ```
pub trait Component: Any + Sized {
/// Associated storage type for this component.
type Storage: UnprotectedStorage<Self> + Any + Send + Sync;
}