From fd42ca5a25f8bab3ea66252f8bc0db02604f70dd Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 1 Aug 2024 16:11:15 +0200 Subject: feat(ecs): add relationships --- ecs/src/entity.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 ecs/src/entity.rs (limited to 'ecs/src/entity.rs') diff --git a/ecs/src/entity.rs b/ecs/src/entity.rs new file mode 100644 index 0000000..abc5991 --- /dev/null +++ b/ecs/src/entity.rs @@ -0,0 +1,30 @@ +use std::sync::atomic::{AtomicU64, Ordering}; + +static NEXT_UID: AtomicU64 = AtomicU64::new(0); + +/// Unique entity ID. +#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct Uid +{ + inner: u64, +} + +impl Uid +{ + pub fn new(uid: u64) -> Self + { + debug_assert!( + uid < NEXT_UID.load(Ordering::Relaxed), + "Invalid entity UID {uid}" + ); + + Self { inner: uid } + } + + pub fn new_unique() -> Self + { + Self { + inner: NEXT_UID.fetch_add(1, Ordering::Relaxed), + } + } +} -- cgit v1.2.3-18-g5258