diff options
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r-- | ecs/src/lib.rs | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 3adc415..3caaa6b 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -10,6 +10,7 @@ use std::sync::Arc; use hashbrown::HashMap; use crate::actions::Action; +use crate::component::storage::archetype::EntityComponent as ArchetypeEntityComponent; use crate::component::storage::Storage as ComponentStorage; use crate::component::{Component, Sequence as ComponentSequence}; use crate::entity::CREATE_STATIC_ENTITIES; @@ -20,7 +21,7 @@ use crate::phase::{Phase, START as START_PHASE}; use crate::query::flexible::Query as FlexibleQuery; use crate::query::term::Without; use crate::query::{ - ComponentIter, + Iter as QueryIter, TermWithFieldTuple as QueryTermWithFieldTuple, TermWithoutFieldTuple as QueryTermWithoutFieldTuple, Terms as QueryTerms, @@ -467,7 +468,7 @@ impl World { let mut component_storage_lock = self.lock_component_storage_rw(); - let components = match component_storage_lock.remove_entity(entity_uid) { + let removed_entity = match component_storage_lock.remove_entity(entity_uid) { Ok(components) => components, Err(err) => { tracing::error!("Failed to despawn entity: {err}"); @@ -475,16 +476,17 @@ impl World } }; - let component_removed_event_uids = components + let component_removed_event_uids = removed_entity + .components() .iter() .map(|component| { component - .component + .component() .read_nonblock() .unwrap_or_else(|_| { panic!( "Failed to acquire read-only {} component lock", - component.name + component.name() ) }) .get_event_uid(ComponentEventKind::Removed) @@ -534,11 +536,6 @@ impl World fn emit_event_by_id(&self, event_id: Uid) { - //let query = self.flexible_query([ - // ComponentMetadata::of::<SystemComponent>(), - // ComponentMetadata { id: event_id, is_optional: false }, - //]); - let mut query_required_ids = [SystemComponent::id(), event_id]; let query = self.flexible_query( @@ -547,8 +544,7 @@ impl World .build(), ); - for (system,) in ComponentIter::<(&SystemComponent,), _>::new(self, query.iter()) - { + for (system,) in QueryIter::<(&SystemComponent,), _>::new(self, query.iter()) { unsafe { system.system.run(self); } @@ -603,23 +599,21 @@ pub struct WorldData } #[derive(Debug)] -#[non_exhaustive] -pub struct EntityComponent +pub struct EntityComponentRef<'a> { - pub id: Uid, - pub name: &'static str, - pub component: Lock<Box<dyn Component>>, + comp: &'a ArchetypeEntityComponent, } -impl EntityComponent +impl<'a> EntityComponentRef<'a> { - pub fn new(id: Uid, component: Box<dyn Component>) -> Self + pub fn component(&self) -> &'a Lock<Box<dyn Component>> { - Self { - id, - name: component.type_name(), - component: Lock::new(component), - } + self.comp.component() + } + + fn new(comp: &'a ArchetypeEntityComponent) -> Self + { + Self { comp } } } |