From 70c7d745f918dd23343599963a619539f4f880cb Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 1 Aug 2024 12:36:35 +0200 Subject: refactor(ecs): add & use component metadata struct --- ecs/src/component.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'ecs/src/component.rs') diff --git a/ecs/src/component.rs b/ecs/src/component.rs index be5756f..67ae453 100644 --- a/ecs/src/component.rs +++ b/ecs/src/component.rs @@ -139,13 +139,33 @@ pub trait Sequence fn into_vec(self) -> Vec>; - fn ids() -> Vec<(Id, IsOptional)>; + fn metadata() -> Vec; fn from_components<'component>( components: impl Iterator, ) -> Self::Refs<'component>; } +/// [`Component`] metadata. +#[derive(Debug, Clone)] +#[non_exhaustive] +pub struct Metadata +{ + pub id: Id, + pub is_optional: IsOptional, +} + +impl Metadata +{ + pub fn of(component: &ComponentT) -> Self + { + Self { + id: component.id(), + is_optional: component.is_optional().into(), + } + } +} + /// Whether or not a `Component` is optional. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum IsOptional @@ -201,11 +221,14 @@ macro_rules! inner { Vec::from_iter([#(Box::new(self.I) as Box,)*]) } - fn ids() -> Vec<(Id, IsOptional)> + fn metadata() -> Vec { vec![ #( - (Id::of::(), is_optional::().into()), + Metadata { + id: Id::of::(), + is_optional: is_optional::().into() + }, )* ] } -- cgit v1.2.3-18-g5258