{"path":"README.md","content":"# Neon Drift\n\nReal-time light-cycle battle royale (2–16 players) on one Cloudflare Worker + Durable Objects.\n\n## Run\n`npm install`, `npm run dev`, `npm test`, `npm run bots -- <baseUrl> --bots 8`.\n\n## How to play\nSteer with ← → / A D, boost with Space. On touch hold the left/right half to turn; double-tap or use two fingers to boost. Touching any trail or leaving the shrinking arena eliminates you; kills +50, orbs +10, survival +1/s.\n\n## Architecture\n- `src/index.ts` routes; `src/room.ts` Room DO (30 Hz authoritative, hibernation WebSockets); `src/lobby.ts` room registry; `src/leaderboard.ts` D1 (graceful without DB).\n- `public/shared/sim.js` deterministic simulation shared by server and client prediction.\n- `public/net.js` prediction, reconciliation, interpolation; `render.js`, `fx.js`, `audio.js`, `input.js` presentation; `app.js` + `ui-helpers.js` landing page and HUD. CSP in `public/_headers`.\n\n## Protocol (compact JSON arrays)\nClient: `[\"j\",name,token,tick]`, `[\"i\",seq,turn,boost,ackTick]`, `[\"a\",tick]`, `[\"p\",ms]`.\nServer: `[\"w\",...]` welcome, `[\"s\",tick,baseTick,seq,delta]` snapshot with appended trail points only, `[\"o\",...]` pong, `[\"v\",tick,...events]` batched events, `[\"e\",code,msg]`.\n\n## Routes\n`/health`, `POST /api/rooms`, `/api/quickplay`, `/api/leaderboard?mode=arena`, `/ws/<CODE>`, `/r/<CODE>`.\n\n\n## Local development\n\n- `npm run dev` starts `wrangler dev`. The leaderboard creates its table on first use, so local D1 works without setup; you can also run `wrangler d1 migrations apply DB --local`.\n- UI flow: `/` is the landing page only; `/r/<code>` shows a compact join sheet over a blurred live view (the client joins watch-only, join field 5 = 1, then sends a normal join on the same socket).\n- UI files: `public/app.js` (bootstrap + HUD), `public/index.html`, `public/style.css`, `public/_headers` (CSP), `public/ui-helpers.js` (pure helpers), `src/index.ts`, `src/lobby.ts`, `src/leaderboard.ts`.\n\n## How to play\nRide a light cycle, leave a trail, and avoid every trail (and the arena edge). Grab orbs for points and boost, take kills for +50, and outlast the shrinking arena. Last rider wins; matches restart automatically.\n\n## Controls\n- Keyboard: ← → or A D steer, Space boosts. M-style mute button in the HUD (remembered).\n- Touch: hold the left or right half to turn, double-tap or two-finger hold to boost.\n\n## Architecture\n```\nbrowser (app.js, render.js, net.js, input.js)\n   │  WebSocket (JSON messages)\nWorker (src/index.ts) ──► Room Durable Object (src/room.ts, shared sim public/shared/sim.js)\n   │                         └─ 30 Hz tick, snapshots + event batches\n   └─► Lobby DO / Leaderboard (D1)\n```\n\n## Protocol summary\nClient → server: inputs (turn, boost, seq, ack tick), `[\"a\", tick]` acks, pings. Server → client: welcome, snapshots (full then deltas), `[\"v\", tick, ...events]` event batches. Excess traffic earns strikes; 3 strikes close with 1008.\n\n## Performance (measured)\n| Metric | Value |\n|---|---|\n| Client fps, 16 players | TBD |\n| Snapshots/s per client | TBD |\n| Mean delta snapshot size | TBD |\n| 16-player sim step | TBD |\n\n## Measured performance\n\n| Metric | Device | Result |\n| --- | --- | --- |\n| Client FPS | _TBD_ | _TBD_ |\n| Snapshot size (bytes) | _TBD_ | _TBD_ |\n| RTT (ms) | _TBD_ | _TBD_ |\n","commitSha":"3efe3da4da489bc55fed83e415b6a4216413c591"}