1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! # Entity Management
//!
//! This module defines the entity identity, lifecycle, and shard-based storage
//! used by the ECS.
//!
//! ## Purpose
//! Entities are lightweight, opaque identifiers that reference rows in archetype
//! storage. This module is responsible for:
//!
//! - Generating stable entity identifiers
//! - Tracking entity liveness via versioning
//! - Mapping entities to archetype locations
//! - Managing scalable entity allocation using sharded storage
//!
//! ## Entity Model
//! An `Entity` is a compact, versioned handle composed of:
//!
//! - A **shard ID**, identifying which shard owns the entity
//! - An **index**, identifying the slot within the shard
//! - A **version**, used to detect stale or recycled entities
//!
//! This layout allows fast validation and prevents use-after-free bugs when
//! entities are despawned and reused.
//!
//! ## Sharding
//! Entities are distributed across multiple shards (`EntityShards`) to reduce
//! contention during concurrent spawning, despawning, and lookup operations.
//!
//! Each shard maintains:
//! - A dense pool of entity slots
//! - Version counters for stale detection
//! - Location metadata pointing into archetype storage
//!
//! ## Invariants
//! - An entity is considered alive if and only if its version matches the
//! version stored in its shard and its slot is marked alive.
//! - Entity locations must always reflect the actual archetype row.
//! - Despawning an entity invalidates all previous handles to that entity.
//!
//! ## Concurrency
//! - Shards synchronize entity allocation and metadata using internal locks.
//! - Global counters are maintained using atomics for low-contention signals.
//!
//! ## Safety
//! Correctness relies on:
//! - Updating entity locations atomically with archetype row moves
//! - Never mutating entity metadata while systems hold archetype borrows
//! - Applying structural changes only at synchronization points
pub use Entity;
pub use EntityLocation;
pub use EntityShards;