ecs: fix issue with Entities query returning the incorrect entity ids
This commit is contained in:
parent
4a0d003181
commit
4162150c5f
|
@ -2,21 +2,20 @@ use crate::{archetype::Archetype, World, Entity};
|
||||||
|
|
||||||
use super::{Fetch, Query, AsQuery};
|
use super::{Fetch, Query, AsQuery};
|
||||||
|
|
||||||
pub struct EntitiesFetch {
|
pub struct EntitiesFetch<'a> {
|
||||||
entities: Vec<Entity>,
|
archetype_entities: Option<&'a [Entity]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Fetch<'a> for EntitiesFetch {
|
impl<'a> Fetch<'a> for EntitiesFetch<'a> {
|
||||||
type Item = Entity;
|
type Item = Entity;
|
||||||
|
|
||||||
unsafe fn get_item(&mut self, entity: crate::world::ArchetypeEntityId) -> Self::Item {
|
unsafe fn get_item(&mut self, entity: crate::world::ArchetypeEntityId) -> Self::Item {
|
||||||
let e = *self.entities.get_unchecked(entity.0 as usize);
|
self.archetype_entities.unwrap()[entity.0 as usize]
|
||||||
e
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dangling() -> Self {
|
fn dangling() -> Self {
|
||||||
Self {
|
Self {
|
||||||
entities: vec![],
|
archetype_entities: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +26,7 @@ pub struct Entities;
|
||||||
impl Query for Entities {
|
impl Query for Entities {
|
||||||
type Item<'a> = Entity;
|
type Item<'a> = Entity;
|
||||||
|
|
||||||
type Fetch<'a> = EntitiesFetch;
|
type Fetch<'a> = EntitiesFetch<'a>;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Entities
|
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> {
|
unsafe fn fetch<'a>(&self, _world: &'a World, archetype: &'a Archetype, tick: crate::Tick) -> Self::Fetch<'a> {
|
||||||
let _ = tick; // ignore unused warnings
|
let _ = tick; // ignore unused warnings
|
||||||
EntitiesFetch {
|
EntitiesFetch {
|
||||||
entities: archetype.entity_ids.keys().cloned().collect::<Vec<Entity>>(),
|
archetype_entities: Some(&archetype.entities),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue