1 import ./deferred_command.bend as Deferred 2 import Base 3 import ./clock_state.bend as Clock 4 import ./world.bend as W 5 import ./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. 9 def cancel_pending(~S:Data,~C:Type,~R:Type,~E:Data,world:W.World) -> W.World: 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} 12 def progress_join(~S:Data,~C:Type,~R:Type,~E:Data,namespace:U32,store:C,resource:R,events:List<&2,E>,pending:List>>,registrations:List<&2,W.RegistrationMeta>,nextSystemId:U32,clock:Clock.State,observed:Alloc.Allocator & Bool) -> W.World & Bool: 13 match observed: 14 case (allocator,accepted):(W.World{namespace,allocator,store,resource,events,pending,registrations,nextSystemId,clock},accepted) 15 def advance_floor(~S:Data,~C:Type,~R:Type,~E:Data,world:W.World,floor:U32) -> W.World & 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 19 def room(~S:Data,~C:Type,~R:Type,~E:Data,world:W.World,floor:U32,needed:Nat) -> W.World & 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))