diff options
Diffstat (limited to 'ecs/src/entity.rs')
-rw-r--r-- | ecs/src/entity.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/ecs/src/entity.rs b/ecs/src/entity.rs index 3de9cd5..85e7461 100644 --- a/ecs/src/entity.rs +++ b/ecs/src/entity.rs @@ -1,6 +1,40 @@ use linkme::distributed_slice; -use crate::World; +use crate::component::storage::archetype::{Archetype, ArchetypeEntity}; +use crate::uid::Uid; +use crate::{EntityComponent, World}; + +/// A handle to a entity. +pub struct Handle<'a> +{ + archetype: &'a Archetype, + entity: &'a ArchetypeEntity, +} + +impl<'a> Handle<'a> +{ + /// Returns the [`Uid`] of this entity. + #[inline] + #[must_use] + pub fn uid(&self) -> Uid + { + self.entity.uid + } + + #[inline] + #[must_use] + pub fn get_component(&self, component_uid: Uid) -> Option<&'a EntityComponent> + { + let index = self.archetype.get_index_for_component(component_uid)?; + + Some(self.entity.components.get(index).unwrap()) + } + + pub(crate) fn new(archetype: &'a Archetype, entity: &'a ArchetypeEntity) -> Self + { + Self { archetype, entity } + } +} #[allow(clippy::module_name_repetitions)] #[macro_export] |