feat(walls): player markers — emission, opaque ids, storage, resync (#59)

A wall that is player_marker:true and derives window sends a player one
anchor (the drawn midpoint, integer px) and an opaque per-player 12-char id
once any point of its segment enters that player's vision polygon. Markers
live in PlayerVision like explored, persist to marker_seen in the same
derived-memory transaction, load before the first connection and resync as a
full set after explored; the GM and other players never receive one.

- markers.nim: emission gate, visible-extent test, id mint, anchor, marker_seen I/O.
- views/main: PlayerView markers + full/diff frames, refresh sync, startup load.
- markers.test.mjs: window preset, switch off, solid wall, any-part anchor,
  walk-away/door/lost sight, full-after-explored, per-player privacy, GM none.
- leakcheck: marker allowed type + independent visible-extent oracle with a
  positive control (a marked window the subject sees).
- restart: marked window in the fixture; marker set and marker_seen rows
  identical before/after SIGTERM and SIGKILL.
- protocol/tviews: catalogue and frame order pin the 16th message.

Retraction, re-earning and MARKER_* faults are #60.

Ref #59
This commit is contained in:
2026-11-19 23:27:26 +01:00
parent e989100f50
commit edd4437f7e
11 changed files with 599 additions and 47 deletions
+123 -1
View File
@@ -27,6 +27,9 @@
## CHAR_OWNER_PROP a character's owner bucket reached a player who does not own it (8)
## GEOMETRY the recomputed polygon disagrees with the clear-segment oracle (sanity)
## ONEWAY the subject's fan ignores `sight_dir` (the two-way fan; TESTING 10.3, #58)
## MARKER a marker frame disagrees with the independent visible-extent oracle, or its shape
## is wrong (the exact MARKER_EARLY/EXTRA/OFF classes are #60's fault builds; #59
## proves the allowed type and the oracle with a positive control)
## PROTOCOL a frame the catalogue does not allow, a bad `n` sequence, a missing hello block
##
## One-way sight (DESIGN 5.8, TESTING 10.3): the checker reads `sight_dir` from the GM's frames and
@@ -41,7 +44,9 @@ import geometry
const
AllowedTypes = ["hello", "ack", "roster", "token", "token_gone", "vision", "explored",
"character", "character_gone", "encountered"]
"marker", "character", "character_gone", "encountered"]
MarkerIdLength = 12
MarkerIdAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"
BannedAlways = ["walls", "wall", "wall_gone", "a", "b", "open", "kind", "controller", "gm_only",
"flags", "radius_own", "extra",
# every wall field name (#54): geometry, switches, door settings, label
@@ -75,9 +80,19 @@ type
Truth = object
walls: seq[Wall]
markerWalls: seq[MarkerWall]
tokens: Table[string, TruthToken]
characters: Table[string, TruthCharacter]
MarkerWall = object
## A wall that should produce a marker (DESIGN 5.8): `player_marker:true` and the derived shape
## label `window` (`blocks_sight:false`, `blocks_movement:true`; a door either way). The checker
## keeps the geometry and the id from the GM's frames and does its own visible-extent test.
id: int
a, b: Vec
playerMarker: bool
isWindow: bool
Group = object
label: string
gmMsgs: seq[JsonNode]
@@ -134,11 +149,29 @@ proc readGroups(path, subject: string): seq[Group] =
# ---------------------------------------------------------------------------------------------------
# Truth from the GM socket (walls and every token)
proc markerWallOf(id: int, w: JsonNode): MarkerWall =
## The marker-relevant projection of a GM wall frame (5.8): the derived `window` gate and the switch.
MarkerWall(id: id, a: vec(w["a"]), b: vec(w["b"]),
playerMarker: w["player_marker"].getBool,
isWindow: not w["blocks_sight"].getBool and w["blocks_movement"].getBool)
proc isMarkerCandidate(m: MarkerWall): bool = m.playerMarker and m.isWindow
proc setMarkerWall(truth: var Truth, mw: MarkerWall) =
## Upsert by wall id, so a `wall` update replaces the marker projection in place.
for i in 0 ..< truth.markerWalls.len:
if truth.markerWalls[i].id == mw.id:
if mw.isMarkerCandidate: truth.markerWalls[i] = mw
else: truth.markerWalls.delete i
return
if mw.isMarkerCandidate: truth.markerWalls.add mw
proc applyGmWalls(truth: var Truth, ids: var seq[int], m: JsonNode) =
## `wall` (upsert) and `wall_gone` need the id, which geometry.Wall does not carry.
case m["t"].getStr
of "walls":
truth.walls.setLen(0)
truth.markerWalls.setLen(0)
ids.setLen(0)
for w in m["walls"]:
truth.walls.add Wall(a: vec(w["a"]), b: vec(w["b"]),
@@ -147,6 +180,7 @@ proc applyGmWalls(truth: var Truth, ids: var seq[int], m: JsonNode) =
sightBarrier: w["blocks_sight"].getBool,
movementBarrier: w["blocks_movement"].getBool)
ids.add w["id"].getInt
truth.setMarkerWall markerWallOf(w["id"].getInt, w)
of "wall":
let id = m["id"].getInt
let w = Wall(a: vec(m["a"]), b: vec(m["b"]), door: m["door"].getBool,
@@ -161,6 +195,7 @@ proc applyGmWalls(truth: var Truth, ids: var seq[int], m: JsonNode) =
if not found:
truth.walls.add w
ids.add id
truth.setMarkerWall markerWallOf(id, m)
of "wall_gone":
let id = m["id"].getInt
for i in 0 ..< ids.len:
@@ -168,6 +203,10 @@ proc applyGmWalls(truth: var Truth, ids: var seq[int], m: JsonNode) =
truth.walls.delete i
ids.delete i
break
for i in 0 ..< truth.markerWalls.len:
if truth.markerWalls[i].id == id:
truth.markerWalls.delete i
break
else: discard
proc applyGmTokens(truth: var Truth, m: JsonNode) =
@@ -294,6 +333,40 @@ proc insideAny(polys: seq[(string, seq[Vec])], p: Vec): bool =
for (_, pts) in polys:
if inside(pts, p): return true
proc extentSeen(polys: seq[(string, seq[Vec])], a, b: Vec): bool =
## The checker's OWN visible-extent test (DESIGN 5.8, TESTING 10.3; never `vision.nim`): any point
## of the segment inside one of the subject's polygons means an endpoint is inside or the segment
## crosses a polygon edge. The polygons themselves are the GM-truth recomputation above.
for (_, pts) in polys:
if pts.len < 3: continue
if inside(pts, a) or inside(pts, b): return true
for i in 0 ..< pts.len:
if segsCross(a, b, pts[i], pts[(i + 1) mod pts.len]): return true
proc anchorOf(mw: MarkerWall): (int, int) =
## The drawn midpoint, rounded once to integer px (5.8, 6.1).
(int(round((mw.a.x + mw.b.x) / 2)), int(round((mw.a.y + mw.b.y) / 2)))
proc validMarkerId(id: string): bool =
if id.len != MarkerIdLength: return false
for c in id:
if c notin MarkerIdAlphabet: return false
true
proc markerShapeOk(m: JsonNode): bool =
## Only `{id, pos}` per entry, the id opaque and the anchor integer px (6.1). A wall id or any
## other field here is a shape failure, and `keysDeep` catches the banned wall names separately.
for e in m["set"]:
if e.kind != JObject or e.len != 2 or not e.hasKey("id") or not e.hasKey("pos"): return false
if e["id"].kind != JString or not validMarkerId(e["id"].getStr): return false
if e["pos"].kind != JArray or e["pos"].len != 2: return false
for q in e["pos"]:
if q.kind != JInt: return false
if m.hasKey("del"):
for d in m["del"]:
if d.kind != JString or not validMarkerId(d.getStr): return false
true
proc cellOf(sceneW: float, cell: int, ix, iy: int): (float, float) =
(float(ix * cell) + float(cell) / 2, float(iy * cell) + float(cell) / 2)
@@ -373,6 +446,9 @@ proc main() =
var encounterable: HashSet[string] # token ids the subject may have met (independent oracle)
var viewCharacters: HashSet[string] # character ids the subject was sent
var prevController: Table[string, int] # controller of each token at the previous group
var markers: Table[string, (int, int)] # marker id -> anchor, what the subject was sent
var expectedMarkers: Table[int, (int, int)] # wall id -> anchor, accumulated memory (#59)
var markerPositive = false # the scenario exercised the oracle at least once
for g in groups:
inc groupsSeen
@@ -380,6 +456,8 @@ proc main() =
applyGmWalls(truth, wallIds, m)
applyGmTokens(truth, m)
applyGmCharacters(truth, m)
if m["t"].getStr == "marker":
fail "PROTOCOL", "the GM received a marker frame (5.8: player memory only)"
# player ids: the subject from its hello, the other from any token it does not control
for m in g.subjMsgs:
@@ -437,6 +515,7 @@ proc main() =
otherExplored.incl cy * int(ceil(sceneW / float(cell))) + cx
# --- the subject's frames of this group -----------------------------------------------------
var sawExploredFull = false
for m in g.subjMsgs:
let t = m["t"].getStr
if not m.hasKey("n") or m["n"].getInt != expectedN:
@@ -643,6 +722,7 @@ proc main() =
if id notin haveIds: fail "OWN_VIEW", "vision is missing the polygon of " & id
of "explored":
if m["full"].getBool:
sawExploredFull = true
# a resync snapshot replaces the set; every cell must be one the recomputation has seen
var cells: seq[(int, int)]
let cols = int(ceil(sceneW / float(cell)))
@@ -663,8 +743,48 @@ proc main() =
let cy = c[1].getInt
let k = cy * int(ceil(sceneW / float(cell))) + cx
exploredSent.incl k
of "marker":
# DESIGN 5.8/6.1/6.3: the player's own opaque ids and integer-px anchors, nothing else.
# `full:true` is the resync set and must follow `explored` full (the client draws it over the
# fog just rebuilt); a diff adds ids in `set` and (from #60) retracts in `del`.
if not markerShapeOk(m):
fail "MARKER", "malformed marker frame (group " & g.label & ")"
elif m["full"].getBool and not sawExploredFull:
fail "PROTOCOL", "marker full before explored full (group " & g.label & ")"
else:
if m["full"].getBool: markers.clear()
for e in m["set"]:
let id = e["id"].getStr
if markers.hasKey(id):
fail "MARKER", "duplicate marker id " & id & " (group " & g.label & ")"
markers[id] = (e["pos"][0].getInt, e["pos"][1].getInt)
if m.hasKey("del"):
for d in m["del"]:
let id = d.getStr
if not markers.hasKey(id):
fail "MARKER", "del for a marker the subject never had: " & id
markers.del id
else: discard
# --- player markers (5.8, TESTING 10.3 #59) -------------------------------------------------
# The oracle's own memory: a marked window enters `expectedMarkers` once any part of its drawn
# extent is inside the subject's polygons, and stays (walking away, a door, lost sight never
# retract it). It never calls vision.nim: `polysChecks` is this file's recomputed fan.
for mw in truth.markerWalls:
if expectedMarkers.hasKey(mw.id): continue
if extentSeen(polysChecks, mw.a, mw.b): expectedMarkers[mw.id] = anchorOf(mw)
var wantPos: seq[(int, int)]
for _, pos in expectedMarkers: wantPos.add pos
var gotPos: seq[(int, int)]
for _, pos in markers: gotPos.add pos
wantPos.sort()
gotPos.sort()
if gotPos != wantPos:
fail "MARKER", "marker set " & $gotPos & " != visible-extent oracle " & $wantPos &
" (group " & g.label & ")"
elif wantPos.len > 0:
markerPositive = true
# --- CONTROLLER_CHANGE (10.3) ----------------------------------------------------------------
# A token's controller may move only when an intent asked for it (`token.create` names one,
# `token.update` patches `controller`, `player.remove` hands them to the GM). A character edit
@@ -762,6 +882,8 @@ proc main() =
if me == 0: fail "PROTOCOL", "no player id in hello"
if removes == 0: fail "NO_REMOVE", "the scenario never withdrew a token (harness coverage)"
if seenAny.len < 3: fail "WITHHELD", "the scenario never showed the subject 3 tokens"
if not markerPositive:
fail "MARKER", "the scenario never produced a marker the visible-extent oracle expects"
for cls, n in classes: echo "FAILCLASS ", cls, " ", n
echo "leakcheck: subject ", subject, " (player ", me, "), ", groupsSeen, " groups, ",