feat(walls): windows — see-through barrier, movement follows blocks_movement (#57)

- geometry.Wall carries the stored blocks_sight/blocks_movement switches; sight asks
  blocksSight, movement and the status rules ask blocks (open door passes both).
- worldmap translates both switches; moverules only pushes on a movement barrier.
- leakcheck and the tile oracle read blocks_sight independently.
- Walls/token-details/tiles groups prove both forms, sight-through, stuck, push and
  the locked-window open refusal; existing scenes stay byte-identical.

Ref #57

# Conflicts:
#	server/geometry.nim
#	server/world.nim
#	server/worldmap.nim
#	tools/leakcheck.nim
This commit is contained in:
2026-11-19 23:09:05 +01:00
parent cc566ee16e
commit e989100f50
9 changed files with 226 additions and 36 deletions
+15 -2
View File
@@ -28,15 +28,28 @@ type
wdRight = "right"
Wall* = object
## The wall as geometry sees it. The two barrier fields are the stored switches (#57): a
## `window` stores `sightBarrier:false, movementBarrier:true`, so sight passes along its whole
## drawn length while movement and the status rules still treat it as a barrier. An open door
## passes both ways whatever the switches say (DESIGN 5.8). Both default to `true` so a wall
## built without switches (tests, fixtures) keeps the historic solid-wall behaviour.
a*, b*: Vec
door*, open*: bool
sightDir*: WallDir
sightBarrier*: bool = true
movementBarrier*: bool = true
const
Eps* = 1e-9 # geometric tolerance (px)
RayEps = 1e-4 # angular nudge past endpoints (rad)
proc blocks*(w: Wall): bool = not (w.door and w.open)
proc blocks*(w: Wall): bool =
## The movement rule: a wall blocks movement unless it is an open door or its switch is off.
w.movementBarrier and not (w.door and w.open)
proc blocksSight*(w: Wall): bool =
## The sight rule: a wall blocks sight unless it is an open door or its switch is off.
w.sightBarrier and not (w.door and w.open)
proc cross*(a, b: Vec): float = a.x * b.y - a.y * b.x
proc `-`*(a, b: Vec): Vec = (a.x - b.x, a.y - b.y)
@@ -76,7 +89,7 @@ proc visibilityPolygon*(o: Vec, walls: openArray[Wall], radius: float,
(o.x + radius * cos a1, o.y + radius * sin a1)))
angles.add arctan2(sin a0, cos a0) # same (-pi,pi] range as the wall angles, else the sort scrambles the fan
for w in walls:
if not w.blocks: continue
if not w.blocksSight: continue
# shortcut: walls beyond the circle are only culled by ray clipping, O(rays*walls); upgrade: spatial grid
if max(w.a.x, w.b.x) < o.x - radius or min(w.a.x, w.b.x) > o.x + radius or
max(w.a.y, w.b.y) < o.y - radius or min(w.a.y, w.b.y) > o.y + radius: continue
+13 -10
View File
@@ -279,16 +279,19 @@ proc setDoor*(sc: var Scene, id: int, open: bool, pushed: var seq[Push]): bool =
else:
sc.walls[id].open = false
let w = sc.walls[id]
for i in 0 ..< sc.tokens.len:
if not overlaps(sc, sc.tokens[i], w): continue
let (ok, p) = pushFrom(sc, sc.tokens[i], w)
if ok:
sc.tokens[i].prev = sc.tokens[i].pos; sc.tokens[i].hasPrev = true
sc.tokens[i].pos = p
sc.tokens[i].clearWalls() # a pushed token is clear of every blocking wall
pushed.add Push(ti: i, pos: p)
else:
sc.tokens[i].squeezedWalls = true
# Only a wall that blocks movement pushes: closing a see-through opening window is a solid
# barrier and pushes; a door whose movement switch is off (a custom shape) does not (#57).
if w.blocks:
for i in 0 ..< sc.tokens.len:
if not overlaps(sc, sc.tokens[i], w): continue
let (ok, p) = pushFrom(sc, sc.tokens[i], w)
if ok:
sc.tokens[i].prev = sc.tokens[i].pos; sc.tokens[i].hasPrev = true
sc.tokens[i].pos = p
sc.tokens[i].clearWalls() # a pushed token is clear of every blocking wall
pushed.add Push(ti: i, pos: p)
else:
sc.tokens[i].squeezedWalls = true
true
proc setDoor*(sc: var Scene, id: int, open: bool): bool =
+4 -4
View File
@@ -4,10 +4,10 @@
##
## Walls (DESIGN 8, FIXED #3): per-scene ids from `scene.next_wall_id`, monotonic and never reused
## (a removal leaves the counter alone). Identity is `(scene, id)` in the DB, in memory and on the
## wire. A wall's sight/movement behaviour is still `blocks = not (door and open)` in
## geometry.Wall plus the per-viewer one-way filter (`sight_dir`, #58); `blocks_sight` and
## `blocks_movement` gain their general behaviour in the window/movement round (#57). `flags` is a
## free JSON object the server never interprets.
## wire. A wall's behaviour is its stored switches: `blocks_sight` drives the vision fan and
## `blocks_movement` drives the move rules and the walls-sourced statuses, and an open door passes
## both (geometry.Wall, #57). `sight_dir` filters sight per viewer (the blind side, #58). `flags` is
## a free JSON object the server never interprets.
##
## Wire payload shapes are DESIGN 6.1; the parts it leaves open are fixed here (recorded FIXED
## owner-delegated, #19, in DESIGN 6.1/14):
+11 -8
View File
@@ -18,26 +18,29 @@ import std/options
import geometry, moverules, tokens, world, faults
proc geometryWalls*(sc: SceneRec, forSight = false): seq[Wall] =
## The scene's walls as the vision code sees them: an open door does not block (5.1), and a
## one-way wall carries the side that is blind (5.8, #58). Movement gets the same mapping and
## ignores `sightDir` (two-way).
## `forSight` is only the sight computation; `LEAK_FAULT=secretgap` (a -d:leakfault build only)
## opens a secret door there, the negative control for the door-equivalence group (#56).
## The scene's walls as the vision and move code see them. Each wall carries its stored switches:
## the sight fan asks `blocksSight` (and the one-way `sightDir`, 5.8/#58), the move rules and the
## statuses ask `blocks`, so a window is see-through but still a barrier to movement (#57). Every
## wall stays in the list, in scene order: `moverules` addresses walls by that index. `forSight`
## is only the sight computation; `LEAK_FAULT=secretgap` (a -d:leakfault build only) opens a
## secret door there, the negative control for the door-equivalence group (#56).
result = newSeqOfCap[Wall](sc.walls.len)
for w in sc.walls:
let dir = case w.sightDir
of sdBoth: wdBoth
of sdLeft: wdLeft
of sdRight: wdRight
var wall = Wall(a: w.a, b: w.b, door: w.door, open: w.open, sightDir: dir)
var wall = Wall(a: w.a, b: w.b, door: w.door, open: w.open, sightDir: dir,
sightBarrier: w.blocksSight, movementBarrier: w.blocksMovement)
if forSight and w.secret and faultActive("secretgap"):
wall.open = true
result.add wall
proc ruleWall*(w: WallRec): Wall =
## The same wall as the move rules see it (they need `door`/`open` to know what blocks; the
## The same wall as the move rules see it (they need the movement switch and `door`/`open`; the
## one-way direction is sight-only and never read by the move rules, so it is not mapped).
Wall(a: w.a, b: w.b, door: w.door, open: w.open)
Wall(a: w.a, b: w.b, door: w.door, open: w.open,
sightBarrier: w.blocksSight, movementBarrier: w.blocksMovement)
proc ruleToken*(sc: SceneRec, t: TokenRec): moverules.Token =
moverules.Token(pos: t.pos, owner: t.owner,
+72
View File
@@ -184,6 +184,78 @@ test('stuck from a wall and from a GM placement, cleared by the removal and by a
})
})
test('windows: see-through, movement and statuses follow blocks_movement, closing pushes (#57)',
async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc',
pos: [300, 300], descriptive_name: 'Alice',
actual_name: 'Alice', controller: alice.id,
flags: { vision: true }, vision_radius: 400 })
// A fixed window (blocks_sight off, movement on, no door) is the only barrier between Alice
// and Bob: Bob must reach her through it, because sight passes along the whole segment.
await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, a: [400, 150],
b: [400, 450], blocks_sight: false })
const bob = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'npc',
pos: [500, 300], descriptive_name: 'a guard',
actual_name: 'Vex' })
const a = await openAs(s.origin, alice.key)
await a.ws.waitText('hello')
const seenBob = await a.ws.waitFor(m => m.t === 'token' && m.id === bob.id)
assert.deepEqual(seenBob.pos, [500, 300], 'a window lets the player see through it')
// Movement does not: the same segment still blocks the crossing exactly as a solid wall.
assert.equal((await gm.ws.request({ t: 'token.move', id: tok.id, pos: [360, 300] })).ok, true)
const nack = await a.ws.request({ t: 'token.move', id: tok.id, pos: [440, 300] })
assert.equal(nack.ok, false, 'a fixed window blocks movement')
assert.deepEqual(nack.pos, [360, 300])
// A window added over the token gives stuck(walls), like a solid wall (movement switch on).
const over = await mutate(gm.ws, { t: 'wall.add', scene: gm.sceneId, a: [360, 200],
b: [360, 400], blocks_sight: false })
let frame = await over.wait(m => m.t === 'token' && m.id === tok.id && m.statuses.length > 0)
assert.deepEqual(frame.statuses, [{ status: 'stuck', source: 'walls' }])
const cleared = await mutate(gm.ws, { t: 'wall.remove', scene: gm.sceneId, id: over.ack.id })
assert.equal(cleared.ack.ok, true)
frame = await cleared.wait(m => m.t === 'token' && m.id === tok.id && m.statuses.length === 0)
assert.deepEqual(frame.statuses, [])
// The movement switch decides the status, not the see-through shape: a custom barrier with
// both switches off overlaps the token without sticking it.
const pass = await mutate(gm.ws, { t: 'wall.add', scene: gm.sceneId, a: [360, 200],
b: [360, 400], blocks_sight: false,
blocks_movement: false })
const passFrame = await gm.ws.waitFor(m => m.t === 'wall' && m.id === pass.ack.id)
assert.equal(passFrame.kind, 'custom')
await sleep(80)
assert.deepEqual(frameOf(gm.ws, tok.id).statuses, [], 'blocks_movement off: no stuck')
// Closing an opening window pushes exactly as a closing solid wall does. The token sits on
// the line while the leaf is open (no overlap: an open door blocks nothing), then is moved
// clear to the wall's left side by the close.
const opening = await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, a: [1000, 150],
b: [1000, 450], preset: 'window' })
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.sceneId, id: opening.id,
open: true })).ok, true)
const onLine = await mutate(gm.ws, { t: 'token.move', id: tok.id, pos: [1000, 300] })
frame = await onLine.wait(m => m.t === 'token' && m.id === tok.id && m.pos[0] === 1000)
assert.deepEqual(frame.statuses, [], 'an open window blocks nothing')
const closed = await mutate(gm.ws, { t: 'door.set', scene: gm.sceneId, id: opening.id,
open: false })
assert.equal(closed.ack.ok, true)
frame = await closed.wait(m => m.t === 'token' && m.id === tok.id && m.pos[0] !== 1000)
assert.ok(Math.abs(frame.pos[0] - 980) < 0.01, `pushed off the leaf: ${JSON.stringify(frame.pos)}`)
assert.equal(frame.pos[1], 300)
assert.deepEqual(frame.statuses, [], 'a pushed token is clear of every blocking wall')
// Re-opening makes the same segment a gap the player can walk through.
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.sceneId, id: opening.id,
open: true })).ok, true)
assert.equal((await a.ws.request({ t: 'token.move', id: tok.id, pos: [1020, 300] })).ok, true)
a.ws.close(); gm.ws.close()
})
})
test('status.set and status.clear: the GM source, single entries, and the codes of 6.1', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
+9 -1
View File
@@ -373,11 +373,19 @@ test('door.set: secret and locked refuse opening, closing is allowed, players ar
await gm.ws.request({ t: 'wall.update', scene, id: locked, locked: false })
await setDoor(locked, true)
// A locked opening window is still see-through, but its leaf refuses to open until unlocked;
// once the lock is cleared the same intent opens it exactly like a door (#57).
const lockedWindow = await add({ a: [10, 60], b: [100, 60], blocks_sight: false,
door: true, locked: true })
await setDoor(lockedWindow, true, 'invalid')
await gm.ws.request({ t: 'wall.update', scene, id: lockedWindow, locked: false })
await setDoor(lockedWindow, true)
const player = await createPlayer(gm.ws)
await namePlayer(s.origin, player.key, 'Dora')
const p = await openAs(s.origin, player.key)
await p.ws.waitText('hello')
for (const id of [plainDoor, secret, locked, both]) {
for (const id of [plainDoor, secret, locked, both, lockedWindow]) {
for (const open of [true, false]) {
const ack = await p.ws.request({ t: 'door.set', scene, id, open })
assert.equal(ack.ok, false, JSON.stringify(ack))
+11 -5
View File
@@ -143,12 +143,16 @@ proc applyGmWalls(truth: var Truth, ids: var seq[int], m: JsonNode) =
for w in m["walls"]:
truth.walls.add Wall(a: vec(w["a"]), b: vec(w["b"]),
door: w["door"].getBool, open: w["open"].getBool,
sightDir: wallDir(w["sight_dir"]))
sightDir: wallDir(w["sight_dir"]),
sightBarrier: w["blocks_sight"].getBool,
movementBarrier: w["blocks_movement"].getBool)
ids.add w["id"].getInt
of "wall":
let id = m["id"].getInt
let w = Wall(a: vec(m["a"]), b: vec(m["b"]), door: m["door"].getBool,
open: m["open"].getBool, sightDir: wallDir(m["sight_dir"]))
open: m["open"].getBool, sightDir: wallDir(m["sight_dir"]),
sightBarrier: m["blocks_sight"].getBool,
movementBarrier: m["blocks_movement"].getBool)
var found = false
for i in 0 ..< ids.len:
if ids[i] == id:
@@ -238,11 +242,13 @@ proc wallsFor(truth: Truth, o: Vec, honourDir: bool): seq[Wall] =
for w in result.mitems: w.sightDir = wdBoth
proc clearLine(walls: seq[Wall], o, p: Vec): bool =
## The clear-segment oracle: no blocking wall between o and p (independent of the ray fan). The
## one-way filter is the checker's own side test, for the sample's viewer `o`.
## The clear-segment oracle: no sight-blocking wall between o and p (independent of the ray fan).
## Two independent readings: the one-way side test for the sample's viewer `o` (#58) and the GM's
## `blocks_sight` switch (#57: a window never blocks, an open door never blocks, a solid or closed
## door does). Neither uses the server's vision code.
for w in walls:
if checkDir and w.sightDir != wdBoth and not w.blindTo(o): continue
if w.blocks and segsCross(o, p, w.a, w.b): return false
if w.blocksSight and segsCross(o, p, w.a, w.b): return false
true
proc rangeOf(sceneDefault: float, t: TruthToken): float =
+49 -6
View File
@@ -56,11 +56,12 @@ async function addWall(gm, fields) {
// A named player who controls one token with vision at (300, 300), radius 400, and a wall at x=400
// splitting the view. The player's explored grid is then produced by the server's own resync.
async function sceneWithVision(s, gmKey, ngx) {
// `wallFields` lets a test make that segment a see-through window without changing anything else.
async function sceneWithVision(s, gmKey, ngx, wallFields = {}) {
const gm = await gmConnect(ngx.origin, gmKey)
const player = await createPlayer(gm.ws)
await namePlayer(ngx.origin, player.key, 'Alice')
const wall = await addWall(gm, { a: [400, 100], b: [400, 700] })
const wall = await addWall(gm, { a: [400, 100], b: [400, 700], ...wallFields })
const created = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
pos: [300, 300], flags: { vision: true },
vision_radius: 400, controller: player.id,
@@ -111,11 +112,13 @@ function segGap(p, q, a, b) {
return Math.min(segDist(p, a, b), segDist(q, a, b), segDist(a, p, q), segDist(b, p, q))
}
function blockingWalls(wallsFrame) {
// A wall blocks sight unless it is an open door (today's rule; the raw switches gain their
// behaviour in the window/one-way rounds, #57/#58).
function blockingWalls(wallsFrame, opts = {}) {
// The oracle's own reading of the sight switches (#57): a wall blocks sight only while its
// `blocks_sight` switch is on and it is not an open door. A window is see-through along its whole
// drawn length. `ignoreBlocksSight` is the negative control: it restores the old
// `door/open`-only rule, under which a window would wrongly block.
return wallsFrame.walls
.filter(w => !(w.door && w.open))
.filter(w => (opts.ignoreBlocksSight || w.blocks_sight !== false) && !(w.door && w.open))
.map(w => ({ a: { x: w.a[0], y: w.a[1] }, b: { x: w.b[0], y: w.b[1] } }))
}
@@ -252,6 +255,46 @@ test('tile gate: leak check (d) matches the independent explored oracle', async
})
})
test('tile gate: a window is see-through along its drawn length (#57)', async () => {
await withTileStack(async ({ s, gmKey, ngx, stateDir }) => {
// A fixed window: the same segment as the solid-wall scenario, `blocks_sight:false` and no door,
// so nothing about the change is a door opening. The token still sits 100 px west of it.
const ctx = await sceneWithVision(s, gmKey, ngx,
{ blocks_sight: false, blocks_movement: true })
const scene = ctx.gm.ws.messages.find(m => m.t === 'hello' && m.scene).scene
const cell = scene.cell
const tile = scene.tile_size
const frame = ctx.wallsFrame.walls[0]
assert.equal(frame.kind, 'window')
assert.equal(frame.blocks_sight, false)
assert.equal(frame.blocks_movement, true)
assert.equal(frame.door, false, 'the fixed form has no open state')
writeTileGrid(stateDir, { scene: scene.id, artVersion: ctx.artVersion, size: tile,
x0: 0, x1: 31, y0: 0, y1: 31 })
const o = { x: ctx.token.pos[0], y: ctx.token.pos[1] }
const radius = ctx.token.vision_radius
const seenThrough = blockingWalls(ctx.wallsFrame)
const opaque = blockingWalls(ctx.wallsFrame, { ignoreBlocksSight: true })
// Cells just east of x=400 are behind the drawn window. The oracle (own reading of
// `blocks_sight`) can see them; a window treated as opaque could not, which is the control.
for (const bx of [13, 14, 15]) {
assert.equal(oracleCell({ o, radius, walls: seenThrough, cell, x: bx, y: 9 }).maybe, true,
`cell ${bx},9 must be visible through the window`)
assert.equal(oracleCell({ o, radius, walls: opaque, cell, x: bx, y: 9 }).maybe, false,
`control: cell ${bx},9 must be hidden if the window wrongly blocked sight`)
}
// The gate agrees with the see-through oracle: those cells are allowed.
const cookie = ctx.seenCtx.cookie
for (const bx of [14, 15]) {
const r = await getTile(ngx.origin, tileUrl(scene.id, ctx.artVersion, bx, 9), cookie)
await r.arrayBuffer()
assert.equal(r.status, 200, `tile ${bx},9 behind the window must be allowed`)
}
ctx.gm.ws.close(); ctx.seenCtx.ws.close()
})
})
test('tile gate: refusals, direct /_tiles, malformed and out-of-range paths', async () => {
await withTileStack(async ({ s, gmKey, ngx, stateDir }) => {
const ctx = await sceneWithVision(s, gmKey, ngx)
+42
View File
@@ -317,6 +317,48 @@ test('wall.update presets replace the whole switch set and raw patches only name
})
})
test('window: the opening and fixed forms author, echo and derive kind "window" (#57)', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const { id } = await addWall(gm, { a: [10, 10], b: [300, 10], preset: 'window' })
const opening = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id)
assert.equal(opening.kind, 'window')
assert.equal(opening.blocks_sight, false)
assert.equal(opening.blocks_movement, true)
assert.equal(opening.door, true, 'the preset form can be opened')
assert.equal(opening.open, false)
assert.equal(opening.player_marker, true, 'the window preset carries the marker')
// The fixed form is the same switches with the door switch off; it still derives `window`.
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id,
door: false })).ok, true)
const fixed = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id && m.door === false)
assert.equal(fixed.kind, 'window')
assert.equal(fixed.blocks_sight, false)
assert.equal(fixed.blocks_movement, true)
assert.equal(fixed.open, false)
assert.equal(fixed.player_marker, true, 'turning the door off keeps the marker')
// A fixed window has no open state, so `door.set` refuses both directions.
for (const open of [true, false]) {
const ack = await gm.ws.request({ t: 'door.set', scene: gm.scene, id, open })
assert.equal(ack.ok, false, String(open))
assert.equal(ack.code, 'invalid')
}
// The obvious conversion, `door:true`, yields a closed opening window. `open` in a wall update
// is an unknown field and is ignored (it belongs to door.set); the door patch still applies.
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id, door: true,
open: true })).ok, true)
const reopened = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id && m.door === true)
assert.equal(reopened.kind, 'window')
assert.equal(reopened.open, false, 'open is not a wall-update patch field')
// An update naming only `open` has no patch field at all and is invalid.
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id, open: true })).code,
'invalid')
gm.ws.close()
})
})
test('switch-set invariants: door-only settings need a door, and open excludes secret/locked (#55)',
async () => {
await withGmServer(async (s, gmKey) => {