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
+22 -17
View File
@@ -1,10 +1,11 @@
## M4 fog benchmark (#76): the 50-token, 16384 px tile map measurement the finish ticket records
## in `results/m4-fog-bench.md`. `devbox run fogbench` compiles and runs it; the log lands in
## `results/m4-fog-bench.log`.
## M4 fog benchmark (#76): the 50-token, Full HD (1920x1080) tile map measurement the finish ticket
## records in `results/m4-fog-bench.md`. `devbox run fogbench` compiles and runs it; the log lands in
## `results/m4-fog-bench.log`. The Full HD cap is the owner decision of 2026-11-21 (#85), so this is
## the product maximum, not the old 16384 px stress map.
##
## Two numbers the phone gate needs to make sense of:
## 1. server recompute on a move: one player's vision refresh (one polygon, ~5k sparse walls,
## 16384 px map) plus the egress pass for that player with 50 visible tokens;
## 1. server recompute on a move: one player's vision refresh (one polygon, 5k-wall generator
## clipped to the Full HD scene) plus the egress pass for that player with 50 visible tokens;
## 2. the client's headless frame time is measured separately by `client/e2e/fogbench.test.mjs`
## (SwiftShader, so it is a floor, never the phone number it is compared with).
##
@@ -26,31 +27,35 @@ proc bench(name: string, n: int, f: proc(i: int)): float =
echo &"{name}: n={n} avg={sum / n.float:.3f}ms worst={worst:.3f}ms"
sum / n.float
const World = 16384.0
const
WorldW = 1920.0
WorldH = 1080.0
const PlayerId = 2
## 50 tokens: the player's one sighted token at the map centre, 49 NPCs inside its radius. The
## cluster is the phone scene (50 tokens rendered with the fog on), so the wall generator's walls
## inside that box are removed: the sight cost still comes from the ~5k walls elsewhere.
## inside that box are removed. The 5k-wall generator runs on a WorldW square and is clipped to the
## Full HD height, so the sight cost still comes from thousands of walls elsewhere.
proc build(): ref ContextStore =
var tokens: seq[TokenRec]
tokens.add TokenRec(id: "vision-token", scene: 1, kind: "pc", descriptiveName: "Ann",
actualName: "Ann", pos: (World / 2, World / 2), owner: PlayerId,
actualName: "Ann", pos: (WorldW / 2, WorldH / 2), owner: PlayerId,
flags: %*{"vision": true}, visionRadius: some(300.0), radius: some(20.0),
props: newProps())
for i in 0 ..< 49:
let dx = float((i mod 7) - 3) * 28.0
let dy = float((i div 7) - 3) * 28.0
tokens.add TokenRec(id: &"npc-{i}", scene: 1, kind: "npc", descriptiveName: &"T{i}",
actualName: &"T{i}", pos: (World / 2 + dx, World / 2 + dy),
actualName: &"T{i}", pos: (WorldW / 2 + dx, WorldH / 2 + dy),
owner: GmControlled, flags: %*{}, props: newProps())
let centre = World / 2
let centre = (WorldW / 2, WorldH / 2)
var walls: seq[WallRec]
var id = 0
for w in genScene(World, 5000, 1):
let near = max(w.a.x, w.b.x) >= centre - 400 and min(w.a.x, w.b.x) <= centre + 400 and
max(w.a.y, w.b.y) >= centre - 400 and min(w.a.y, w.b.y) <= centre + 400
for w in genScene(WorldW, 5000, 1):
if w.a.y > WorldH or w.b.y > WorldH: continue # clipped away by the Full HD scene height
let near = max(w.a.x, w.b.x) >= centre[0] - 400 and min(w.a.x, w.b.x) <= centre[0] + 400 and
max(w.a.y, w.b.y) >= centre[1] - 400 and min(w.a.y, w.b.y) <= centre[1] + 400
if near: continue
inc id
walls.add WallRec(id: id, a: w.a, b: w.b, thickness: 0, position: wpCenter,
@@ -60,7 +65,7 @@ proc build(): ref ContextStore =
flags: newJObject())
result = (ref ContextStore)(scene: SceneRec(
id: 1, name: "Scene", w: World, h: World, tileSize: 32, cell: 32,
id: 1, name: "Scene", w: WorldW, h: WorldH, tileSize: 32, cell: 32,
visionRadiusDefault: 400, tokenRadiusDefault: 20, artVersion: 1, nextWallId: id + 1,
extra: newJObject(), walls: walls), tokens: tokens)
for pid in 2 .. 7:
@@ -70,11 +75,11 @@ proc build(): ref ContextStore =
result.encountered[pid] = initTable[string, characters.EncounteredEntry]()
let store = build()
echo &"== M4 fog bench: 16384 px map, cell 32 ({store.scene.cols}x{store.scene.rows} cells), " &
echo &"== M4 fog bench: Full HD map 1920x1080, cell 32 ({store.scene.cols}x{store.scene.rows} cells), " &
&"{store.tokens.len} tokens, {store.scene.walls.len} walls =="
# 1. A move refreshes the mover's player: one polygon + its explored cells (main.refreshPlayer).
let refreshAvg = bench("server vision refresh, one player (1 polygon, radius 300, ~5k walls)", 500, proc(i: int) =
let refreshAvg = bench("server vision refresh, one player (1 polygon, radius 300, 5k-wall generator clipped to the scene)", 500, proc(i: int) =
store.visions[PlayerId].refresh(store.scene, store.tokens, PlayerId)
sink += store.visions[PlayerId].polys.len)
@@ -95,7 +100,7 @@ discard egressFrames(Recipient(isGm: false, playerId: PlayerId), ctx, warmKnown)
discard bench("player egress pass, warm Known (no changes)", 2000, proc(i: int) =
sink += egressFrames(Recipient(isGm: false, playerId: PlayerId), ctx, warmKnown).len)
echo &"explored snapshot size: {store.visions[PlayerId].explored.card} cells on the 16384 px map"
echo &"explored snapshot size: {store.visions[PlayerId].explored.card} cells on the Full HD map"
let budget = 16.7
echo &"TARGET move path: refresh + 50-token egress {refreshAvg + egressAvg:.3f} ms vs <= {budget} ms " &
&"(one 60 fps frame): {(if refreshAvg + egressAvg <= budget: \"PASS\" else: \"MISS\")}"