use super::Entity; use super::sparse_set::SparseSet; pub trait Component {} #[macro_export] macro_rules! component { ($name:ident) => { #[derive(Clone, Copy, Debug)] pub struct $name; impl Component for $name {} }; ($name:ident, $ty:ty) => { #[derive(Clone, Copy, Debug)] pub struct $name(pub $ty); impl std::ops::Deref for $name { type Target = $ty; fn deref(&self) -> &Self::Target { &self.0 } } impl std::ops::DerefMut for $name { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } impl Component for $name {} }; ($name:ident, { $($field:ident : $ty:ty),+ $(,)? }) => { #[derive(Clone, Debug)] pub struct $name { $(pub $field: $ty),+ } impl Component for $name {} }; } pub trait ComponentStorage { fn storage(&self) -> &SparseSet; fn storage_mut(&mut self) -> &mut SparseSet; fn storage_ptr(&mut self) -> *mut SparseSet; fn insert(&mut self, entity: Entity, component: T) { self.storage_mut().insert(entity, component); } }