feat(m4): playtest friction: perf overlay, fresh import, token seed (#82)

Opt-in ?perf=1 overlay (fps, frame p50/p95, JS p50/p95, tokens, zoom; no node or ticker work when off). fff-vtt import creates and migrates a fresh/empty state dir through the shared server startup path; devbox run serve gains --image. devbox run seed creates deterministic labelled NPC tokens over the real WS (idempotent rerun, --replace), and the GM token form defaults X/Y to the viewport centre.
This commit is contained in:
2026-11-21 17:20:05 +01:00
parent 356705823b
commit 9c7f9de910
20 changed files with 933 additions and 53 deletions
+41 -7
View File
@@ -36,6 +36,13 @@ in front of the server (the server itself stays on `127.0.0.1`), and prints:
- the GM key (created on first run; an existing key is printed, never replaced),
- the certificate-trust steps for Android Chrome and for a laptop (Linux/macOS/Firefox).
To import a map on the same first start, pass `--image` (an offline import runs before the server;
a fresh state dir is created and migrated first):
```sh
devbox run serve -- --image=run/map16384.png --tile-size=64
```
Ctrl-C stops nginx and the server and releases the port; the next start works. State (`state.db`,
`tiles/`), the GM key and the certificate live under `run/lan` and are **not** wiped, so a session
survives a restart and a phone that trusted the certificate does not have to trust it again.
@@ -86,7 +93,9 @@ sign-in page.
The map is a source image plus a tiled copy the server gates per player. One offline command slices
the image and updates the scene; the server must be **stopped** for it (it reads the scene once at
startup) and restarted afterwards. ImageMagick comes from the root devbox.
startup) and restarted afterwards. The command also works on a fresh/empty state dir: it creates
the directory, migrates the DB and seeds the scene through the same startup path as the server.
ImageMagick comes from the root devbox.
```sh
# stop the server first, then:
@@ -99,23 +108,32 @@ devbox run -- ./run/fff-vtt import --state-dir=run --image=/path/to/map.png --ti
| `--image=<path>` | source PNG or WebP (required); tiles are always PNG |
| `--tile-size=<px>` | tile edge, default the scene's current tile size; must be a positive multiple of the 32 px explored cell (so 32 or the 64 px fallback) |
| `--scene=<id>` | target scene; v1 has exactly one, id 1 |
| `--state-dir=<path>` | the same state dir as the server (default `run`) |
| `--state-dir=<path>` | the same state dir as the server (default `run`); created and migrated if absent |
Tiles land in `<state-dir>/tiles/1/v<art_version>/<x>_<y>.png`, origin at the world origin, which is
exactly what the gate parses and nginx's internal `/_tiles/` alias serves. The command sets the
scene's width, height and tile size from the image. Importing again grows `art_version` and writes a
new `v` directory, so browsers never keep a stale tile; old versions stay on disk until the M6
cleanup. Any problem exits non-zero and writes nothing: a missing/unreadable source or state dir, an
cleanup. Any problem exits non-zero and writes no tiles: a missing/unreadable source, an
unsupported or multi-frame image, a scene other than 1, a tile size that is not a multiple of the
cell, or a server still holding the state-dir lock (exit 3).
cell, a malformed state DB, or a server still holding the state-dir lock (exit 3).
**A 16384 px scene with 50 tokens (the phone-playtest target).**
1. Prepare a 16384×16384 PNG or WebP. `--tile-size=64` is the designed fallback and gives 256×256 =
65,536 tiles (32 px would give 262,144 files); ImageMagick keeps the source in a disk-backed
pixel cache, so allow temp space and a few minutes rather than gigabytes of RAM.
2. Stop the server, run the import above, restart it.
3. Create the 50 tokens with the GM token panel (or the `token.create` intent); tokens, walls and
2. Start with the import in one step: `devbox run serve -- --image=run/map16384.png --tile-size=64`
(or stop the server, run `fff-vtt import` as above, then restart it).
3. Create the 50 tokens with the seeding tool, not 50 panel submits (a rerun does not double up):
```sh
NODE_EXTRA_CA_CERTS=run/lan/tls/cert.pem \
devbox run seed -- --url=https://<lan-ip>:8443 --tokens=49 --vision=1
```
`--replace` clears the labelled `Seed NN` tokens first; `--seed` changes the deterministic
layout; the GM token panel's X/Y now default to the current viewport centre. Tokens, walls and
explored state are untouched by the import.
4. Point nginx's `/_tiles/` alias at `<state-dir>/tiles` as shown below.
@@ -194,7 +212,8 @@ backup timer) exists in the repo yet; that is M6.
only after they have explored a cell that overlaps it; the GM
always gets every tile. Because one 32 px cell is the unit of disclosure, do not paint secret
doors, traps or notes into map art near places players can reach — keep secrets as GM-only tokens.
4. **Tokens.** *Create token* takes a kind, a descriptive name, an actual name, a position, a radius
4. **Tokens.** *Create token* takes a kind, a descriptive name, an actual name, a position (X/Y
default to the current viewport centre), a radius
(blank = scene default), a `gm_only` flag and a controller (a player, or blank for the GM).
*Select* a token to edit or remove it, resize it, or add and clear `stuck`/`squeezed` statuses.
The GM may drag any token; a player only their own.
@@ -243,6 +262,21 @@ Still missing entirely:
5. The badge shows `connected`, `reconnecting` or `offline`. A dropped connection keeps the map on
screen and retries; the server then resyncs everything.
### Measure fps on the phone
Open the site with `?perf=1` appended to the URL (for example
`https://192.168.1.50:8443/?perf=1`). After sign-in a small overlay appears in the top-right:
```
fps 59.8 · frame p50 16.6 p95 17.1 ms · JS p50 1.20 p95 2.40 ms · tokens 50 · zoom 1.00
```
It is off by default and adds no per-frame work when off. The line is computed over the last 10 s:
`fps` and the frame interval from the render loop, and `JS` is the main-thread time from the first
ticker listener to after the render submission, so it is an upper bound on the app's JS cost.
`chrome://inspect/#devices` remains the optional cross-check (Frame Rendering Stats + Performance
panel); it needs USB debugging, the overlay does not.
### When something goes wrong
- **"Key not recognised."** — wrong or unknown key; the server deliberately says the same thing for