diff options
Diffstat (limited to 'ecs/src/entity.rs')
| -rw-r--r-- | ecs/src/entity.rs | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/ecs/src/entity.rs b/ecs/src/entity.rs deleted file mode 100644 index 85e7461..0000000 --- a/ecs/src/entity.rs +++ /dev/null @@ -1,66 +0,0 @@ -use linkme::distributed_slice; - -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] -macro_rules! static_entity { - ($visibility: vis $ident: ident, $components: expr) => { - $visibility static $ident: ::std::sync::LazyLock<$crate::uid::Uid> = - ::std::sync::LazyLock::new(|| { - $crate::uid::Uid::new_unique($crate::uid::Kind::Entity) - }); - - $crate::private::paste::paste! { - mod [<__ecs_ $ident:lower _static_entity_priv>] { - use super::*; - - #[$crate::private::linkme::distributed_slice( - $crate::entity::CREATE_STATIC_ENTITIES - )] - #[linkme(crate=$crate::private::linkme)] - static CREATE_STATIC_ENTITY: fn(&$crate::World) = |world| { - world.create_entity_with_uid($components, *$ident); - }; - } - } - } -} - -#[distributed_slice] -#[doc(hidden)] -pub static CREATE_STATIC_ENTITIES: [fn(&World)]; |
