use std::{any::{TypeId, Any}, cell::Ref, ptr::NonNull, mem::size_of}; use crate::{archetype::{ComponentColumn, Archetype}, component::Component, component_info::ComponentInfo}; pub trait Bundle { // Get a list of type ids that this bundle is storing fn types(&self) -> Vec; /// Take components into a list. /// The return value could be seen as a list of a list of components, but that inner list /// only contains a single value to make it easier to add it to an archetype. //fn take_components(self) -> Vec>; //fn from_component_columns(columns: Vec<&Box>) -> Self; //fn from_archetype(archetype: &Archetype) -> Self; fn info(&self) -> Vec; /// Take the bundle by calling the closure with pointers to each component, its type and size. /// The closure is expected to take ownership of the pointer. fn takefn(self, cb: impl FnMut(NonNull, TypeId, usize)); } impl Bundle for (C1,) { fn types(&self) -> Vec { vec![self.0.type_id()] } fn info(&self) -> Vec { vec![ComponentInfo::new::()] } fn takefn(self, mut cb: impl FnMut(NonNull, TypeId, usize)) { let (c1, ) = self; cb(NonNull::from(&c1).cast(), TypeId::of::(), size_of::()); } } /* macro_rules! impl_bundle_tuple { ( $(($name: ident, $index: tt))+ ) => ( impl<$($name: Component),+> Bundle for ($($name,)+) { fn types(&self) -> Vec { vec![$(self.$index.type_id()),+] } fn take_components(self) -> Vec> { vec![$(Box::new(vec![self.$index])),+] } fn from_component_columns(columns: Vec<&Box>) -> Self { let mut chains = Vec::new(); for col in columns.iter() { col. } todo!() } } ); } */ // hopefully 16 components in a bundle is enough //impl_bundle_tuple! { (C1, 0) } /* impl_bundle_tuple! { (C1, 0) (C2, 1) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) (C8, 7) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) (C8, 7) (C9, 8) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) (C8, 7) (C9, 8) (C10, 9) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) (C8, 7) (C9, 8) (C10, 9) (C11, 10) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) (C8, 7) (C9, 8) (C10, 9) (C11, 10) (C12, 11) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) (C8, 7) (C9, 8) (C10, 9) (C11, 10) (C12, 11) (C13, 12) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) (C8, 7) (C9, 8) (C10, 9) (C11, 10) (C12, 11) (C13, 12) (C14, 13) } impl_bundle_tuple! { (C1, 0) (C2, 1) (C3, 2) (C4, 3) (C5, 4) (C6, 5) (C7, 6) (C8, 7) (C9, 8) (C10, 9) (C11, 10) (C12, 11) (C13, 12) (C14, 13) (C15, 14) } */