1 import Base 2 import ./clock_state.bend as Clock 3 import ./deferred_command.bend as Deferred 4 import entity_allocator.bend as Alloc 5 import machine.bend as M 6 import world.bend as W 7 8 # Closed resource lenses adapt machine slots to the existing actual ECS world. 9 # No component store or affine resource is projected to Data or copied. 10 def take_join(~S: Data,~K: Data,~V: Data,~C: Type,~R: Type,~E: Data, 11 +ns: U32,allocator:Alloc.Allocator, 12 store: C,split: R & M.Slot,+events: List<&2,E>,commands:List<&1,Deferred.Command>>, 13 +registrations: List<&2,W.RegistrationMeta>,+nextSystem: U32,+clock:Clock.State 14 ) -> W.World & M.Slot: 15 (resources,slot)=split 16 (W.World{ns,allocator,store,resources,events,commands,registrations,nextSystem,clock},slot) 17 18 def take(~S: Data,~K: Data,~V: Data,~C: Type,~R: Type,~E: Data, 19 ~take_resource: R -> R & M.Slot,world: W.World) -> W.World & M.Slot: 20 match world: 21 case W.World{ns,allocator,store,resources,events,commands,registrations,nextSystem,clock}: 22 take_join(~S,~K,~V,~C,~R,~E,ns,allocator,store,take_resource(resources),events,commands,registrations,nextSystem,clock) 23 24 def put(~S: Data,~K: Data,~V: Data,~C: Type,~R: Type,~E: Data, 25 ~put_resource: R -> M.Slot -> R,world: W.World,slot: M.Slot) -> W.World: 26 match world: 27 case W.World{ns,allocator,store,resources,events,commands,registrations,nextSystem,clock}: 28 W.World{ns,allocator,store,put_resource(resources,slot),events,commands,registrations,nextSystem,clock} 29 30 # ApplyDeferred only drains structural commands. Machine commits require the 31 # separate marker; callers must not conflate the two public operations. 32 def structural_flush(~S: Data,~C: Type,~R: Type,~E: Data,world: W.World) -> W.World: 33 W.barrier(~S,~C,~R,~E,world)