Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - introduce EntityLocation::INVALID const and adjust Entities::get comment #7623

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions crates/bevy_ecs/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ impl Entities {
self.len += 1;
AllocAtWithoutReplacement::DidNotExist
} else {
let current_meta = &mut self.meta[entity.index as usize];
let current_meta = &self.meta[entity.index as usize];
if current_meta.location.archetype_id == ArchetypeId::INVALID {
AllocAtWithoutReplacement::DidNotExist
} else if current_meta.generation == entity.generation {
Expand Down Expand Up @@ -563,7 +563,8 @@ impl Entities {
self.len = 0;
}

/// Returns `Ok(Location { archetype: Archetype::invalid(), index: undefined })` for pending entities.
/// Returns the location of an [`Entity`].
/// Note: for pending entities, returns `Some(EntityLocation::INVALID)`.
shuoli84 marked this conversation as resolved.
Show resolved Hide resolved
pub fn get(&self, entity: Entity) -> Option<EntityLocation> {
if (entity.index as usize) < self.meta.len() {
let meta = &self.meta[entity.index as usize];
Expand Down Expand Up @@ -733,12 +734,7 @@ struct EntityMeta {
impl EntityMeta {
const EMPTY: EntityMeta = EntityMeta {
generation: 0,
location: EntityLocation {
archetype_id: ArchetypeId::INVALID,
archetype_row: ArchetypeRow::INVALID, // dummy value, to be filled in
table_id: TableId::INVALID,
table_row: TableRow::INVALID, // dummy value, to be filled in
},
location: EntityLocation::INVALID,
};
}

Expand Down Expand Up @@ -771,6 +767,15 @@ pub struct EntityLocation {
pub table_row: TableRow,
}

impl EntityLocation {
const INVALID: EntityLocation = EntityLocation {
shuoli84 marked this conversation as resolved.
Show resolved Hide resolved
archetype_id: ArchetypeId::INVALID,
archetype_row: ArchetypeRow::INVALID,
table_id: TableId::INVALID,
table_row: TableRow::INVALID,
};
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down