Skip to main content

concinnity_core/ecs/
entity_by_name.rs

1// src/ecs/entity_by_name.rs
2//
3// The name -> Entity index published by the load-time Prop decomposition pass.
4// The pass itself (`decompose::run`) lives in the client crate, but the index it
5// produces is renderer-free, so it lives here where the physics / audio subsystem
6// crates can resolve a name reference (a Prop parent, a PropBody owner, an audio
7// emitter target) to an Entity without depending on the renderer. The client
8// `ecs::decompose` module re-exports it under the historical
9// `crate::ecs::decompose::EntityByName` path.
10
11use crate::ecs::Entity;
12use crate::ecs::asset_id::AssetId;
13use alloc::collections::BTreeMap;
14
15/// Maps a placement's asset identity (its declared name) to the live Entity it
16/// was loaded into. Built by the decomposition pass so later passes can resolve
17/// a name reference (a Prop parent, a PropBody owner, an audio emitter target)
18/// to an Entity without scanning.
19#[derive(Debug, Default)]
20pub struct EntityByName(pub BTreeMap<AssetId, Entity>);
21
22impl EntityByName {
23    /// The entity a name was loaded into, if the name is known.
24    pub fn get(&self, name: AssetId) -> Option<Entity> {
25        self.0.get(&name).copied()
26    }
27}