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

forked from trevato/cs

Assets become engine: a mesh builder, a texture painter and a sound device; the game keeps its recipes #4

shipped production is serving it opened this has it
opened this

Everything this game generates at start-up is made with three generic tools; move the tools into the engine and leave the CS-shaped recipes in the game.

Done looks like

  • [ ] src/engine/mesh.ts: Mesh, builder, finish, addBox, quadMesh — the primitive and nothing about this game. src/client/models.ts keeps levelMesh, playerMesh, bombMesh and viewModelMesh, built with it.
  • [ ] src/engine/texture.ts: hash, noise, fbm, the Shader type and paintAtlas(shaders, size), returning the tightly packed RGBA an array texture wants. The nine material shaders move to src/client/materials.ts, which exports the list plus TEX_SIZE and LAYERS — LAYERS derived from the list length, not written twice.
  • [ ] src/engine/sound.ts: a device that opens an AudioContext lazily, holds the noise buffer, and exposes noiseBurst, tone, resume, muted and a distance-attenuation helper. src/client/audio.ts stays the game's voice — the weapon-to-tone table, shot, hit, beep — built on the device, and createAudio() keeps its signature so main.ts does not change.
  • [ ] Tests that would fail without the change: addBox makes twelve triangles with outward normals and uv tiling at the scale asked; paintAtlas returns size*size*4*layers opaque, deterministic bytes and clamps a shader that returns out-of-range values; the attenuation helper falls off with distance and never exceeds 1.
  • [ ] The atlas is byte-identical to today's: take the sha256 of materialTextures() before the move and assert the same digest after, so the map cannot change colour by accident.
  • [ ] bun test green, the bundle rebuilt and the new static/app.<hash>.js committed, and the preview looks and sounds exactly as it does now.

Files I expect to change

src/engine/{mesh,texture,sound}.ts and their tests (new), src/client/models.ts, src/client/textures.ts → src/client/materials.ts, src/client/audio.ts, src/client/renderer.ts import lines, README.md, static/app.<hash>.js.

Risks

Three moves in one change: do them one at a time, run bun test between, and keep the commits separate so a bisect means something. Renaming textures.ts moves a concept — every importer of LAYERS and TEX_SIZE has to follow it. The sound device is the one piece with no test coverage possible in Bun; keep the untestable part to the AudioContext wiring and put the arithmetic where a test can reach it.

Whose brief fits

Vesper — procedural assets and noise written by hand is the brief.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs