ordinary_machine_schedule.bend
bendvy-ecs-core@0.1.0.4 · 39 lines · 8 definitions
1import Base
2import bendvy-ecs-core@0.1.0.4/schedule.bend as Sch
3import bendvy-ecs-core@0.1.0.4/world.bend as W
4import bendvy-ecs-core@0.1.0.4/system.bend as Sys
5
6
7type Declaration<-S:Data> is Data: Declaration{name:String}
8
9def declare(~S:Data,name:String) -> Declaration<S>:Declaration{name}
10def phase_name(id:U32) -> String:
11 match id:
12 case 1:"apply"
13 case 2:"exit"
14 case 3:"transition"
15 case _:"enter"
16
17
18def steps() -> List<&2,Sch.Step>:[Sch.Barrier{},Sch.Phase{phase_name(1)},Sch.System{1,0},Sch.Phase{phase_name(2)},Sch.System{2,0},Sch.Phase{phase_name(3)},Sch.System{3,0},Sch.Phase{phase_name(4)},Sch.System{4,0}]
19
20
21def install(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Error:Data,declaration:Declaration<S>,namespace:U32,owners:H) -> Sch.Build<S,C,R,E,H>:
22 match declaration:
23 case Declaration{name}:Sch.build(~S,~C,~R,~E,~H,namespace,name,steps(),[1,2,3,4],owners)
24
25
26
27def dispatch(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Error:Data,~apply:H -> W.World<S,C,R,E> -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~exit:H -> W.World<S,C,R,E> -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~transition:H -> W.World<S,C,R,E> -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~enter:H -> W.World<S,C,R,E> -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,owners:H,world:W.World<S,C,R,E>,id:U32) -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>:
28 match id:
29 case 1:apply(owners,world)
30 case 2:exit(owners,world)
31 case 3:transition(owners,world)
32 case _:enter(owners,world)
33
34def condition(~S:Data,~C:Type,~R:Type,~E:Data,world:W.World<S,C,R,E>,_:U32) -> W.World<S,C,R,E> & Bool:(world,True{})
35
36
37
38
39def run(~S:Data,~C:Type,~R:Type,~E:Data,~H:Type,~Error:Data,~apply:H -> W.World<S,C,R,E> -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~exit:H -> W.World<S,C,R,E> -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~transition:H -> W.World<S,C,R,E> -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,~enter:H -> W.World<S,C,R,E> -> H & Sys.Outcome<W.World<S,C,R,E>,Error,Unit>,schedule:Sch.Schedule<S,C,R,E,H>,world:W.World<S,C,R,E>) -> Sch.RunResult<S,C,R,E,H,Error>:Sch.run(~S,~C,~R,~E,~H,~Error,~dispatch(~S,~C,~R,~E,~H,~Error,~apply,~exit,~transition,~enter),~condition(~S,~C,~R,~E),schedule,world)