docs: point DESIGN §5 at TESTING; move vision/bench proof out

Edge-case counts and bug regressions, the perf table and bench scenes, oracle
citations, the move-rule regression baseline, the see-over oracle spec and the
thickness/joint measurements move to TESTING §5.1-§5.10. Targets, the 5k-wall
gate and the accepted thickness cost stay in DESIGN.
This commit is contained in:
2026-11-17 23:22:06 +01:00
parent 6837bbcf11
commit bc10780625
2 changed files with 53 additions and 75 deletions
+51 -71
View File
@@ -690,9 +690,8 @@ explored_chunk(player_id, scene_id, cx, cy, bits BLOB, PRIMARY KEY(player_id, sc
holds only walls whose sight switch is on; an open door and a window (`blocks_sight:false`) are
absent from it, and a one-way wall is skipped for a viewer on its blind side (5.8).
- **Explored**: `cellsTouched(poly, cell)` marks every grid cell that the polygon overlaps; union
into the player's explored set. Vertex-in-cell test added after a bug (polygon wholly inside one
cell) [MEASURED bug log, prototype `NOTES.md`; covered by `tests/tgeometry.nim`, suite "cells",
test "tiny polygon inside one cell"].
into the player's explored set. The vertex-in-cell case is handled (bug log and its regression test:
TESTING §5.1).
- **Token visibility** to a player: token centre inside any of the player's polygons (even-odd
`inside`).
- **Move validation (prototype)**: inclusive segment intersection on blocking walls (touching =
@@ -700,54 +699,45 @@ explored_chunk(player_id, scene_id, cx, cy, bits BLOB, PRIMARY KEY(player_id, sc
radius from every blocking wall. Replaced by the M2 rules in 5.5; the prototype result is a
baseline only.
### 5.2 Edge cases handled and tested [MEASURED, `tests/tgeometry.nim`; M1 port baseline (history): 33 test blocks / 98 checks, none dropped; current count: 92 `[OK]` test cases in `results/nimble-test.log` (M2, 2026-11-08)]
### 5.2 Edge cases handled
These are the cases the algorithm handles. Proven by: TESTING §5.2 (port baseline, regression tests).
- Collinear rays skipped (neighbouring +-eps rays cover them).
- Token standing on an endpoint: that endpoint skipped, hits at t <= 1e-9 ignored.
- T-junction, shared vertex, free-standing wall, '<' apex, box corner, behind-viewer fan, long thin
corridor.
- Angle-sort bug: circle angles must use the same (-pi, pi] range as wall angles (`atan2(sin,cos)`),
otherwise bow-tie polygon (position dependent) [MEASURED bug, prototype `NOTES.md`
"Post-phase-3"]. Regression test: `tests/tgeometry.nim`, suite "visibility", test "wall endpoints
behind the viewer: fan stays angularly ordered".
- Vision circle is an inscribed 64-gon: error <= ~0.12% of R [MEASURED, prototype `NOTES.md`].
- Circle angles must use the same (-pi, pi] range as wall angles (`atan2(sin,cos)`), otherwise the
polygon is a bow-tie (position dependent).
- Vision circle is an inscribed 64-gon: error <= ~0.12% of R.
### 5.3 Performance [MEASURED; single laptop, release build, loopback, power-save CPU; `results/bench.log`, `results/concurrency-final1-server.log`]
| item | avg | worst |
|---|---|---|
| 1 visibility polygon (prototype scene, 60 walls) | 0.038 ms | 0.18 ms |
| 1 polygon + `cellsTouched` | 0.451 ms | 0.98 ms |
| 6 polygons + `cellsTouched` | 2.95 ms | 3.73 ms |
| server vision recompute per player move (incl. cells + diff) | 1.18 ms | 4.55 ms |
| door toggle (2 players) | 0.20 ms | 0.30 ms |
| monster move | ~0 | 0.024 ms |
### 5.3 Performance
Targets and accepted decisions. The measured table, the bench scenes and the regression gate are in
TESTING §5.3.
Conclusions:
- `cellsTouched` is ~12x the polygon itself and dominates [MEASURED]. M2 target: replace per-cell
polygon tests with scanline rasterization of the polygon over the explored grid,
differential-tested against the ported implementation [PROPOSED].
- Polygon cost is O(rays x walls in bbox) [MEASURED code reading, `server/geometry.nim`
`visibilityPolygon` (ported unchanged from prototype)]. Prototype scene has 60 walls and 8 tokens,
so this says nothing about big maps. With radius-bbox culling the cost scales with local wall
density, not total walls [INFERRED]; a uniform spatial grid over walls is needed when scenes reach
thousands of walls (M2 gate: bench with a synthetic 5k-wall scene, target polygon < 1 ms [PROPOSED
test target, Q2: owner has no map size yet; revisit with real maps]). The 5k target is the sparse
primary layout `genScene(16384, 5000, 1)` (`tools/scenegen.nim`): 0.082 ms avg [MEASURED,
`results/bench.log`]. The dense layout `genScene(4096, 5000, 1)` is a stress reference (1.28 ms
avg, ~207 walls in the vision bbox) [MEASURED]; revisit the uniform grid if real maps approach
that density.
`visibilityPolygon`, ported unchanged from the prototype]. With radius-bbox culling the cost scales
with local wall density, not total walls [INFERRED]; a uniform spatial grid over walls is needed only
if the 5k-wall target is missed (M2 gate: bench with a synthetic 5k-wall scene, target polygon < 1 ms
[PROPOSED test target, Q2: owner has no map size yet; revisit with real maps]).
- Cell marking dominated the prototype's polygon cost, so M2 replaced per-cell polygon tests with
scanline rasterization of the polygon over the explored grid, differential-tested against the ported
implementation [PROPOSED; built in M2].
- Skip recompute when the token moved but its polygon is unchanged (prototype already compares `np
== r.polys`).
- **Thickness cost** [#43, 5.10]: a thick body is a quad, and the fan costs about 10x on a dense
scene (13.2 ms vs 1.25 ms baseline on the 5k dense layout; 0.26 ms per polygon, 3.15x, on the 5k
sparse one). The owner accepted that and re-baselined the per-move budget [FIXED (owner decision),
#43]; polygon optimisation is deferred. The quad is hoisted per wall edit, so the extra cost is in
the fan, never in per-viewer geometry.
scene. The owner accepted that and re-baselined the per-move budget [FIXED (owner decision), #43];
polygon optimisation is deferred. The quad is hoisted per wall edit, so the extra cost is in the
fan, never in per-viewer geometry.
- **Load/perf regression gate:** the bench and concurrency numbers are compared with committed
baselines; fail on > 2x regression [PROPOSED]. Numbers and method: TESTING §5.3.
### 5.4 Known limitations (carry forward)
- Token exactly on a wall cannot move off it: `moveBlocked` counts any touch as a hit, so every move
from that point is blocked, even a perpendicular step to the open side [MEASURED limit,
`tests/tgeometry.nim` test "KNOWN LIMITATION: token exactly on a wall cannot move off it"; also in
the `server/geometry.nim` header]. Known limitation, not a policy. Fixed in M2 by the escape rule
from that point is blocked, even a perpendicular step to the open side [MEASURED limit; the test is
named in TESTING §5.4 and the limit is in the `server/geometry.nim` header]. Known limitation, not a
policy. Fixed in M2 by the escape rule
(5.5). The escape is required by Q14 so the GM can move such a token: mechanism [PROPOSED],
requirement [FIXED]. A validated move cannot reach this state (a destination within r of a wall is
rejected) [INFERRED from `moveBlocked`]; it arises from a wall/door edit (`stuck` trigger, 5.5) or
@@ -762,8 +752,8 @@ Conclusions:
by the 5.5 move-rule tests: under the 5.5 trigger such a token is `stuck`, so its player moves are
refused.
- Boundary epsilon ambiguity (RayEps 1e-4, inclusive tolerances).
- Explored and tile checks in the leak test recompute with the server's own `cellsTouched`:
self-consistency only (caveat in 10.2). New independent oracle in section 10.
- The prototype's leak-test explored and tile checks were self-consistent only; the independent
oracle and its remaining caveat are in TESTING §5.4, §10.2.
- Doors/walls changing does not un-explore anything; explored only grows [MEASURED behaviour].
- Single uniform vision radius in prototype; v1 uses a per-entity numeric property (`vision_radius`)
with scene default; no light/darkvision [FIXED, Q7].
@@ -771,8 +761,9 @@ Conclusions:
### 5.5 Move rules and statuses (M2 decisions, 2026-11-08; status model 2026-11-10, #4)
Normative for M2. Replaces the prototype move validation (5.1) and the move-related limitations in
4.2 and 5.4. Implemented as a pure in-process module with unit tests; the WebSocket layer only maps
its result to `ack` (6.1). The WebSocket probing test is M3.
4.2 and 5.4. Implemented as a pure in-process module; the WebSocket layer only maps its result to
`ack` (6.1). Proven by: TESTING §5.5 (in-process pins, the zero-thickness regression gate, the WS
probing test).
Notation: token centre `c`, radius `r` (entity `radius` if set, else scene `token_radius_default`;
5.6), start `s`, destination `d`. Blocking wall: segment with `blocks_movement` on, and for a door
@@ -830,7 +821,7 @@ magic grasp); `squeezed` = pressed, no room (walls around it, closing hand).
q1 = 0`, so `c' = foot + n·σ·(sqrt(r^2 - e^2) + PushEps)`, which is today's `pushFrom` term for
term — keep that arithmetic shape (`foot` from the same projection, `perp = sqrt(max(0, r^2 -
e^2)) + PushEps`, then `foot + n·σ·perp`), so a zero-thickness door returns identical values on
the same inputs; the unchanged existing tests are the regression gate (10.3). *Validity:* the
the same inputs; the unchanged existing tests are the regression gate (TESTING §5.5). *Validity:* the
pushed position must be in bounds and `>= r` from every blocking wall's body (the closed door
included, other thick bodies included), using the same rectangle-distance primitive as the
collider (5.10); else the opposite side is tried; if neither is valid the token stays and gets
@@ -882,11 +873,7 @@ walls only if the 5k-wall bench misses target (13, M2).
**Thresholds and tolerances** [FIXED, accepted default]: `eps` and any float tolerance are chosen by
the implementer and documented in the module header. Oracle comparisons use 0.5 px, as the leak
checker (T14).
**Regression baseline** [FIXED, accepted default]: "results equal old implementation" =
`visibilityPolygon` and `cellsTouched` on the prototype leak transcripts plus
`tests/fixtures/scene.json`. `moveBlocked` is excluded: its results change on purpose.
checker (T14); the oracle side is TESTING §5.5.
**Unconfirmed** [PROPOSED, owner to confirm]: `wall.update` counts as remove + add for the status
rule. (A door opened while another wall overlaps does not clear `stuck`: the Keep rule above,
@@ -944,8 +931,8 @@ migration are settled by #49 (6.1, 8).
field itself [FIXED (owner-delegated), 2026-11-17, #49]:** `height` is a typed wall field, metres,
a finite number `> 0` and `<= 100`; absent or `null` means full height and is stored as SQL
`NULL`, never as `0` or `100`. It is set by `wall.add`/`wall.update` (6.1), stored as a wall
column (8), and carried only on the GM's `wall`/`walls` frames — it is in leakcheck's
`BannedAlways` (`WALLDATA`, 10.3) because no player frame ever carries it. 100 m is a finite wall:
column (8), and carried only on the GM's `wall`/`walls` frames because no player frame ever carries
it (leakcheck's `BannedAlways`, TESTING §5.7). 100 m is a finite wall:
every legal figure is `<= 100 m` tall and equality is hidden (5.9), so a 100 m wall hides
everyone, and `NULL` differs from it only in a hypothetical taller thing.
- **GM-only.** Both keys are in the `gm` bucket, so no player frame carries either: the `token`
@@ -1027,9 +1014,9 @@ What a wall's behaviour is made of. Heights are 5.7; what a low wall does to sig
and — for a marked wall only — the marker (next two bullets). Consequences: a closed secret door
must give byte-identical player frames and identical refusals to a solid wall of the same
switches; a locked door is just a closed door to sight and movement; no refusal names locked,
secret, solid or any other cause (the uniform move nack, 5.5/6.5, already holds). The oracle that
pins this is the differential door-equivalence test (10.3, T17, #46). A refused move stays the
uniform nack (5.5), with no marker, shape change or cause.
secret, solid or any other cause (the uniform move nack, 5.5/6.5, already holds). A refused move
stays the uniform nack (5.5), with no marker, shape change or cause. Proven by: TESTING §5.8 (the
differential door-equivalence test, T17, #46).
- **Player marker: the one wall fact a player receives [FIXED (owner decision), 2026-11-16, #48;
shape and storage 2026-11-17, #49].** `player_marker` is a switch on the wall. On for the `window`
preset, **off** for every other preset and for raw switches (a GM may toggle it on any wall). A
@@ -1071,8 +1058,8 @@ What a wall's behaviour is made of. Heights are 5.7; what a low wall does to sig
GM-only free-text `label` (e.g. "railing", "pit edge", "the king's window"): at most 64 code
points, trimmed, no control characters, the 6.5 text rule. It has no behaviour, is stored
verbatim, never derived from the switches and never feeds the derived `kind`. It never reaches a
player: it is in the leak checker's `BannedAlways` key scan (`10.3`), so a player frame carrying
`label` is `WALLDATA`.
player: it is in the leak checker's `BannedAlways` key scan, so a player frame carrying `label` is
`WALLDATA` (TESTING §5.8).
- **Only the GM touches a door [FIXED (owner decision), 2026-11-15, #46].** In v1 `door.set` stays
G-only: a player sender is refused `not-allowed` at the role step (6.5), whatever the door's
settings and whether it is locked or secret. Player-opened doors, lock refusals addressed to a
@@ -1208,7 +1195,7 @@ settled by #49 (6.1, 8). Answers #41's open question: the *target's* height matt
pass, zero geometry.*
- Hook at `visibleTo` (`server/vision.nim`): visible iff `insideAny(pos)` **or** the predicate.
`visibilityPolygon`, `cellsTouched` and `tiles.nim` never read a height. *Why: the
token-visibility rule stays in one copy (10.3's fault classes rely on it) and the fan is
token-visibility rule stays in one copy (the fault classes rely on it) and the fan is
untouched.*
- Visible fraction: per crossed wall the required top is `h_req(W) = h_e + (h_w - h_e)·(d_T/d_W)`,
and `f_W = clamp((h_t - h_req(W))/h_t, 0, 1)`; the token's fraction is the **minimum** over
@@ -1217,14 +1204,9 @@ settled by #49 (6.1, 8). Answers #41's open question: the *target's* height matt
answer.*
- In the GM view a player's fraction for a token = the **maximum** over that player's tokens that
see it. *Why: the player does see it from that one.*
- Oracles [FIXED (owner-delegated), #44]. `tools/leakcheck.nim`'s `clearLine` gets its own height
test (walls carry their height; a target's top is compared independently of the server's code,
never by calling vision.nim). Cells in a low wall's hidden band are **maybe** for the
independent explored/tile oracle: a tile there may be allowed or refused, both correct, but a
band cell may never be **sure** (a `200` on a band cell is legitimate, a withheld proof cell
never). A token hidden only by the band gives no `token` frame, no name and no encountered
entry, and no churn: no alternating frames as a position crosses the line. The assertions land
with the build tickets (/to-spec), not here.
- Oracles [FIXED (owner-delegated), #44]: `tools/leakcheck.nim`'s `clearLine` gets its own height
test, the band cells are oracle-*maybe* and never *sure*, and a band-hidden token produces no
frame, name, entry or churn. The assertions and their details are in TESTING §5.9.
- Deferred: nothing about see-over itself. A window is unaffected (its `blocks_sight` is off, so it
never reaches sight, 5.8). Whether the client or the server computes the GM's numbers is M4's
build call.
@@ -1263,10 +1245,9 @@ units are 5.7, the switches 5.8, see-over 5.9; the wire fields and the migration
thickness is movement-only, 5.8); its collider still uses the thickness.
- **Sight: the body quad.** A sight-blocking thick wall enters the vision input as the four faces of
its rectangle (two long, two square ends), hoisted once per wall edit and reused for every viewer
and frame — viewer-independent, so it caches [#43 measured: 4-face quad 0.263 ms hoisted vs 0.943
ms per query on 5k sparse, 12.721 vs 13.229 ms dense; the 3-face near+caps silhouette is
observer-dependent, cannot be hoisted, and costs 0.699 ms per query sparse (8.4x thin), so the
hoisted quad is the cheaper exact model]. The fan and `cellsTouched` are otherwise unchanged, and
and frame — viewer-independent, so it caches (the 3-face near+caps silhouette is observer-dependent,
cannot be hoisted and costs more; numbers in TESTING §5.10). The fan and `cellsTouched` are
otherwise unchanged, and
zero thickness is the segment of today. A one-way wall's own body is opaque floor on **both**
sides (5.8, #47): the blind side gets no face at all, and the seeing side sees up to the near face
— never into or past the body's floor.
@@ -1296,8 +1277,7 @@ units are 5.7, the switches 5.8, see-over 5.9; the wire fields and the migration
- **Joints: overlap, never a mitre [FIXED (owner-delegated), #45].** Two walls meeting at a corner
keep their own rectangles; the bodies overlap at the joint and the outside corner shows a small
notch. No mitre, no merged joint, no joint object, and no crack: the overlap is what closes it. A
cave is a chain of straight walls. #43 measured that joints need no thickness: zero-width corners
show no crack either.
cave is a chain of straight walls; joints need no thickness (TESTING §5.10).
- **Shape behind a seam [FIXED (owner-delegated), #45].** A wall's occupied area is produced by
**one** wall-shape function, and no other code reads `a`/`b` to build geometry; in v1 that
function returns the 5.10 rectangle. Curved, freeform and image-traced walls are out of v1 (1) and
@@ -1309,7 +1289,7 @@ units are 5.7, the switches 5.8, see-over 5.9; the wire fields and the migration
fields and their validation are 6.1; the record is 8.
- Oracles build the body rectangle from `a`, `b`, `thickness` and `position` with their own code,
never by calling `vision.nim` or the move rules, and use it for both the sight footprint and the
distance test (10.2, 10.3).
distance test (TESTING §5.10).
- Deferred: nothing about thickness. The columns, the payload shape and the migration are settled in
6.1, 8 and 4.4 (#49). What a door is with thickness is settled: the leaf is the wall's own body
(5.8) and the push is measured from that body, reducing to today exactly at zero thickness (5.5)
+2 -4
View File
@@ -174,10 +174,8 @@ power-save CPU.
- `cellsTouched` is ~12x the polygon itself and dominates [MEASURED]. M2 replaced per-cell polygon
tests with scanline rasterization over the explored grid, differential-tested against the ported
implementation [PROPOSED; built in M2].
- Polygon cost is O(rays x walls in bbox) [MEASURED code reading, `server/geometry.nim`
`visibilityPolygon`, ported unchanged from the prototype]. The prototype scene has 60 walls and 8
tokens, so this says nothing about big maps. With radius-bbox culling the cost scales with local wall
density, not total walls [INFERRED].
- The prototype scene the table measures has 60 walls and 8 tokens, so its numbers say nothing about
big maps; the 5k bench scenes below are the answer.
- Bench scenes (`tools/scenegen.nim`): the 5k target is the sparse primary layout
`genScene(16384, 5000, 1)`: 0.082 ms avg [MEASURED, `results/bench.log`]. The dense layout
`genScene(4096, 5000, 1)` is a stress reference (1.28 ms avg, ~207 walls in the vision bbox)