diff options
author | HampusM <hampus@hampusmat.com> | 2025-06-07 22:52:36 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-06-07 22:54:34 +0200 |
commit | 43cbd47900d23801c584def1b7877fdea700c23a (patch) | |
tree | 72393506bbe46a66cff5fe8e1acaf68107216c25 /ecs/src/component.rs | |
parent | aeed1b1ff3e34fe719a2f7e6097584b99a673ded (diff) |
This replaces the old component removed events
Diffstat (limited to 'ecs/src/component.rs')
-rw-r--r-- | ecs/src/component.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ecs/src/component.rs b/ecs/src/component.rs index 6fb1230..5a8cd0b 100644 --- a/ecs/src/component.rs +++ b/ecs/src/component.rs @@ -2,6 +2,8 @@ use std::any::{type_name, Any}; use std::fmt::Debug; use std::ops::{Deref, DerefMut}; +use ecs_macros::Component; +use hashbrown::HashSet; use seq_macro::seq; use crate::lock::{ @@ -311,3 +313,38 @@ impl Default for PartsBuilder Self { name: "(unspecified)" } } } + +/// Pending component removals for a entity. +#[derive(Debug, Clone, Component)] +pub struct Removals +{ + component_ids: HashSet<Uid>, +} + +impl Removals +{ + pub fn contains<ComponentT: Component>(&self) -> bool + { + self.contains_id(ComponentT::id()) + } + + pub fn contains_id(&self, component_id: Uid) -> bool + { + self.component_ids.contains(&component_id) + } + + pub(crate) fn add_ids(&mut self, ids: impl IntoIterator<Item = Uid>) + { + self.component_ids.extend(ids) + } +} + +impl FromIterator<Uid> for Removals +{ + fn from_iter<T: IntoIterator<Item = Uid>>(iter: T) -> Self + { + Self { + component_ids: iter.into_iter().collect(), + } + } +} |