diff options
| -rw-r--r-- | engine-ecs/src/actions.rs | 2 | ||||
| -rw-r--r-- | engine-ecs/src/component.rs | 27 |
2 files changed, 17 insertions, 12 deletions
diff --git a/engine-ecs/src/actions.rs b/engine-ecs/src/actions.rs index efef384..9e88011 100644 --- a/engine-ecs/src/actions.rs +++ b/engine-ecs/src/actions.rs @@ -69,7 +69,7 @@ impl Actions<'_> { debug_assert!(!entity_uid.is_pair()); - if Comps::COUNT == 0 { + if components.cnt() == 0 { return; } diff --git a/engine-ecs/src/component.rs b/engine-ecs/src/component.rs index 681e546..157d79c 100644 --- a/engine-ecs/src/component.rs +++ b/engine-ecs/src/component.rs @@ -68,11 +68,10 @@ impl Debug for dyn Component /// A sequence of components. pub trait Sequence { - /// The number of components in this component sequence. - const COUNT: usize; - type PartsArray: Array<Parts>; + fn cnt(&self) -> usize; + fn into_parts_array(self) -> Self::PartsArray; } @@ -242,12 +241,15 @@ pub struct AcquireLockError(#[source] LockError); macro_rules! inner { ($c: tt) => { - seq!(I in 0..=$c { + seq!(I in 0..$c { impl<#(IntoCompParts~I: IntoParts,)*> Sequence for (#(IntoCompParts~I,)*) { - const COUNT: usize = $c + 1; + type PartsArray = [Parts; $c]; - type PartsArray = [Parts; $c + 1]; + fn cnt(&self) -> usize + { + $c + } fn into_parts_array(self) -> Self::PartsArray { @@ -260,19 +262,22 @@ macro_rules! inner { }; } -seq!(C in 0..=16 { +seq!(C in 0..17 { inner!(C); }); -impl Sequence for () +impl<const LEN: usize> Sequence for [Parts; LEN] { - type PartsArray = [Parts; 0]; + type PartsArray = Self; - const COUNT: usize = 0; + fn cnt(&self) -> usize + { + self.len() + } fn into_parts_array(self) -> Self::PartsArray { - [] + self } } |
