pub(crate) struct ScopeTree {
parents: EntityHashMap<Entity>,
children: EntityHashMap<Vec<Entity>>,
}Expand description
The parent and child links of every live entity.
Fields§
§parents: EntityHashMap<Entity>§children: EntityHashMap<Vec<Entity>>Implementations§
Source§impl ScopeTree
impl ScopeTree
Sourcepub(crate) fn attach(&mut self, entity: Entity, parent: Entity)
pub(crate) fn attach(&mut self, entity: Entity, parent: Entity)
Record that entity lives in parent, dropping its old link.
Sourcepub(crate) fn detach(&mut self, entity: Entity)
pub(crate) fn detach(&mut self, entity: Entity)
Drop entity’s link to its parent, keeping its children linked to it.
Sourcepub(crate) fn parent(&self, entity: Entity) -> Result<Entity, EntityAccessError>
pub(crate) fn parent(&self, entity: Entity) -> Result<Entity, EntityAccessError>
The parent of entity.
Every live entity is attached to the tree in the same step that gives it a row, so a handle missing from it names no live entity.
Sourcepub(crate) fn is_descendant(&self, ancestor: Entity, entity: Entity) -> bool
pub(crate) fn is_descendant(&self, ancestor: Entity, entity: Entity) -> bool
Whether entity is strictly below ancestor in the tree.
A walk up the parent chain rather than an interval comparison: the tree is as deep as a scene nests, which is a handful of levels, while an interval index would have to be rebuilt over the whole world on every spawn. The walk is bounded by the number of nodes so that a corrupted index cannot loop forever.
Sourcepub(crate) fn subtree_post_order(&self, root: Entity) -> Vec<Entity>
pub(crate) fn subtree_post_order(&self, root: Entity) -> Vec<Entity>
The subtree rooted at root, deepest first.
Post-order is what a cascade despawn needs: a child is removed before the parent it lived in, so a child’s callback still sees living ancestors.