From 65c6b53c2adf55dbabf6e098e3217b658a462a52 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Sun, 8 Nov 2026 18:56:22 +0100 Subject: [PATCH] docs: DESIGN door push rule (5.5, 5.4, 6.1, H2, M2 accept, Q14) Co-Authored-By: Claude Sonnet 5.5 --- docs/DESIGN.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/DESIGN.md b/docs/DESIGN.md index b0dd69f..ccc6ff5 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -242,7 +242,7 @@ explored_chunk(player_id, scene_id, cx, cy, bits BLOB, PRIMARY KEY(player_id, sc - **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 = blocked, so no squeezing through shared vertices) AND destination circle at distance >= token 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: 87 `[OK]` test cases in `results/nimble-test.log` (M2, 2026-11-08)] +### 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)] - 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. @@ -266,7 +266,7 @@ Conclusions: ### 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 (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 (`blocked` trigger, 5.5) or from a GM placement on a wall (GM placements ignore walls, 5.5); the escape rule covers both. -- Closing a door (or editing a wall) on a token [FIXED, Q14]: the token gets `blocked` (trigger narrowed to circle overlap, 5.5). The server refuses that token's player moves; the GM can still move it; status clears per the 5.5 Keep/Clear rules (wall removed or door opened and no other wall overlaps, GM move to a free spot, or GM clear). Current pin: `tests/tgeometry.nim`, suite "door/wall closing on a token", test "door closed on a token: Q14 undecided, DESIGN 5.4 vs 12 H2 conflict": a token whose centre is 10 px off a closed door may move to a clear spot, may not stay overlapped, and may not cross the door. It pins `moveBlocked` only; it is replaced in M2 by tests of the 5.5 policy (under the 5.5 trigger this token is `blocked`, so player moves are refused). +- Closing a door on a token [FIXED, owner 2026-11-08, supersedes the earlier `blocked` decision for doors]: the token is pushed aside (5.5), `blocked` only if neither side is valid. Editing or adding a wall on a token [FIXED, Q14]: the token gets `blocked` (trigger narrowed to circle overlap, 5.5). The server refuses that token's player moves; the GM can still move it; status clears per the 5.5 Keep/Clear rules (wall removed or door opened and no other wall overlaps, GM move to a free spot, or GM clear). Current pin: `tests/tgeometry.nim`, suite "door/wall closing on a token", test "door closed on a token: Q14 undecided, DESIGN 5.4 vs 12 H2 conflict": a token whose centre is 10 px off a closed door may move to a clear spot, may not stay overlapped, and may not cross the door. It pins `moveBlocked` only; it is replaced in M2 by tests of the 5.5 policy (under the 5.5 trigger this token is `blocked`, so 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. - Doors/walls changing does not un-explore anything; explored only grows [MEASURED behaviour]. @@ -280,9 +280,10 @@ Notation: token centre `c`, radius `r` (scene `token_radius`), start `s`, destin **`blocked` flag** ("stuck": the player cannot move the token at all; the GM always can) (stored bool on the entity, persisted) [FIXED, owner (B), Q14, refined 2026-11-08] - Overlap: `dist(c, W) < r` for a blocking wall `W`. An open door stops blocking, so opening = removing that wall for this rule; closing = adding it. Centre-on-wall is not required. -- Set: a wall is added or updated, or a door is closed -> every token overlapping that wall becomes `blocked`. The GM places or moves a token to a position overlapping any blocking wall -> `blocked`. +- Set: a wall is added or updated -> every token overlapping that wall becomes `blocked`. (A door CLOSING on a token does not set it: push rule below.) The GM places or moves a token to a position overlapping any blocking wall -> `blocked`. - Keep: while any blocking wall still overlaps the token it stays `blocked` (opening a door does not free it if another wall overlaps). - Clear: a wall is removed or a door opened -> each token that overlapped that wall gets `blocked` = overlaps any remaining blocking wall. The GM moves the token to a position overlapping no blocking wall -> cleared. GM manual clear -> cleared unconditionally (wire intent defined in M3). +- **Door closing on a token = push aside, not stuck** [FIXED, owner, 2026-11-08; changes the door case only]: each token (player or GM-owned) with `dist(c, door) < r` is moved perpendicular to the door segment, to the side its centre is already on, by the minimal distance that ends `>= r` from the door (+ `PushEps` = 1e-6 px; past the door's end the offset is `sqrt(r^2 - e^2)`, `e` = along-axis overshoot). Centre exactly on the door line: side of the token's previous position (position before its most recent move or push; `prev`/`hasPrev` on the token); no history, or previous also on the line: left of the door's a->b direction (deterministic default). The pushed position must be in bounds and `>= r` from every blocking wall (the closed door included); else the opposite side is tried; if neither is valid the token stays and becomes `blocked`, and opening that door later clears it per the Clear rule. A pushed token ends `blocked = false`. The push is a server-originated position change returned by the move-rules module (list of token index + new position) so M3 can broadcast it and recompute vision; no step cap applies. Each token is pushed independently; tokens do not block tokens (no token-token collision; the `blocks_move` flag is not modelled in M2), so pushed tokens may overlap each other. Wall add / wall update / GM placement or move inside a wall are unchanged (stuck). Door open is unchanged. - An event changes only the tokens it touches (those overlapping the changed wall, or the moved token). An unrelated wall change elsewhere never re-blocks a GM-cleared token. - After a GM manual clear while a wall still overlaps, the player escape rule (step 3 below) applies unchanged: the token may step out without crossing, destination >= r from every blocking wall. - `wall.update` = remove then add for this rule [PROPOSED; not in the owner's list]. @@ -319,7 +320,7 @@ Client -> server (intents). Authority column: P = player, G = GM. | t | fields (contract) | who | server behaviour | |---|---|---|---| | `move` | `reqId:int, id, pos:[x,y]` | P (owned) / G (any) | validate; reply `moveAck` (+ `token` diffs); non-owned -> `error`; P move refused (`blocked`, over step cap, or wall collision; 5.5) -> `moveAck{ok:false, pos:old}`, one uniform nack; G move ignores walls, step cap and `blocked`, then sets/clears `blocked` by overlap; out-of-bounds G move gets the same nack (5.5) | -| `door` | `id, open:bool` | G | toggle; recompute all players; close sets `blocked` on tokens whose circle overlaps the door, open recomputes it for those tokens (still blocked if another wall overlaps; Q14, 5.5) | +| `door` | `id, open:bool` | G | toggle; recompute all players; close pushes tokens whose circle overlaps the door aside (perpendicular, valid side; server-originated position change to broadcast, vision recomputed; `blocked` only if no side is valid; Q14, 5.5), open recomputes `blocked` for those tokens (still blocked if another wall overlaps) | | `wall.add` / `wall.update` / `wall.remove` | wall fields / `id` | G | validate geometry; recompute all players; GM-only broadcast of wall delta; add sets `blocked` on tokens whose circle overlaps the wall, remove recomputes it for those tokens (Keep rule), update = remove + add (Q14, 5.5; update PROPOSED) | | `entity.create` / `entity.update` / `entity.remove` | kind, name, pos, owner, props buckets | G | validate against property schema; view diff | | `prop.set` | `id, bucket, key, value` | G (v1) | owner-bucket writes by players come with FFF actions (section 9) | @@ -523,7 +524,7 @@ Source: `prototype-server-vision/HANDOFF.md` (and README/NOTES worries). | # | Item | Decision / open | Milestone | |---|---|---|---| | H1 | Port geometry + tests as-is | Decision: port `geometry.nim`, `tgeometry.nim`, mutation check, leak harness first | M1 | -| H2 | Token on a wall can't leave (inclusive `segsCross`); closing a door or editing a wall on a token | Decision [FIXED, Q14]: token gets `blocked` (player moves refused, GM moves allowed). Set/Keep/Clear per 5.5: stays while any blocking wall overlaps; clears on wall removal or door open only if no other wall overlaps, on a GM move to a free spot, or on GM clear; GM placements/moves onto a wall set it. Trigger = circle overlap [FIXED, owner]; escape + capsule rule [FIXED, accepted default]; both in 5.5. Pin tests replaced in M2. | M2 | +| H2 | Token on a wall can't leave (inclusive `segsCross`); closing a door or editing a wall on a token | Decision [FIXED, Q14; door case revised by owner 2026-11-08]: wall add/edit on a token gives it `blocked` (player moves refused, GM moves allowed); a door closing on a token pushes it aside instead (5.5; `blocked` only if no side is valid). Set/Keep/Clear per 5.5: stays while any blocking wall overlaps; clears on wall removal or door open only if no other wall overlaps, on a GM move to a free spot, or on GM clear; GM placements/moves onto a wall set it. Trigger = circle overlap [FIXED, owner]; escape + capsule rule [FIXED, accepted default]; both in 5.5. Pin tests replaced in M2. | M2 | | H3 | O(rays x walls) vision | Decision: radius-bbox cull now; uniform spatial grid over walls only if the 5k-wall bench misses target (5.5) | M2 | | H4 | `cellsTouched` ~12x polygon | Decision: scanline rasterization, differential test vs ported version | M2 | | H5 | Shared-endpoint test gap | Decision: port with a test that fails if either arm is removed; new mutation (d) | M1 | @@ -557,10 +558,10 @@ Each is small, ends with a green gate, and no milestone depends on browser UI be - **M1 - Port geometry + tests.** - Scope: new repo layout (`server/`, `tools/`, `tests/`), devbox config, `geometry.nim` + `tgeometry.nim`, mutation script, add mutation (d) and the shared-endpoint arm test. - - Accept: `nimble test` green: M1 port baseline 33 test blocks / 98 checks, none dropped (plus new tests on top; current count in `results/nimble-test.log`); mutations a-d each fail >= 1 test (M1; M2 adds e-l in `tools/mutation.sh`), control passes; repo builds with devbox only. + - Accept: `nimble test` green: M1 port baseline 33 test blocks / 98 checks, none dropped (plus new tests on top; current count in `results/nimble-test.log`); mutations a-d each fail >= 1 test (M1; M2 adds e-o in `tools/mutation.sh`), control passes; repo builds with devbox only. - **M2 - Vision engine v2 and move rules** (decisions in 5.5, recorded 2026-11-08). - Scope: scanline `cellsTouched`, differential + independent explored oracle tests, radius-bbox wall cull (spatial grid only if the 5k bench misses), capsule/swept move check and token-on-wall escape (5.5), step cap = effective vision radius (5.5), `blocked` flag with circle-overlap trigger and Set/Keep/Clear policy (5.5), GM moves ignore walls and step cap (and set/clear `blocked`), bench harness incl. 5k-wall scene, pure in-process move-rules module with unit tests. The WS/hostile-client harness is M3, not M2. - - Accept: `visibilityPolygon` and `cellsTouched` equal the old implementation on the corpus (5.5); `moveBlocked` excluded (its results change on purpose); polygon+cells bench <= prototype (0.451 ms) on the prototype scene and polygon < 1 ms on the 5k-wall scene [targets PROPOSED]; in-process probing test passes; escape and capsule positive and negative unit tests pass; `blocked` tests pass (every Set/Keep/Clear rule of 5.5: overlap trigger, doorway, two overlapping walls, GM drop/move sets and clears, GM clear then escape, unrelated change does not re-block); mutations k (no Keep) and l (GM moves do not set blocked) each fail >= 1 test; over-cap move gives the same nack as a blocked move; thresholds documented in the module header; oracle tolerance 0.5 px. The KNOWN LIMITATION test and the Q14 pin test are replaced with positive assertions and `blocked`-policy tests. + - Accept: `visibilityPolygon` and `cellsTouched` equal the old implementation on the corpus (5.5); `moveBlocked` excluded (its results change on purpose); polygon+cells bench <= prototype (0.451 ms) on the prototype scene and polygon < 1 ms on the 5k-wall scene [targets PROPOSED]; in-process probing test passes; escape and capsule positive and negative unit tests pass; door-push tests pass (each side, centre on the line uses the previous side, other-side fallback for a blocking wall and for out of bounds, both invalid -> blocked and opening frees it, GM-owned token pushed, wall add still sticks); `blocked` tests pass (every Set/Keep/Clear rule of 5.5: overlap trigger, doorway, two overlapping walls, GM drop/move sets and clears, GM clear then escape, unrelated change does not re-block); mutations k (no Keep), l (GM moves do not set blocked), m (push to the wrong side), n (push skips the validity check) and o (previous side ignored) each fail >= 1 test; over-cap move gives the same nack as a blocked move; thresholds documented in the module header; oracle tolerance 0.5 px. The KNOWN LIMITATION test and the Q14 pin test are replaced with positive assertions and `blocked`-policy tests. - **M3 - Server core.** - Scope: entities with bucketed props, players, invites/sessions, scenes, chunked explored persistence, typed per-recipient views and single egress, per-connection counters, proto versioning, wall/entity CRUD intents, Origin check, plaintext invite secrets and non-expiring sessions (Q10, Q11), SQLite schema + migrations. - Accept: ported leak test (A and B) + fault test with the extended fault classes: all caught with exact class sets, clean build passes; restart test passes incl. CRUD; auth tests pass; no secrets in logs. @@ -596,7 +597,7 @@ Each is small, ends with a green gate, and no milestone depends on browser UI be 11. Q11 - Invite secrets: stored hashed (shown once, GM regenerates to re-share) or stored plaintext so the GM can re-copy a link? **RESOLVED [FIXED (owner decision), 2026-11-08]:** invite secrets stored plaintext so the GM can re-copy the link. 12. Q12 - Durability: is `synchronous=NORMAL` (can lose the last few commits on power loss/OS crash, never corrupts) acceptable, or should it be FULL for some or all writes? **RESOLVED [FIXED (owner decision), 2026-11-08]:** `synchronous=NORMAL`; `FULL` around GM authoring transactions. 13. Q13 - Slow/dead client policy: acceptable to disconnect clients that fall behind? Willing to patch/fork the pinned mummy commit if per-socket queue depth cannot be read from outside? **RESOLVED [FIXED (owner decision), 2026-11-08]:** option A: app-level bounded per-client outbox, latest-state-wins coalescing per key (MQTT-retained-like), diff at flush time, server Ping(seq)/Pong ack tracking for lag, stop feeding lagging clients + full resync on recovery; no mummy patch. Dead/stuck peers closed by nginx proxy timeouts (mechanism PROPOSED; verify WS goes through nginx in M5). Fork of mummy (option B) is fallback only, not planned. Research: `docs/research/q13-mummy-slow-clients.md`; detail in 4.3. -14. Q14 - Moving tokens when walls change: what should happen if the GM closes a door (or edits a wall) on top of a token? Allow the token to walk out, auto-nudge it, or refuse the edit? **RESOLVED [FIXED (owner decision), 2026-11-08]:** a GM edit that lands on a token gives it status `blocked`: server refuses that token's player moves; GM can still move it; status clears when the wall is removed or the door opened, or when the GM clears it. +14. Q14 - Moving tokens when walls change: what should happen if the GM closes a door (or edits a wall) on top of a token? Allow the token to walk out, auto-nudge it, or refuse the edit? **RESOLVED [FIXED (owner decision), 2026-11-08]:** a GM edit that lands on a token gives it status `blocked`: server refuses that token's player moves; GM can still move it; status clears when the wall is removed or the door opened, or when the GM clears it. **Door case revised [FIXED (owner decision), 2026-11-08]:** spell walls and wall edits stay stuck; a door closing on a token pushes the token aside (5.5), stuck only if neither side is valid. 15. Q15 - Reconnect: is a full resync on every reconnect fine up to what explored/state size, or do you want `resume since N` later? **RESOLVED [FIXED (owner decision), 2026-11-08]:** full resync on every reconnect; revisit if a measured snapshot exceeds ~100 KB. 16. Q16 - Vision payload: OK with full polygon per move (~3.4-3.7 KB per mover delivery, measured on loopback) for v1, or do you want deltas/binary earlier (e.g. for mobile data plans)? **RESOLVED [FIXED (owner decision), 2026-11-08]:** full vision polygon, integer px, sent only on change; deltas post-v1. 17. Q17 - Names/labels: which character sets must labels support (Latin only, accents, non-Latin, emoji)? Affects BitmapText glyph atlas vs Text/HTMLText. **RESOLVED [FIXED (owner decision), 2026-11-08]:** labels in Latin incl. accented characters plus Nerd Font icon glyphs.