diff --git a/lyra-ecs/src/query/entities.rs b/lyra-ecs/src/query/entities.rs index 9f2cef6..1d823b2 100644 --- a/lyra-ecs/src/query/entities.rs +++ b/lyra-ecs/src/query/entities.rs @@ -2,21 +2,20 @@ use crate::{archetype::Archetype, World, Entity}; use super::{Fetch, Query, AsQuery}; -pub struct EntitiesFetch { - entities: Vec, +pub struct EntitiesFetch<'a> { + archetype_entities: Option<&'a [Entity]>, } -impl<'a> Fetch<'a> for EntitiesFetch { +impl<'a> Fetch<'a> for EntitiesFetch<'a> { type Item = Entity; unsafe fn get_item(&mut self, entity: crate::world::ArchetypeEntityId) -> Self::Item { - let e = *self.entities.get_unchecked(entity.0 as usize); - e + self.archetype_entities.unwrap()[entity.0 as usize] } fn dangling() -> Self { Self { - entities: vec![], + archetype_entities: None, } } } @@ -27,7 +26,7 @@ pub struct Entities; impl Query for Entities { type Item<'a> = Entity; - type Fetch<'a> = EntitiesFetch; + type Fetch<'a> = EntitiesFetch<'a>; fn new() -> Self { Entities @@ -41,7 +40,7 @@ impl Query for Entities { unsafe fn fetch<'a>(&self, _world: &'a World, archetype: &'a Archetype, tick: crate::Tick) -> Self::Fetch<'a> { let _ = tick; // ignore unused warnings EntitiesFetch { - entities: archetype.entity_ids.keys().cloned().collect::>(), + archetype_entities: Some(&archetype.entities), } } }