diff options
author | HampusM <hampus@hampusmat.com> | 2024-11-02 21:11:55 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-11-02 21:13:30 +0100 |
commit | f71f967a8d804181038116fe2ad9776c08ddcfbc (patch) | |
tree | ea668d78f5ff513d709cad329b7ba631fdff0dca /ecs/src/entity.rs | |
parent | 61dfbc23b9d68b39eee388fd0bc7df4d02da61f9 (diff) |
feat(ecs): add creating static entities
Diffstat (limited to 'ecs/src/entity.rs')
-rw-r--r-- | ecs/src/entity.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ecs/src/entity.rs b/ecs/src/entity.rs index abc5991..18f229a 100644 --- a/ecs/src/entity.rs +++ b/ecs/src/entity.rs @@ -1,5 +1,9 @@ use std::sync::atomic::{AtomicU64, Ordering}; +use linkme::distributed_slice; + +use crate::World; + static NEXT_UID: AtomicU64 = AtomicU64::new(0); /// Unique entity ID. @@ -28,3 +32,29 @@ impl Uid } } } + +#[macro_export] +macro_rules! static_entity { + ($visibility: vis $ident: ident, $components: expr) => { + $visibility static $ident: ::std::sync::LazyLock<$crate::entity::Uid> = + ::std::sync::LazyLock::new(|| $crate::entity::Uid::new_unique()); + + $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)]; |