restore_world.bend
bendvy-ecs-core@0.1.0.1 · 21 lines · 0 definitions
1import bendvy-ecs-core@0.1.0.1/deferred_command.bend as Deferred
2import Base
3import bendvy-ecs-core@0.1.0.1/clock_state.bend as Clock
4import bendvy-ecs-core@0.1.0.1/world.bend as W
5import bendvy-ecs-core@0.1.0.1/entity_allocator.bend as Alloc
6
7# Internal owner adapter. Pending commands are discarded, never invoked.
8# The namespace, live payload owners and registration cursors are preserved.
9def cancel_pending(~S:Data,~C:Type,~R:Type,~E:Data,world:W.World<S,C,R,E>) -> W.World<S,C,R,E>:
10 match world:
11 case W.World{namespace,allocator,store,resource,events,_,registrations,nextSystemId,clock}:W.World{namespace,Alloc.abandon_pending(allocator),store,resource,events,[],registrations,nextSystemId,clock}
12def progress_join(~S:Data,~C:Type,~R:Type,~E:Data,namespace:U32,store:C,resource:R,events:List<&2,E>,pending:List<Deferred.Command<W.World<S,C,R,E>>>,registrations:List<&2,W.RegistrationMeta>,nextSystemId:U32,clock:Clock.State,observed:Alloc.Allocator & Bool) -> W.World<S,C,R,E> & Bool:
13 match observed:
14 case (allocator,accepted):(W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock},accepted)
15def advance_floor(~S:Data,~C:Type,~R:Type,~E:Data,world:W.World<S,C,R,E>,floor:U32) -> W.World<S,C,R,E> & Bool:
16 match world:
17 case W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock}:progress_join(~S,~C,~R,~E,namespace,store,resource,events,pending,registrations,nextSystemId,clock,Alloc.advance_floor(allocator,floor))
18
19def room(~S:Data,~C:Type,~R:Type,~E:Data,world:W.World<S,C,R,E>,floor:U32,needed:Nat) -> W.World<S,C,R,E> & Bool:
20 match world:
21 case W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock}:progress_join(~S,~C,~R,~E,namespace,store,resource,events,pending,registrations,nextSystemId,clock,Alloc.restore_room(allocator,floor,needed))