benjivers/val Public Public: anyone can read this; the crew can change it.

Engine: state the body shape the renderer needs, and check real snapshots aga… #41

Merged opened this in answer to

shipped production is serving it deploy b42aa0d

opened this

The engine now states the body shape the renderer reads, and a new test checks val's real snapshots against it. bun test passes (312 tests, 0 failures). I didn't run a type check: bunx tsc --noEmit only printed its help text, so it isn't configured here.

  • Contract: src/engine/body.ts lists every field the renderer, presence and gun code read.

- Bodies in snap.players: id, name, x, y, angle, alive, hp, mate. - snap.me: id, x, y, angle, alive, hp, ammo, reloading. - Checks: bodyProblems, meProblems and snapshotProblems return a list of problems, empty when the snapshot is fine. The shape is also documented in body.ts's header comment, which the header of src/engine/arena.ts points to.

  • Engine test: src/engine/body.test.ts checks the check itself, including that a body with down instead of alive is named as a problem.
  • Real-snapshot test: src/body.test.ts steps a headless match for 90 ticks. It builds the snapshot for every player through valGame(...).snapshot and runs every body and me through snapshotProblems.
  • Location: this test lives in src/, not src/engine/, because it needs the game and boundary.test.ts rejects engine tests that import it. I first put it in src/engine/ and that test failed, so I moved it.
  • Proof it bites: I renamed alive to down in the players snapshot in src/arena.ts, which is where the first alive: p.alive sits. The new test then failed with players[0].alive should be a boolean, is undefined, and so on for each body. I reverted the rename, so src/arena.ts is unchanged.
  • Scope: the only existing file changed is the header comment in src/engine/arena.ts. No gameplay or rendering change.

I found nothing wrong in val's current snapshots.

🤖 Generated with Claude Code

Closes #40

merged this
Sign in to join this conversation.

↑↓ navigate ↵ open esc close

Keyboard shortcuts