From 4162150c5fd20b31eaa80904a933c5cc03d26225 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Wed, 10 Apr 2024 22:27:23 -0400 Subject: [PATCH] ecs: fix issue with Entities query returning the incorrect entity ids --- lyra-ecs/src/query/entities.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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), } } }