registration.bend

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

1import Base
2import bendvy-ecs-core@0.1.0.1/world.bend as W
3
4# Remove exact registration identity, preserving every other system instance.
5# IDs are monotonic and are not recycled by disposal.
6def retained(keep: Bool,meta: W.RegistrationMeta,rest: List<&2,W.RegistrationMeta>) -> List<&2,W.RegistrationMeta>:
7  match keep:
8    case True{}: meta <> rest
9    case False{}: rest
10
11def without(registrations: List<&2,W.RegistrationMeta>,+id: U32,+name: String,+access: List<&2,String>) -> List<&2,W.RegistrationMeta>:
12  match registrations:
13    case []: []
14    case +meta <> rest: retained(Bool.not(W.registration_meta_matches(meta,id,name,access)),meta,without(rest,id,name,access))
15
16def remove_checked(~S: Data,~Store: Type,~R: Type,~E: Data,allowed: Bool,world: W.World<S,Store,R,E>,+id: U32,+name: String,+access: List<&2,String>) -> W.World<S,Store,R,E> & Bool:
17  match allowed world:
18    case False{} world: (world,False{})
19    case True{} W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock}: (W.World{namespace,allocator,store,resource,events,pending,without(registrations,id,name,access),nextSystemId,clock},True{})
20
21def remove(~S: Data,~Store: Type,~R: Type,~E: Data,world: W.World<S,Store,R,E>,namespace: U32,+id: U32,+name: String,+access: List<&2,String>) -> W.World<S,Store,R,E> & Bool:
22  match world:
23    case W.World{+actual,allocator,store,resource,events,pending,+registrations,nextSystemId,clock}: remove_checked(~S,~Store,~R,~E,Bool.and(U32.is_eq(namespace,actual),W.registration_list_matches(registrations,id,name,access)),W.World{actual,allocator,store,resource,events,pending,registrations,nextSystemId,clock},id,name,access)