entity_key.bend

bendvy-ecs-core@0.1.0.1 · 24 lines · 0 definitions

1import Base
2
3# Detached entity slot index and generation. This key has no world namespace
4# or liveness proof; use a World.Handle and checked operations for authority.
5# Generation wrap follows the allocator contract, not eternal key uniqueness.
6type Key is Data:
7  EntityKey{index:U32,generation:U32}
8
9# Return only the slot index, discarding generation for this observation.
10# Equal indices do not establish equal entity identities or valid handles.
11def index(key:Key) -> U32:
12  match key:
13    case EntityKey{index,_}:index
14
15# Return the stored generation without validating a live entity or world.
16def generation(key:Key) -> U32:
17  match key:
18    case EntityKey{_,generation}:generation
19
20# Compare both slot index and generation. Does not compare world namespaces
21# or establish liveness; World handle validation remains required.
22def equal(left:Key,right:Key) -> Bool:
23  match left right:
24    case EntityKey{li,lg} EntityKey{ri,rg}:Bool.and(U32.is_eq(li,ri),U32.is_eq(lg,rg))