ludic/examples/networking/net_snapshot.ludic
Orkuncakilkaya fb728bbefe chore(repo): DX cleanup — categorise examples, text-diffable golden, build/ output (#27 #28 #30)
Repository-cleanup / DX pass folding three tracker items into one coherent
change, verified green end to end (`bin/x test` 49/0, `bin/x selfhost-test`
29/0, `bin/x test-tools` 29/0).

#28 — curate & categorise examples/
- 42 flat entries regrouped into intent-revealing subdirs: games/, rendering/,
  ecs/, events/, networking/, lang/, library/ (was lib/).
- chronorift dir-vs-file duplication resolved: the entry file and its import
  modules now live together under games/chronorift(.ludic).
- Every path reference updated repo-wide (test runner, editor-tool drivers,
  docs/site, design docs).
- New examples/README.md indexes the whole set with run commands.
- Showcase examples without a self-asserting entry (hello, events, net_rt) now
  get a compile-only rot guard in `bin/x test`, so nothing here rots silently.

#30 — text-diffable golden baseline
- The 4 binary selfhost/golden/*.ppm blobs are replaced by a single
  selfhost/golden/renders.sha256 manifest (SHA-256 per render). Hashes are
  byte-identical to the old PPMs, so the baseline is unchanged — only its form.
- game_case now compares framebuffer hashes; a regression shows as a changed
  hex line in review, not "binary files differ".
- New `bin/x golden` regenerates the manifest deliberately (review with
  `git diff selfhost/golden/renders.sha256`).

#27 — PPM & asset handling
- Headless renders now write build/out.ppm, never the repo root; `x app`,
  `x clean`, messaging and .gitignore updated to match. Nothing is written to
  the working root any more.
- Redundant local Kenney .zip archives removed (the art ships extracted;
  .gitignore already excludes *.zip). CC0 License.txt files retained.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 18:54:21 +03:00

29 lines
1.3 KiB
Text

# net_snapshot.ludic — N1: whole-world snapshot to a memory buffer
# (NETWORKING-DESIGN §5, §13 N1). The rollback/replication substrate.
#
# save()/load() snapshot the entire ECS world to a file; world_size/world_save/
# world_load generalize the identical layout to a caller-owned memory buffer:
# world_size() -> exact snapshot byte count
# world_save(buf) -> bytes written (entities, components, vars)
# world_load(buf, len) -> restore the world from those bytes
# That is all rollback needs (save → predict → on misprediction restore and
# re-sim) and all state replication needs (snapshot → ship → apply). This program
# spawns a Unit (hp 50), snapshots the world, mutates hp to 7, then restores — hp
# reads back 50. Prints 50 / 7 / 50, driven entirely from Ludic (no C host).
program NetSnapshot {
property Health { hp: int = 0, max: int = 0 }
model Unit { Health }
entry {
spawn Unit { Health { hp: 50, max: 100 } }
let buf = bytes(world_size())
for (Health) in query [Health, {Unit}] {
print(Health.hp) # 50
let n = world_save(buf) # snapshot the whole world
Health.hp = 7
print(Health.hp) # 7
world_load(buf, n) # roll the world back
print(Health.hp) # 50 — restored from bytes
}
}
}