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:
+43
-2
@@ -57,6 +57,11 @@ async function buildWorld(origin, gmKey) {
|
||||
assert.equal(door.ok, true, JSON.stringify(door))
|
||||
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.sceneId, id: door.id,
|
||||
open: true })).ok, true)
|
||||
// Walls r1 (#59): a marked window every sighted player starts in view of, so the restart
|
||||
// compares a non-empty per-player marker set and the `marker_seen` rows behind it.
|
||||
const window = await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, preset: 'window',
|
||||
a: [450, 300], b: [550, 300] })
|
||||
assert.equal(window.ok, true, JSON.stringify(window))
|
||||
|
||||
// The player's own token: vision, explored cells and the encountered list come from it.
|
||||
const pc = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc',
|
||||
@@ -115,7 +120,7 @@ async function buildWorld(origin, gmKey) {
|
||||
assert.equal((await gm.ws.request({ t: 'name.reveal_all', subject: 'token',
|
||||
id: pc.id })).ok, true)
|
||||
saved.ids = { ...saved.ids, pc: pc.id, monster: monster.id, character: character.id,
|
||||
linked: linked.id, wall: wall.id, door: door.id }
|
||||
linked: linked.id, wall: wall.id, door: door.id, window: window.id }
|
||||
gm.ws.close()
|
||||
} finally {
|
||||
try { gm.ws.close() } catch {}
|
||||
@@ -136,7 +141,7 @@ async function waitResync(client, expected) {
|
||||
count(client, 'character') >= expected.characters &&
|
||||
(expected.gm ? count(client, 'walls') >= 1
|
||||
: count(client, 'encountered') >= 1 && count(client, 'vision') >= 1 &&
|
||||
count(client, 'explored') >= 1)
|
||||
count(client, 'explored') >= 1 && count(client, 'marker') >= 1)
|
||||
if (ok) return
|
||||
if (Date.now() > deadline) {
|
||||
throw new Error(`resync incomplete: ${JSON.stringify(client.messages.map(m => m.t))}`)
|
||||
@@ -162,6 +167,8 @@ async function snapshot(origin, key, expected, isGm) {
|
||||
snap.walls = walls
|
||||
snap.walls.walls.sort(by('id'))
|
||||
snap.characters = pick('character').sort(by('id'))
|
||||
assert.equal(c.ws.messages.some(m => m.t === 'marker'), false,
|
||||
'the GM never receives a marker frame (5.8)')
|
||||
snap.encountered = pick('encountered').map(e => {
|
||||
e.set.sort(by('id'))
|
||||
return e
|
||||
@@ -174,6 +181,9 @@ async function snapshot(origin, key, expected, isGm) {
|
||||
snap.vision.polys.sort(by('id'))
|
||||
// explored RLE rows are already ordered by cy; keep the payload as the view, not a set.
|
||||
snap.explored = pick('explored').pop()
|
||||
// #59: the full marker set, after explored, with this player's own opaque ids.
|
||||
snap.marker = pick('marker').pop()
|
||||
snap.marker.set.sort(by('id'))
|
||||
}
|
||||
return snap
|
||||
} finally {
|
||||
@@ -219,6 +229,15 @@ async function compareAcross(origin, gmKey, players, ids, expected) {
|
||||
}
|
||||
assert.ok(snap.vision.polys.length >= 1, `${who} has sight`)
|
||||
assert.ok(snap.explored.rle.length >= 1, `${who} explored something`)
|
||||
// #59: the marked window is in every sighted player's full set, at its drawn midpoint, under
|
||||
// an opaque 12-character id of that player's own (never the wall id).
|
||||
assert.equal(snap.marker.full, true, `${who}'s marker set is a full resync set`)
|
||||
assert.ok(snap.marker.set.length >= 1, `${who} saw the marked window`)
|
||||
for (const entry of snap.marker.set) {
|
||||
assert.deepEqual(entry.pos, [500, 300], `${who}'s marker anchor is the drawn midpoint`)
|
||||
assert.match(entry.id, /^[A-Za-z0-9_-]{12}$/, `${who}'s marker id is opaque`)
|
||||
assert.notEqual(entry.id, String(ids.window), `${who}'s marker id is never the wall id`)
|
||||
}
|
||||
}
|
||||
return before
|
||||
}
|
||||
@@ -267,6 +286,16 @@ function dbEncounteredNames(stateDir, entityId) {
|
||||
.map(line => { const [id, name] = line.split('='); return [id, name] }))
|
||||
}
|
||||
|
||||
// #59: the persisted marker memory, player id -> marker id, for one wall.
|
||||
function dbMarkerRows(stateDir, wallId) {
|
||||
const r = spawnSync('sqlite3', [path.join(stateDir, 'state.db'),
|
||||
`SELECT player_id || '=' || marker_id FROM marker_seen WHERE wall_id = ${wallId} ` +
|
||||
`ORDER BY player_id`], { encoding: 'utf8' })
|
||||
assert.equal(r.status, 0, r.stderr)
|
||||
return Object.fromEntries(r.stdout.trim().split('\n').filter(Boolean)
|
||||
.map(line => { const [id, markerId] = line.split('='); return [id, markerId] }))
|
||||
}
|
||||
|
||||
const EXPECTED = { tokens: 5, characters: 1 }
|
||||
|
||||
async function restartGroup(hard) {
|
||||
@@ -275,11 +304,21 @@ async function restartGroup(hard) {
|
||||
const players = {}
|
||||
let s = await startServer({ stateDir })
|
||||
let saved
|
||||
let markerRows
|
||||
try {
|
||||
saved = await buildWorld(s.origin, gmKey)
|
||||
players.alice = saved.alice
|
||||
players.bob = saved.bob
|
||||
players.carol = saved.carol
|
||||
// #59: one persisted marker row per player/wall that has seen the window, all distinct per
|
||||
// player, each an opaque id that is never the wall id. The rows are the restart fixture.
|
||||
markerRows = dbMarkerRows(stateDir, saved.ids.window)
|
||||
assert.ok(Object.keys(markerRows).length >= 2,
|
||||
`the marked window wrote marker_seen rows for the sighted players: ${JSON.stringify(markerRows)}`)
|
||||
for (const markerId of Object.values(markerRows)) {
|
||||
assert.match(markerId, /^[A-Za-z0-9_-]{12}$/, 'the persisted marker id is opaque')
|
||||
assert.notEqual(markerId, String(saved.ids.window), 'the marker id is never the wall id')
|
||||
}
|
||||
// #27, asserted against the rows while the server is still up: the monster's actual name was
|
||||
// revealed to Bob only, so exactly one of the three rows carries it.
|
||||
const monsterRows = dbEncounteredNames(stateDir, saved.ids.monster)
|
||||
@@ -297,6 +336,8 @@ async function restartGroup(hard) {
|
||||
}
|
||||
try {
|
||||
await restartAndCompare(stateDir, gmKey, players, saved.ids, EXPECTED, hard)
|
||||
assert.deepEqual(dbMarkerRows(stateDir, saved.ids.window), markerRows,
|
||||
'the marker_seen rows (player and opaque id) survive the restart unchanged')
|
||||
} finally {
|
||||
fs.rmSync(stateDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user