ordinary_component_despawn.bend
bendvy-ecs-core@0.1.0.0 · 34 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.0/column.bend as Col
3import bendvy-ecs-core@0.1.0.0/world.bend as W
4import bendvy-ecs-core@0.1.0.0/ordinary_declaration.bend as Identity
5import bendvy-ecs-core@0.1.0.0/ordinary_component_binding.bend as Binding
6import bendvy-ecs-core@0.1.0.0/commands.bend as Cmd
7import bendvy-ecs-core@0.1.0.0/transaction.bend as Tx
8
9def handle_id(~S:Data,handle:W.Handle<S>) -> U32:
10 match handle:
11 case W.Handle{_,key}:W.handle_index(~S,W.Handle{0,key})
12def accepted(~S:Data,~Store:Type,~Rest:Type,~P:Type,~E:Data,~put:Rest -> Col.Column<S,P> -> Store,~emit:W.Handle<S> -> E,rest:Rest,+handle:W.Handle<S>,result:Col.SwapOutcome<S,P>) -> Store & List<&2,E>:
13 match result:
14 case Col.Accepted{column,Some{_}}:(put(rest,column),[emit(handle)])
15 case Col.Accepted{column,None{}}:(put(rest,column),[])
16 case Col.Rejected{column,_}:(put(rest,column),[])
17def leaf_taken(~S:Data,~Store:Type,~Rest:Type,~P:Type,~E:Data,~put:Rest -> Col.Column<S,P> -> Store,~emit:W.Handle<S> -> E,+handle:W.Handle<S>,taken:Rest & Col.Column<S,P>) -> Store & List<&2,E>:
18 (rest,column)=taken
19 accepted(~S,~Store,~Rest,~P,~E,~put,~emit,rest,handle,Col.clear(~S,~P,column,handle_id(~S,handle)))
20def leaf_record(~S:Data,~Store:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:Store -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> Store,~view:P -> P & V,~E:Data,~inject:Identity.Declaration<S,P> -> W.Handle<S> -> E,~binding:Binding.Binding<S,Store,Rest,P,V,Token,take,put,view>,handle:W.Handle<S>) -> E:
21 inject(Binding.identity(~S,~Store,~Rest,~P,~V,~Token,~take,~put,~view,binding),handle)
22def leaf(~S:Data,~Store:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:Store -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> Store,~view:P -> P & V,~E:Data,~inject:Identity.Declaration<S,P> -> W.Handle<S> -> E,~binding:Binding.Binding<S,Store,Rest,P,V,Token,take,put,view>,store:Store,handle:W.Handle<S>) -> Store & List<&2,E>:
23 leaf_taken(~S,~Store,~Rest,~P,~E,~put,~leaf_record(~S,~Store,~Rest,~P,~V,~Token,~take,~put,~view,~E,~inject,~binding),handle,take(store))
24def append(~Store:Type,~E:Data,first:List<&2,E>,second:Store & List<&2,E>) -> Store & List<&2,E>:
25 (store,records)=second
26 (store,List.append(&2,E,first,records))
27def product_next(~S:Data,~Store:Type,~E:Data,~right:Store -> W.Handle<S> -> Store & List<&2,E>,handle:W.Handle<S>,first:Store & List<&2,E>) -> Store & List<&2,E>:
28 (store,records)=first
29 append(~Store,~E,records,right(store,handle))
30def product(~S:Data,~Store:Type,~E:Data,~left:Store -> W.Handle<S> -> Store & List<&2,E>,~right:Store -> W.Handle<S> -> Store & List<&2,E>,store:Store,+handle:W.Handle<S>) -> Store & List<&2,E>:
31 product_next(~S,~Store,~E,~right,handle,left(store,handle))
32
33def despawn(~S:Data,~C:Type,~R:Type,~E:Data,~clear:C -> W.Handle<S> -> C & List<&2,E>,~record:W.Handle<S> -> E,tx:Tx.Tx<W.World<S,C,R,E>,E>,handle:W.Handle<S>) -> Tx.Tx<W.World<S,C,R,E>,E> & W.Status:
34 Cmd.tx_despawn_observed(~S,~C,~R,~E,~clear,~record,tx,handle)