execution_query_lifecycle.bend
bendvy-ecs-core@0.1.0.3 · 44 lines · 8 definitions
1import Base
2import bendvy-ecs-core@0.1.0.3/chunk_column.bend as Column
3import bendvy-ecs-core@0.1.0.3/execution_composer_layout.bend as L
4import bendvy-ecs-core@0.1.0.3/execution_query_store.bend as Store
5import bendvy-ecs-core@0.1.0.3/execution_query_schema.bend as Schema
6import bendvy-ecs-core@0.1.0.3/execution_query_matches.bend as Match
7import bendvy-ecs-core@0.1.0.3/execution_query_recipe.bend as Recipe
8import bendvy-ecs-core@0.1.0.3/execution_query_admission.bend as Admission
9import bendvy-ecs-core@0.1.0.3/owner_product.bend as Product
10import bendvy-ecs-core@0.1.0.3/lifecycle.bend as Life
11import bendvy-ecs-core@0.1.0.3/change_tick.bend as Tick
12
13def whole_left(~S:Data,-left:L.Layout,-right:L.Layout,other:L.columns(~S,right),result:L.columns(~S,left) & Life.Stamp) -> L.columns(~S,L.LayoutPair{left,right}) & Life.Stamp:
14 match result:
15 case (owner,stamp):(Product.Owner{owner,other},stamp)
16def whole_right(~S:Data,-left:L.Layout,-right:L.Layout,other:L.columns(~S,left),result:L.columns(~S,right) & Life.Stamp) -> L.columns(~S,L.LayoutPair{left,right}) & Life.Stamp:
17 match result:
18 case (owner,stamp):(Product.Owner{other,owner},stamp)
19def whole_cached(-S:Data,-P:Type,-V:Data,-key:String,-origin:L.Layout,index:U32,result:Column.Column<S,L.Viewed<P,V>> & List<&2,Match.Row<V>>) -> L.ColumnSlot<S,L.Viewed<P,V>,key,origin> & Life.Stamp:
20 match result:
21 case (column,rows):(L.ColumnSlot{column},Store.cached_stamp(V,rows,index))
22def whole_stamp(~S:Data,layout:L.Layout,route:L.Route,owner:L.columns(~S,layout),index:U32) -> L.columns(~S,layout) & Life.Stamp:
23 match layout route owner:
24 case L.LayoutLeaf{P,V,refresh,key,policy} L.AtLeaf{} L.ColumnSlot{column}:whole_cached(S,P,V,key,L.LayoutLeaf{P,V,refresh,key,policy},index,Schema.cache_column(S,P,V,column,0))
25 case L.ClassifiedLayoutLeaf{P,V,refresh,key,kind,policy} L.AtLeaf{} L.ColumnSlot{column}:whole_cached(S,P,V,key,L.ClassifiedLayoutLeaf{P,V,refresh,key,kind,policy},index,Schema.cache_column(S,P,V,column,0))
26 case L.LayoutPair{left,right} L.InLeft{path} Product.Owner{l,r}:whole_left(~S,left,right,r,whole_stamp(~S,left,path,l,index))
27 case L.LayoutPair{left,right} L.InRight{path} Product.Owner{l,r}:whole_right(~S,left,right,l,whole_stamp(~S,right,path,r,index))
28 case _ _ owner:(owner,Life.Stamp{None{},None{}})
29def whole_changed(~S:Data,~layout:L.Layout,prior:Maybe<&2,Tick.Tick>,tick:Tick.Tick,result:L.columns(~S,layout) & Life.Stamp) -> L.columns(~S,layout) & Bool:
30 match result:
31 case (owner,stamp):(owner,Life.changed(stamp,prior,tick))
32def whole_combine(~S:Data,~layout:L.Layout,left:Bool,and:Bool,result:L.columns(~S,layout) & Bool) -> L.columns(~S,layout) & Bool:
33 match and result:
34 case True{}, (owner,right):(owner,Bool.and(left,right))
35 case False{}, (owner,right):(owner,Bool.or(left,right))
36def whole_rest(~S:Data,~layout:L.Layout,and:Bool,next:L.columns(~S,layout) -> L.columns(~S,layout) & Bool,result:L.columns(~S,layout) & Bool) -> L.columns(~S,layout) & Bool:
37 match result:
38 case (owner,left):whole_combine(~S,~layout,left,and,next(owner))
39def whole_bound(~S:Data,~layout:L.Layout,+info:List<&2,Schema.Info>,selection:Recipe.Bound,+index:U32,+prior:Maybe<&2,Tick.Tick>,+tick:Tick.Tick,owner:L.columns(~S,layout)) -> L.columns(~S,layout) & Bool:
40 match selection:
41 case Recipe.Changed{route}:whole_changed(~S,~layout,prior,tick,whole_stamp(~S,layout,route,owner,index))
42 case Recipe.And{left,right}:whole_rest(~S,~layout,True{},(owner => whole_bound(~S,~layout,info,right,index,prior,tick,owner)),whole_bound(~S,~layout,info,left,index,prior,tick,owner))
43 case Recipe.Or{left,right}:whole_rest(~S,~layout,False{},(owner => whole_bound(~S,~layout,info,right,index,prior,tick,owner)),whole_bound(~S,~layout,info,left,index,prior,tick,owner))
44 case selection:(owner,Admission.bound(info,selection,index))