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

forked from trevato/cs · proposes · 4 behind

Start the engine package: math and tracing move to src/engine/, and a test keeps the game out #6

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

`src/engine/` now exists as the part a second game could use: `math.ts` and `trace.ts` moved out of `src/client/` verbatim, with `math.test.ts` alongside them. The proof the move changed nothing is the bundle — rebuilding produced `static/app.e8ca965610.js`, byte-for-byte the file that was already committed, so there is no new bundle in this diff and the build test stays green on the old one.

shipped production is serving it deploy ae07c2d

opened this

src/engine/ now exists as the part a second game could use: math.ts and trace.ts moved out of src/client/ verbatim, with math.test.ts alongside them. The proof the move changed nothing is the bundle — rebuilding produced static/app.e8ca965610.js, byte-for-byte the file that was already committed, so there is no new bundle in this diff and the build test stays green on the old one.

Box ({ min, max, mat }) is now written in src/engine/trace.ts, since the tracer is what it exists for, and src/client/map.ts re-exports the type so every call site in the game still imports it from the map. Every importer moved with it: nothing under src/client/, src/rl/ or scripts/ reaches for ./math.ts or ./trace.ts any more.

The thing to look at is src/engine/boundary.test.ts. It reads every .ts under src/engine/, pulls the import specifiers straight out of the source, and fails if one of them leaves the engine — ../client, ../rl or a bare package name. I pointed trace.ts at ../client/map.ts by hand and it went red with trace.ts: "../client/map.ts" resolves outside src/engine/, then restored it. A test in there may also use bun:test and node: builtins, which is how the boundary test reads the sources; neither ships in the bundle, and the rule is spelled out in the file's comment. One quirk worth knowing: the check reads its own source too, so an import written literally in a comment or a fixture string fails it — the docstring and the extraction fixture are both phrased to avoid that, and the fixture spells from at run time for exactly that reason.

trace.ts also gains the test it never had: eight ray-vs-box cases with the entry fractions worked out by hand (a face at half the segment, a ray stopping short, misses on each axis, a start inside the box, and a corner-on ray whose last-crossed axis decides the normal), plus nearest-of-several through traceWorld and visible as an empty trace.

README.md gains the src/engine/ line under Shape and drops math from the src/client/ list. bun test is 118 passing across 16 files; / answers in 15 ms serving the same bundle, and scripts/train.ts still runs through the new paths. I did not rewrite anything inside the two modules — this issue is the boundary, not a rewrite — and I left the rest of src/client/ where it is.

🤖 Generated with Claude Code

Closes #2

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs