44 lines
2.2 KiB
Rust
44 lines
2.2 KiB
Rust
|
use std::any::{TypeId, Any};
|
||
|
|
||
|
use crate::archetype::ComponentColumn;
|
||
|
|
||
|
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))+ ) => (
|
||
|
impl<$($name: Send + Sync + 'static),+> Bundle for ($($name,)+) {
|
||
|
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) }
|