diff options
author | HampusM <hampus@hampusmat.com> | 2024-06-06 12:21:34 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-06-06 12:21:34 +0200 |
commit | 989bffa8ec39bf7421801129fb5b116c47ce8a35 (patch) | |
tree | f0f244049230e5be449a9e2a857fa3b72dddc190 | |
parent | c962b8721aaaaf001e9599fac17596bef71e433d (diff) |
chore(ecs): remove support for specifying component to be dropped last
-rw-r--r-- | ecs/src/component.rs | 9 | ||||
-rw-r--r-- | ecs/src/lib.rs | 74 | ||||
-rw-r--r-- | ecs/src/query.rs | 5 |
3 files changed, 10 insertions, 78 deletions
diff --git a/ecs/src/component.rs b/ecs/src/component.rs index 3399183..63ef7c4 100644 --- a/ecs/src/component.rs +++ b/ecs/src/component.rs @@ -21,8 +21,6 @@ pub trait Component: SystemInput + Any + TypeName where Self: Sized; - fn drop_last(&self) -> bool; - #[doc(hidden)] fn as_any_mut(&mut self) -> &mut dyn Any; @@ -71,13 +69,6 @@ where type Component = ComponentT; type RefMut<'component> = Option<ComponentRefMut<'component, ComponentT>>; - fn drop_last(&self) -> bool - { - self.as_ref() - .map(|component| component.drop_last()) - .unwrap_or_default() - } - fn as_any_mut(&mut self) -> &mut dyn Any { self diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 0bc7aa6..f76d1ae 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -40,7 +40,7 @@ pub use crate::query::Query; #[derive(Debug, Default)] struct Entity { - components: Vec<ManuallyDrop<EntityComponent>>, + components: Vec<EntityComponent>, } #[derive(Debug)] @@ -50,7 +50,6 @@ pub struct EntityComponent pub id: TypeId, pub name: &'static str, pub component: Lock<Box<dyn Component>>, - pub drop_last: bool, } #[derive(Debug, Default)] @@ -86,15 +85,10 @@ impl World components: components .into_vec() .into_iter() - .map(|component| { - let drop_last = component.drop_last(); - - ManuallyDrop::new(EntityComponent { - id: (*component).type_id(), - name: component.type_name(), - component: Lock::new(component), - drop_last, - }) + .map(|component| EntityComponent { + id: (*component).type_id(), + name: component.type_name(), + component: Lock::new(component), }) .collect(), }); @@ -184,15 +178,10 @@ impl World .push(Entity { components: components .into_iter() - .map(|component| { - let drop_last = component.drop_last(); - - ManuallyDrop::new(EntityComponent { - id: (*component).type_id(), - name: component.type_name(), - component: Lock::new(component), - drop_last, - }) + .map(|component| EntityComponent { + id: (*component).type_id(), + name: component.type_name(), + component: Lock::new(component), }) .collect(), }); @@ -326,51 +315,6 @@ impl TypeName for ComponentStorage } } -impl Drop for ComponentStorage -{ - fn drop(&mut self) - { - let mut components_to_drop_last = Vec::new(); - - for entity in &mut self.entities { - for component in &mut entity.components { - if component.drop_last { - #[cfg(feature = "debug")] - tracing::debug!( - "Component {} pushed to dropping last queue", - component.component.read_nonblock().unwrap().type_name() - ); - - components_to_drop_last.push(component); - continue; - } - - #[cfg(feature = "debug")] - tracing::debug!( - "Dropping component {}", - component.component.read_nonblock().unwrap().type_name() - ); - - unsafe { - ManuallyDrop::drop(component); - } - } - } - - for component in &mut components_to_drop_last { - #[cfg(feature = "debug")] - tracing::debug!( - "Dropping component {} last", - component.component.read_nonblock().unwrap().type_name() - ); - - unsafe { - ManuallyDrop::drop(component); - } - } - } -} - #[derive(Debug, thiserror::Error)] #[error("Sole {0} already exists")] pub struct SoleAlreadyExistsError(pub &'static str); diff --git a/ecs/src/query.rs b/ecs/src/query.rs index 73792b3..ffab105 100644 --- a/ecs/src/query.rs +++ b/ecs/src/query.rs @@ -208,10 +208,7 @@ where self.current_entity_index = matching_entity_index + 1; Some(Comps::from_components( - matching_entity - .components - .iter() - .map(|component| &**component), + matching_entity.components.iter().map(|component| component), )) } } |