diff options
author | HampusM <hampus@hampusmat.com> | 2025-10-13 18:50:30 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-10-13 18:50:30 +0200 |
commit | cb1197a132f87cd5034bb8927fdbd09878d9239a (patch) | |
tree | ac234c3d659f06f99e0945a88b73cae28fc4bf59 /ecs | |
parent | d1cf80806c3be68d4a96faefbad4e4cdc0a7832e (diff) |
Diffstat (limited to 'ecs')
-rw-r--r-- | ecs/src/actions.rs | 8 | ||||
-rw-r--r-- | ecs/src/uid.rs | 31 |
2 files changed, 37 insertions, 2 deletions
diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs index f8a59fa..549e341 100644 --- a/ecs/src/actions.rs +++ b/ecs/src/actions.rs @@ -6,7 +6,7 @@ use crate::component::{Parts as ComponentParts, Sequence as ComponentSequence}; use crate::event::component::Removed; use crate::pair::Pair; use crate::system::{Metadata as SystemMetadata, Param as SystemParam}; -use crate::uid::{Kind as UidKind, Uid}; +use crate::uid::{Kind as UidKind, Uid, WithUidTuple}; use crate::{ActionQueue, World}; /// Used to to queue up actions for a [`World`] to perform. @@ -139,6 +139,12 @@ impl Actions<'_> .push(Action::RemoveComponents(entity_uid, component_ids)); } + /// Queues up removing component(s) from a entity at the end of the current tick. + pub fn remove_comps<Ids: WithUidTuple>(&mut self, entity_uid: Uid) + { + self.remove_components(entity_uid, Ids::uids()); + } + /// Stops the [`World`]. The world will finish the current tick and that tick will be /// the last. pub fn stop(&mut self) diff --git a/ecs/src/uid.rs b/ecs/src/uid.rs index a361882..bb393a1 100644 --- a/ecs/src/uid.rs +++ b/ecs/src/uid.rs @@ -2,8 +2,10 @@ use std::fmt::{Debug, Display, Formatter}; use std::mem::transmute; use std::sync::atomic::{AtomicU32, Ordering}; +use seq_macro::seq; + use crate::component::Component; -use crate::util::{gen_mask_64, BitMask, NumberExt}; +use crate::util::{gen_mask_64, Array, BitMask, NumberExt}; static NEXT: AtomicU32 = AtomicU32::new(Uid::FIRST_UNIQUE_ID); @@ -230,3 +232,30 @@ impl<ComponentT: Component> With for ComponentT Self::id() } } + +pub trait WithUidTuple +{ + type UidsArray: Array<Uid>; + + fn uids() -> Self::UidsArray; +} + +macro_rules! impl_with_uid_tuple { + ($c: tt) => { + seq!(I in 0..=$c { + impl<#(WithUid~I: With,)*> WithUidTuple for (#(WithUid~I,)*) + { + type UidsArray = [Uid; $c + 1]; + + fn uids() -> Self::UidsArray + { + [#(WithUid~I::uid(),)*] + } + } + }); + }; +} + +seq!(C in 0..=16 { + impl_with_uid_tuple!(C); +}); |