Skip to content

Commit 609ad5a

Browse files
committed
introduce EntityLocation::INVALID const and adjust Entities::get comment (#7623)
also remove one un-needed mut.
1 parent cd1737e commit 609ad5a

File tree

1 file changed

+20
-8
lines changed
  • crates/bevy_ecs/src/entity

1 file changed

+20
-8
lines changed

crates/bevy_ecs/src/entity/mod.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
//!
33
//! An **entity** exclusively owns zero or more [component] instances, all of different types, and can dynamically acquire or lose them over its lifetime.
44
//!
5+
//! **empty entity**: Entity with zero components.
6+
//! **pending entity**: Entity reserved, but not flushed yet (see [`Entities::flush`] docs for reference).
7+
//! **reserved entity**: same as **pending entity**.
8+
//! **invalid entity**: **pending entity** flushed with invalid (see [`Entities::flush_as_invalid`] docs for reference).
9+
//!
510
//! See [`Entity`] to learn more.
611
//!
712
//! [component]: crate::component::Component
@@ -498,7 +503,7 @@ impl Entities {
498503
self.len += 1;
499504
AllocAtWithoutReplacement::DidNotExist
500505
} else {
501-
let current_meta = &mut self.meta[entity.index as usize];
506+
let current_meta = &self.meta[entity.index as usize];
502507
if current_meta.location.archetype_id == ArchetypeId::INVALID {
503508
AllocAtWithoutReplacement::DidNotExist
504509
} else if current_meta.generation == entity.generation {
@@ -563,7 +568,8 @@ impl Entities {
563568
self.len = 0;
564569
}
565570

566-
/// Returns `Ok(Location { archetype: Archetype::invalid(), index: undefined })` for pending entities.
571+
/// Returns the location of an [`Entity`].
572+
/// Note: for pending entities, returns `Some(EntityLocation::INVALID)`.
567573
pub fn get(&self, entity: Entity) -> Option<EntityLocation> {
568574
if (entity.index as usize) < self.meta.len() {
569575
let meta = &self.meta[entity.index as usize];
@@ -731,14 +737,10 @@ struct EntityMeta {
731737
}
732738

733739
impl EntityMeta {
740+
/// meta for **pending entity**
734741
const EMPTY: EntityMeta = EntityMeta {
735742
generation: 0,
736-
location: EntityLocation {
737-
archetype_id: ArchetypeId::INVALID,
738-
archetype_row: ArchetypeRow::INVALID, // dummy value, to be filled in
739-
table_id: TableId::INVALID,
740-
table_row: TableRow::INVALID, // dummy value, to be filled in
741-
},
743+
location: EntityLocation::INVALID,
742744
};
743745
}
744746

@@ -771,6 +773,16 @@ pub struct EntityLocation {
771773
pub table_row: TableRow,
772774
}
773775

776+
impl EntityLocation {
777+
/// location for **pending entity** and **invalid entity**
778+
const INVALID: EntityLocation = EntityLocation {
779+
archetype_id: ArchetypeId::INVALID,
780+
archetype_row: ArchetypeRow::INVALID,
781+
table_id: TableId::INVALID,
782+
table_row: TableRow::INVALID,
783+
};
784+
}
785+
774786
#[cfg(test)]
775787
mod tests {
776788
use super::*;

0 commit comments

Comments
 (0)