feat(m4): cap map images at Full HD and shrink on import (#85)

The owner fixed the map cap at 1920 px on the long side and 1080 px on the
short side (either orientation). fff-vtt import now shrinks a larger source
with ImageMagick Lanczos before tiling (alpha kept, proportions preserved,
no upscaling), prints `scaled WxH -> WxH`, and records the shrunk w/h; a
source at or below the cap is untouched, so the pixel-identity tests still
hold. A scene row already above the cap is not rewritten: the server logs
`map_above_cap` at startup and serve prints the re-import advice.

Docs: ADR-0023, DESIGN 3.3/5.3/8/11.1/13/14, TESTING 5.3/13, README,
HANDOFF-M4, client README. The M4 phone gate and the fogbench measurement
now use the Full HD maximum; the 16384 px / 262144-cell bench and test rows
stay as labelled server stress references. import-scale now proves a 16384²
input is shrunk to 1080x1080 (289 tiles at 64 px) quickly and bounded.

Part of #63, #85. #77 is blocked by this issue.
This commit is contained in:
2026-11-21 22:37:34 +01:00
parent 52ab50d765
commit a79d809394
22 changed files with 515 additions and 193 deletions
+27 -15
View File
@@ -42,9 +42,12 @@ To import a map on the same first start, pass `--image` (an offline import runs
a fresh state dir is created and migrated first):
```sh
devbox run serve -- --image=run/map16384.png --tile-size=64
devbox run serve -- --image=run/map16384.png
```
Any single-frame PNG or WebP works: images larger than Full HD (1920 px long side, 1080 px short
side) are shrunk automatically on import (see below), so no tile-size juggling is needed.
Everything after `--` reaches the script (#84: devbox 0.17.2 needs the `"$@"` suffix in
`devbox.json`); an unknown or unusable flag fails loudly instead of being ignored. To check the
parsed options without building anything: `devbox run serve -- --dry-run`.
@@ -105,14 +108,21 @@ ImageMagick comes from the root devbox.
```sh
# stop the server first, then:
devbox run -- ./run/fff-vtt import --state-dir=run --image=/path/to/map.png --tile-size=64
devbox run -- ./run/fff-vtt import --state-dir=run --image=/path/to/map.png
# restart the server with the usual command
```
**Any map image works, up to Full HD.** The cap is 1920 px on the long side and 1080 px on the
short side (either orientation). A larger source is shrunk with ImageMagick's Lanczos filter before
tiling, keeping proportions and alpha, and the import says what it did:
`scaled 4000×3000 → 1440×1080`. Smaller images are imported as-is; nothing is upscaled. The scene's
`w,h` become the (possibly shrunk) image size. A 16384×16384 source therefore becomes 1080×1080 —
1156 tiles at 32 px or 289 at 64 px, not the ~30k a 16384 map used to need.
| argument | meaning |
|---|---|
| `--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) |
| `--tile-size=<px>` | tile edge, default the scene's current tile size; must be a positive multiple of the 32 px explored cell (32 is the default, 64 a common larger choice) |
| `--scene=<id>` | target scene; v1 has exactly one, id 1 |
| `--state-dir=<path>` | the same state dir as the server (default `run`); created and migrated if absent |
@@ -126,18 +136,20 @@ cell, a malformed state DB, or a server still holding the state-dir lock (exit 3
Slicing streams: one ImageMagick decode of the source supplies raw row bands, and a small pool of
`magick` children cuts one tile row each (live caches and file descriptors are bounded by the worker
count, never by the tile count). A long import reports where it is on stderr, e.g.
`rows 128/256, tiles 32768/65536`; a failure prints the image, the row band and ImageMagick's own
message.
count, never by the tile count). An import reports where it is on stderr, e.g.
`rows 12/34, tiles 720/2040` for a Full HD map at 32 px; a failure prints the image, the row band and
ImageMagick's own message.
**A 16384 px scene with 50 tokens (the phone-playtest target).**
**A Full HD 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). On this 16-core box such an import takes about
20 s and peaks near 400 MB RSS (the old one-shot crop died at 4-8 GB and 65k fds, #83); the
decode still uses ImageMagick's disk-backed pixel cache, so allow a few GB of temp space.
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).
1. Use any single-frame PNG or WebP. Anything larger than 1920×1080 (long side × short side) is
shrunk to the cap automatically. The Full HD maximum is 60×34 = 2040 tiles at 32 px (30×17 = 510
at 64 px); a 16384×16384 square becomes 1080×1080, i.e. 34×34 = 1156 tiles at 32 px (17×17 = 289
at 64 px). The shrink uses ImageMagick's disk-backed pixel cache, so a huge source needs a few GB
of temp space but bounded RSS.
2. Start with the import in one step: `devbox run serve -- --image=run/map16384.png`
(or stop the server, run `fff-vtt import` as above, then restart it). The import prints
`scaled 16384×16384 → 1080×1080` before the tile report.
3. Create the 50 tokens with the seeding tool, not 50 panel submits (a rerun does not double up):
```sh
@@ -332,8 +344,8 @@ panel); it needs USB debugging, the overlay does not.
| `devbox run e2e` | builds `client/dist`, then drives headless Chromium against the real server through the TLS/HTTP2 test nginx |
| `devbox run mutation` | mutation suite on a temp copy of `server/`, `tests/`, `tools/`: every seeded mutation must fail at least one test |
| `devbox run bench` | release-build bench of the vision and egress paths, writing `results/bench.log` |
| `devbox run fogbench` | the 50-token / 16384 px server measurement, writing `results/m4-fog-bench.log`; the numbers live in `results/m4-fog-bench.md` |
| `devbox run import-scale` | the map import at target scale: 16384×16384 at 64 px (65,536 tiles) under a 256-fd limit, asserting bounded RSS/fds and progress, writing `results/import-scale.log`; ~25 s, too slow for the pre-push gate (`test` skips it) |
| `devbox run fogbench` | the 50-token / Full HD (1920×1080, the max scene) server measurement, writing `results/m4-fog-bench.log`; the numbers live in `results/m4-fog-bench.md` |
| `devbox run import-scale` | the map import at the old huge-input scale: a 16384×16384 source shrunk to 1080×1080 (289 tiles at 64 px) under a 256-fd limit, asserting bounded RSS/fds, the printed shrink and progress, writing `results/import-scale.log`; too slow for the pre-push gate (`test` skips it) |
| `devbox run -- nimble install -d -y` | install/refresh the pinned Nim dependencies |
| `devbox run -- bash -c 'cd client && npm ci && npm run dev'` | Vite dev server on :5173 — the UI only, no server API behind it |