summaryrefslogtreecommitdiff
path: root/ecs/src/component.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-01-02 17:02:25 +0100
committerHampusM <hampus@hampusmat.com>2025-01-02 17:02:25 +0100
commit85ed89df486858984f0936086205efc23fd32d24 (patch)
treef0480c745b3980e0767ed79177d87188f8129514 /ecs/src/component.rs
parent1f6685aa570eadc70342bd1c62f5f9ff451afcb2 (diff)
refactor(ecs): make component::Sequence return metadata as array
Diffstat (limited to 'ecs/src/component.rs')
-rw-r--r--ecs/src/component.rs18
1 files changed, 13 insertions, 5 deletions
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<Box<dyn Component>>;
- fn metadata() -> Vec<Metadata>;
+ fn metadata() -> impl Array<Metadata>;
fn added_event_ids() -> Vec<Uid>;
@@ -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<Box<dyn Component>>
{
Vec::from_iter([#(Box::new(self.I) as Box<dyn Component>,)*])
}
- fn metadata() -> Vec<Metadata>
+ fn metadata() -> impl Array<Metadata>
{
- 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<Box<dyn Component>>
{
Vec::new()
}
- fn metadata() -> Vec<Metadata>
+ fn metadata() -> impl Array<Metadata>
{
- Vec::new()
+ []
}
fn added_event_ids() -> Vec<Uid>