1 import Base 2 import entity_key.bend as Key 3 import ./snapshot_schema.bend as Schema 4 import ./snapshot_data.bend as Export 5 import ./decode_data.bend as D 6 import ./world.bend as W 7 8 def prepend(~C:Type,entity:Export.Entity,observed:C & List<&2,Export.Entity>) -> C & List<&2,Export.Entity>: 9 match observed: 10 case (owner,entities):(owner,entity <> entities) 11 def stepped(~C:Type,next:C -> C & List<&2,Export.Entity>,id:Key.Key,observed:C & List<&2,D.Field>) -> C & List<&2,Export.Entity>: 12 match observed: 13 case (owner,fields):prepend(~C,Export.Entity{id,fields},next(owner)) 14 def rows(~S:Data,~C:Type,~components:U32 -> C -> C & List<&2,D.Field>,handles:List<&2,W.Handle>,owner:C) -> C & List<&2,Export.Entity>: 15 match handles: 16 case []:(owner,[]) 17 case W.Handle{_,+id} <> rest:stepped(~C,next => rows(~S,~C,~components,rest,next),id,components(Key.index(id),owner)) 18 # Public call requires the SAME complete ordinary schema to be save-eligible. 19 # Plain leaves propagate False through product and cannot call this method. 20 # Export version-1 detached entity/component/resource Data and allocator progress, 21 # returning the live World owner through every projection. Live handles supply 22 # saved keys; this is not a runtime checkpoint or an implicit structural barrier. 23 # The complete schema must carry True eligibility: persisted leaves use declared 24 # projections/codecs, while explicit transient leaves are omitted. Closed schema 25 # projections and name bindings remain trusted setup, not arbitrary descriptor 26 # validation inferred from this wrapper. The save contains no registration owners, 27 # reader positions or event-log checkpoint. Pending structural commands refuse 28 # BEFORE any projection, returning the same World/queue as RefusedPending. No 29 # implicit barrier runs; apply an explicit barrier and retry when appropriate. 30 # See docs/parity/snapshot-export.md and its ordinary constructor/save consumer. 31 def save(~S:Data,~C:Type,~R:Type,~E:Data,~components:U32 -> C -> C & List<&2,D.Field>,~resources:R -> R & List<&2,D.Field>,schema:Schema.Schema,world:W.World) -> W.World & Export.Outcome: 32 Export.basic(~S,~C,~R,~E,~rows(~S,~C,~components),~resources,world)