diff options
| author | HampusM <hampus@hampusmat.com> | 2026-06-16 17:23:05 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-06-16 17:23:05 +0200 |
| commit | 166da477e761416a87ffd5fb8fc49ceaf7f53690 (patch) | |
| tree | 60e54ee65aca16e8d0e03a6dd3306b8622c8da6e | |
| parent | 5cdb4b0adb55cf2995e999135c5f3e9d6da70843 (diff) | |
feat(engine-ecs): impl component::Sequence for component::Parts arrays
| -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 } } |
