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
+14 -1
View File
@@ -20,7 +20,12 @@
##
## Change tracking: `ver` counts polygon changes (the client gets `vision` only when it changes, 6.4)
## and `fresh` holds the cells this mutation added (4.2 step 8: cleared after egress).
import std/[algorithm, math, sets]
##
## Player markers (DESIGN 5.8, ADR-0015, #59) are per-player memory like explored: `markers` maps a
## wall id to that player's own opaque marker id and its fixed anchor (integer px). The map only grows
## in this round; retraction and re-earning are #60. `markerFresh` holds the markers minted by the
## current refresh so the mutation's transaction can persist them (server/markers.nim).
import std/[algorithm, math, sets, tables]
import tokens, worldmap, geometry, world, faults
type
@@ -28,11 +33,19 @@ type
tokenId*: string
pts*: seq[Vec]
Marker* = object
## One player's marker memory for one wall (DESIGN 5.8, 6.1). The id is opaque and per player;
## the anchor is the wall's drawn midpoint, rounded once at mint time and never updated.
id*: string
x*, y*: int
PlayerVision* = object
polys*: seq[Poly]
explored*: HashSet[int] ## cell index cy * cols + cx
ver*: int ## bumped when `polys` changes
fresh*: seq[(int, int)] ## cells added by the current mutation (cx, cy), sorted
markers*: Table[int, Marker] ## wall id -> this player's marker (5.8, #59)
markerFresh*: seq[(int, Marker)] ## markers minted by the last refresh, awaiting the DB write
proc cols*(sc: SceneRec): int =
## Cells across the scene (DESIGN 8: ceil(w / cell)).