|  | 
| 2 | 2 | //! | 
| 3 | 3 | //! An **entity** exclusively owns zero or more [component] instances, all of different types, and can dynamically acquire or lose them over its lifetime. | 
| 4 | 4 | //! | 
|  | 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 | +//! | 
| 5 | 10 | //! See [`Entity`] to learn more. | 
| 6 | 11 | //! | 
| 7 | 12 | //! [component]: crate::component::Component | 
| @@ -498,7 +503,7 @@ impl Entities { | 
| 498 | 503 |             self.len += 1; | 
| 499 | 504 |             AllocAtWithoutReplacement::DidNotExist | 
| 500 | 505 |         } else { | 
| 501 |  | -            let current_meta = &mut self.meta[entity.index as usize]; | 
|  | 506 | +            let current_meta = &self.meta[entity.index as usize]; | 
| 502 | 507 |             if current_meta.location.archetype_id == ArchetypeId::INVALID { | 
| 503 | 508 |                 AllocAtWithoutReplacement::DidNotExist | 
| 504 | 509 |             } else if current_meta.generation == entity.generation { | 
| @@ -563,7 +568,8 @@ impl Entities { | 
| 563 | 568 |         self.len = 0; | 
| 564 | 569 |     } | 
| 565 | 570 | 
 | 
| 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)`. | 
| 567 | 573 |     pub fn get(&self, entity: Entity) -> Option<EntityLocation> { | 
| 568 | 574 |         if (entity.index as usize) < self.meta.len() { | 
| 569 | 575 |             let meta = &self.meta[entity.index as usize]; | 
| @@ -731,14 +737,10 @@ struct EntityMeta { | 
| 731 | 737 | } | 
| 732 | 738 | 
 | 
| 733 | 739 | impl EntityMeta { | 
|  | 740 | +    /// meta for **pending entity** | 
| 734 | 741 |     const EMPTY: EntityMeta = EntityMeta { | 
| 735 | 742 |         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, | 
| 742 | 744 |     }; | 
| 743 | 745 | } | 
| 744 | 746 | 
 | 
| @@ -771,6 +773,16 @@ pub struct EntityLocation { | 
| 771 | 773 |     pub table_row: TableRow, | 
| 772 | 774 | } | 
| 773 | 775 | 
 | 
|  | 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 | + | 
| 774 | 786 | #[cfg(test)] | 
| 775 | 787 | mod tests { | 
| 776 | 788 |     use super::*; | 
|  | 
0 commit comments