From 85ed89df486858984f0936086205efc23fd32d24 Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 2 Jan 2025 17:02:25 +0100 Subject: refactor(ecs): make component::Sequence return metadata as array --- ecs/src/component.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'ecs/src/component.rs') diff --git a/ecs/src/component.rs b/ecs/src/component.rs index 1fde5b4..bf19c9e 100644 --- a/ecs/src/component.rs +++ b/ecs/src/component.rs @@ -12,6 +12,7 @@ use crate::lock::{ReadGuard, WriteGuard}; use crate::system::{ComponentRef, ComponentRefMut, Input as SystemInput}; use crate::type_name::TypeName; use crate::uid::Uid; +use crate::util::Array; use crate::{EntityComponent, World}; pub mod local; @@ -170,9 +171,12 @@ pub trait Sequence where Self: 'component; + /// The number of components in this component sequence. + const COUNT: usize; + fn into_vec(self) -> Vec>; - fn metadata() -> Vec; + fn metadata() -> impl Array; fn added_event_ids() -> Vec; @@ -271,14 +275,16 @@ macro_rules! inner { type Refs<'component> = (#(Comp~I::Ref<'component>,)*) where Self: 'component; + const COUNT: usize = $c + 1; + fn into_vec(self) -> Vec> { Vec::from_iter([#(Box::new(self.I) as Box,)*]) } - fn metadata() -> Vec + fn metadata() -> impl Array { - vec![ + [ #( Metadata { id: Comp~I::id(), @@ -357,14 +363,16 @@ impl Sequence for () type MutRefs<'component> = (); type Refs<'component> = (); + const COUNT: usize = 0; + fn into_vec(self) -> Vec> { Vec::new() } - fn metadata() -> Vec + fn metadata() -> impl Array { - Vec::new() + [] } fn added_event_ids() -> Vec -- cgit v1.2.3-18-g5258