relation_cleanup_control.bend

bendvy-ecs-core@0.1.0.3 · 27 lines · 4 definitions

1import Base
2import bendvy-ecs-core@0.1.0.3/relation_types.bend as T
3import bendvy-ecs-core@0.1.0.3/entity_key.bend as Key
4
5# Both storage adapters execute this same cleanup continuation. Intents carry
6# identities and descriptors only; they contain no World mutator or owner.
7type Intent<-S:Data> is Data:
8  Check{key:Key.Key,descriptors:List<&2,T.Descriptor<S>>,frames:List<&2,T.CleanupFrame<S>>}
9  Observe{key:Key.Key,descriptor:T.Descriptor<S>,remaining:List<&2,T.Descriptor<S>>,frames:List<&2,T.CleanupFrame<S>>}
10  Unrelate{key:Key.Key,descriptor:T.Descriptor<S>,frames:List<&2,T.CleanupFrame<S>>}
11  Finish{key:Key.Key,frames:List<&2,T.CleanupFrame<S>>}
12  Continue{frames:List<&2,T.CleanupFrame<S>>}
13def child_intent(-S:Data,kind:T.RelationKind,+key:Key.Key,+descriptor:T.Descriptor<S>,remaining:List<&2,T.Descriptor<S>>,child:Key.Key,children:List<&2,Key.Key>,frames:List<&2,T.CleanupFrame<S>>) -> Intent<S>:
14  match kind:
15    case T.Hierarchy{}:Continue{T.CleanupEnter{child} <> T.CleanupChildren{key,descriptor,remaining,children} <> frames}
16    case T.Ordinary{}:Unrelate{child,descriptor,T.CleanupChildren{key,descriptor,remaining,children} <> frames}
17def kind(-S:Data,descriptor:T.Descriptor<S>) -> T.RelationKind:
18  match descriptor:
19    case T.Descriptor{_,_,_,kind}:kind
20def next(-S:Data,frame:T.CleanupFrame<S>,descriptors:List<&2,T.Descriptor<S>>,frames:List<&2,T.CleanupFrame<S>>) -> Intent<S>:
21  match frame:
22    case T.CleanupEnter{key}:Check{key,descriptors,frames}
23    case T.CleanupDescriptors{key,[]}:Continue{T.CleanupFinish{key} <> frames}
24    case T.CleanupDescriptors{key,descriptor <> remaining}:Observe{key,descriptor,remaining,frames}
25    case T.CleanupChildren{+key,descriptor,remaining,[]}:Unrelate{key,descriptor,T.CleanupDescriptors{key,remaining} <> frames}
26    case T.CleanupChildren{key,+descriptor,remaining,child <> children}:child_intent(S,kind(S,descriptor),key,descriptor,remaining,child,children,frames)
27    case T.CleanupFinish{key}:Finish{key,frames}