2023-05-25 04:11:16 +00:00
|
|
|
use std::any::{TypeId, Any};
|
|
|
|
|
2023-05-26 02:59:27 +00:00
|
|
|
use crate::{archetype::ComponentColumn, component::Component};
|
2023-05-25 04:11:16 +00:00
|
|
|
|
|
|
|
pub trait Bundle {
|
|
|
|
// Get a list of type ids that this bundle is storing
|
|
|
|
fn types(&self) -> Vec<TypeId>;
|
|
|
|
/// 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<Box<dyn ComponentColumn>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_bundle_tuple {
|
|
|
|
( $(($name: ident, $index: tt))+ ) => (
|
2023-05-26 02:59:27 +00:00
|
|
|
impl<$($name: Component),+> Bundle for ($($name,)+) {
|
2023-05-25 04:11:16 +00:00
|
|
|
fn types(&self) -> Vec<TypeId> {
|
|
|
|
vec![$(self.$index.type_id()),+]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn take_components(self) -> Vec<Box<dyn ComponentColumn>> {
|
|
|
|
vec![$(Box::new(vec![self.$index])),+]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) }
|