fix: walls r1 review — server (ref #52)

This commit is contained in:
2026-11-20 08:42:50 +01:00
parent f9f26a4a01
commit e1a5b297e4
11 changed files with 198 additions and 167 deletions
+6 -9
View File
@@ -32,11 +32,6 @@ proc anchorOf*(w: WallRec): (int, int) =
## The wall's drawn midpoint, rounded once to integer px and fixed for the wall (5.8, 6.1).
(int(round((w.a.x + w.b.x) / 2.0)), int(round((w.a.y + w.b.y) / 2.0)))
proc wallSig(w: WallRec): string =
## Alias for the shared signature in `world` (5.8, #60): the write path deletes the persisted
## rows by the same rule the online retraction uses.
markerSig(w)
proc extentSeen*(pv: PlayerVision, a, b: Vec): bool =
## True when any point of the wall's visible extent (the segment in this round) is inside one of
## the player's polygons: an endpoint inside, or the segment crossing a polygon edge. Boundary
@@ -84,10 +79,12 @@ proc syncMarkers*(pv: var PlayerVision, sc: SceneRec): int =
## Retraction is first, so a moved wall gives up its old id even when the new geometry is already
## in sight; the mint below is still the ordinary extent gate, never a "the wall moved" shortcut.
## `markerDead` feeds the same derived-memory transaction as `markerFresh` (4.2 step 6).
## One id->wall table per refresh: the retraction is a lookup, not a scan of every wall per marker.
var byId = initTable[int, WallRec]()
for w in sc.walls: byId[w.id] = w
var retract: seq[int]
for wallId in pv.markers.keys:
let wall = sc.wallById(wallId)
if wall.isNone or pv.markers[wallId].sig != wallSig(wall.get):
if not byId.hasKey(wallId) or pv.markers[wallId].sig != markerSig(byId[wallId]):
retract.add wallId
for wallId in retract:
pv.markerDead.add pv.markers[wallId].id
@@ -99,7 +96,7 @@ proc syncMarkers*(pv: var PlayerVision, sc: SceneRec): int =
if w.id in pv.markers: continue
if not pv.qualifies(w): continue
let (x, y) = anchorOf(w)
let marker = Marker(id: freshMarkerId(pv), x: x, y: y, sig: wallSig(w))
let marker = Marker(id: freshMarkerId(pv), x: x, y: y, sig: markerSig(w))
pv.markers[w.id] = marker
pv.markerFresh.add (w.id, marker)
inc result
@@ -156,7 +153,7 @@ proc restore*(db: DbConn, sc: SceneRec, visions: var Table[int, PlayerVision]) =
if wall.isNone: continue
let (x, y) = anchorOf(wall.get)
visions.mgetOrPut(pid, PlayerVision()).markers[wallId] =
Marker(id: row[2], x: x, y: y, sig: wallSig(wall.get))
Marker(id: row[2], x: x, y: y, sig: markerSig(wall.get))
proc markerCount*(db: DbConn, sceneId: int): int =
## Scene-wide marker rows: an O(1) startup log number (11.3) and a test probe.