feat(walls): marker retraction, re-earn and marker fault classes (#60)

Retract a player marker when the GM removes the wall, clears
player_marker, makes the wall stop deriving window, or moves its
geometry (a/b, thickness, position). Retraction emits del only and
never the new anchor; a re-earned marker gets a fresh id. The
marker_seen deletes ride the same derived-memory NORMAL transaction as
the explored chunks, after the wall row commits and before the ack.

Replace the leak checker's aggregate MARKER class with MARKER_EARLY,
MARKER_EXTRA and MARKER_OFF, add their leakfault hooks and exact-class
fault tests, and extend the leak scenario with an unseen marked window
and a marked solid wall as the negative controls. WS black-box tests
cover all four causes, fresh re-earns, no untouched re-send, no
set/del for one id in a frame, no explored write from a retraction,
and delete/cascade durability across a restart.
This commit is contained in:
2026-11-19 23:43:44 +01:00
parent edd4437f7e
commit c3c0a39188
9 changed files with 425 additions and 60 deletions
+14 -6
View File
@@ -21,10 +21,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).
##
## 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).
## Player markers (DESIGN 5.8, ADR-0015, #59/#60) are per-player memory like explored: `markers`
## maps a wall id to that player's own opaque marker id, its fixed anchor (integer px) and the
## wall-cause signature it was minted for. A marker is retracted when the wall goes, the switch is
## cleared, the wall stops deriving `window`, or its geometry (`a`/`b`, `thickness`, `position`)
## moves; a re-earn gets a fresh id. `markerFresh`/`markerDead` hold the markers minted/retracted 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
@@ -35,9 +37,12 @@ type
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.
## the anchor is the wall's drawn midpoint, rounded once at mint time and never updated. `sig`
## is the retraction-relevant wall state (geometry, switch, derived kind) the marker was earned
## for: a different signature at the next refresh means the cause changed and the marker dies.
id*: string
x*, y*: int
sig*: string
PlayerVision* = object
polys*: seq[Poly]
@@ -46,6 +51,7 @@ type
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
markerDead*: seq[string] ## marker ids retracted by the last refresh, awaiting the DB delete
proc cols*(sc: SceneRec): int =
## Cells across the scene (DESIGN 8: ceil(w / cell)).
@@ -95,7 +101,9 @@ proc refresh*(pv: var PlayerVision, sc: SceneRec, tokens: seq[TokenRec], playerI
pv.fresh.sort()
proc clearFresh*(pv: var PlayerVision) =
## 4.2 step 8: after the egress fan-out every connection has the cells.
## 4.2 step 8: after the egress fan-out every connection has the cells. `markerFresh` and
## `markerDead` are cleared by their own write (markers.writeNew/writeDead), which ran before the
## egress under the same lock.
pv.fresh.setLen(0)
proc exploredFull*(pv: PlayerVision, sc: SceneRec): seq[(int, int)] =