From b982b205373f445db9ced7f3cf13c1156ad8a40a Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 8 Apr 2025 20:20:33 +0200 Subject: feat(ecs): add support for component data not implementing Component --- ecs/src/actions.rs | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) (limited to 'ecs/src/actions.rs') diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs index 7dff3a5..f366b4c 100644 --- a/ecs/src/actions.rs +++ b/ecs/src/actions.rs @@ -1,11 +1,7 @@ use std::marker::PhantomData; use std::sync::{Arc, Weak}; -use crate::component::{ - Component, - Metadata as ComponentMetadata, - Sequence as ComponentSequence, -}; +use crate::component::{Parts as ComponentParts, Sequence as ComponentSequence}; use crate::system::{Param as SystemParam, System}; use crate::uid::{Kind as UidKind, Uid}; use crate::{ActionQueue, World}; @@ -23,10 +19,8 @@ impl<'world> Actions<'world> /// Queues up a entity to spawn at the end of the current tick. pub fn spawn(&mut self, components: Comps) { - self.action_queue.push(Action::Spawn( - components.into_array().into(), - EventIds { ids: Comps::added_event_ids() }, - )); + self.action_queue + .push(Action::Spawn(components.into_parts_array().into())); } /// Queues up despawning a entity at the end of the current tick. @@ -50,26 +44,28 @@ impl<'world> Actions<'world> self.action_queue.push(Action::AddComponents( entity_uid, - components.into_array().into(), - EventIds { ids: Comps::added_event_ids() }, + components.into_parts_array().into(), )); } /// Queues up removing component(s) from a entity at the end of the current tick. - pub fn remove_components(&mut self, entity_uid: Uid) - where - Comps: ComponentSequence, + pub fn remove_components( + &mut self, + entity_uid: Uid, + component_ids: impl IntoIterator, + ) { debug_assert_eq!(entity_uid.kind(), UidKind::Entity); - if Comps::COUNT == 0 { + let mut component_ids = component_ids.into_iter().peekable(); + + if component_ids.peek().is_none() { return; } self.action_queue.push(Action::RemoveComponents( entity_uid, - Comps::metadata().into_iter().collect(), - EventIds { ids: Comps::removed_event_ids() }, + component_ids.collect(), )); } @@ -159,19 +155,13 @@ impl Ref<'_> } } -#[derive(Debug)] -pub(crate) struct EventIds -{ - pub(crate) ids: Vec, -} - /// A action for a [`System`] to perform. #[derive(Debug)] pub(crate) enum Action { - Spawn(Vec<(Uid, Box)>, EventIds), + Spawn(Vec), Despawn(Uid), - AddComponents(Uid, Vec<(Uid, Box)>, EventIds), - RemoveComponents(Uid, Vec, EventIds), + AddComponents(Uid, Vec), + RemoveComponents(Uid, Vec), Stop, } -- cgit v1.2.3-18-g5258