snapshot.bend
bendvy-ecs-core@0.1.0.1 · 32 lines · 0 definitions
1import Base
2import entity_key.bend as Key
3import bendvy-ecs-core@0.1.0.1/snapshot_schema.bend as Schema
4import bendvy-ecs-core@0.1.0.1/snapshot_data.bend as Export
5import bendvy-ecs-core@0.1.0.1/decode_data.bend as D
6import bendvy-ecs-core@0.1.0.1/world.bend as W
7
8def 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)
11def 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))
14def rows(~S:Data,~C:Type,~components:U32 -> C -> C & List<&2,D.Field>,handles:List<&2,W.Handle<S>>,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.
31def 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<S,C,R,True{},components,resources>,world:W.World<S,C,R,E>) -> W.World<S,C,R,E> & Export.Outcome<Export.Snapshot>:
32 Export.basic(~S,~C,~R,~E,~rows(~S,~C,~components),~resources,world)