summaryrefslogtreecommitdiff
path: root/ecs/src/entity.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-08-01 16:11:15 +0200
committerHampusM <hampus@hampusmat.com>2024-08-02 15:34:54 +0200
commitfd42ca5a25f8bab3ea66252f8bc0db02604f70dd (patch)
tree6d384b5f462e2699342372f6b56791fc4607e9c6 /ecs/src/entity.rs
parent70c7d745f918dd23343599963a619539f4f880cb (diff)
feat(ecs): add relationships
Diffstat (limited to 'ecs/src/entity.rs')
-rw-r--r--ecs/src/entity.rs30
1 files changed, 30 insertions, 0 deletions
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),
+ }
+ }
+}