feat(client): fog explored bitmap, vision cut-out and player markers (#70)

The fog layer (DESIGN 7.1 layer 4, spec #63 decision 9) keeps the explored
grid in one cell-resolution RGBA canvas: never-seen cells opaque black,
explored cells black at 0.6 alpha. A second canvas is the sprite texture:
the explored canvas is copied into it and the union of the server's vision
polygons is cut out with `destination-out`. A full explored snapshot
repaints; a cell diff mutates only the new bytes and uploads the dirty
rectangle. Player markers from the marker set/del frames are sprites above
the fog; the GM layer hides the fog.

The cut-out is baked instead of using a Graphics stencil mask: on the e2e's
software renderer the stencil state cost ~350 ms of the phone-class viewport
fill budget (412x869 dpr 2.625), while baking keeps the fill at the pre-fog
baseline. The cut-out is rasterized at cell resolution, the same grid the
server sends.

Integration fix in the tile layer: a tile denied with 403 because it was
unexplored is asked once more when the fog says its cells became explored;
unexplored denials still never retry (the map 403 test is unchanged).

Proven at the reducer seam (fog slice) and by screenshot pixel probes in the
browser e2e: black/dim/visible, window see-through, one-way blind side,
secret door, marker anchor and retraction, a drag that moves the fog with no
reload, and a reconnect resync. Fog update cost recorded under the 412x869
dpr 2.625 / 4x CPU emulation.
This commit is contained in:
2026-11-21 10:44:32 +01:00
parent d225e956ca
commit 2d9548c941
8 changed files with 1423 additions and 6 deletions
+320
View File
@@ -0,0 +1,320 @@
// The fog and marker layer (T7, #70; DESIGN 7.1 layer 4, 7.3). Three states from the server's facts:
// never-seen floor is opaque black, explored floor is black at ~0.6 alpha, currently visible floor
// is cut out of the fog so the map shows through.
//
// Mechanism (spec #63 decision 9 leaves the Pixi object to the build):
// - one RGBA canvas at cell resolution (`ceil(w/cell) x ceil(h/cell)`) holds the *explored* state:
// never-seen cells alpha 255, explored cells alpha ~0.6. It is repainted from an `ImageData`
// buffer; a cell diff mutates only the new bytes and uploads only the dirty rectangle, so "only
// changed cells" is the normal path (DESIGN 7.2);
// - a second canvas of the same size is the texture the sprite displays: the explored canvas is
// copied into it and the union of this player's `vision` polygons is cut out with
// `destination-out`, which is the polygon cut-out itself, not a separate stencil pass. It is
// recomposed only when an explored or vision frame arrives; there is no per-frame work here;
// - player markers are small sprites in the same layer, drawn above the fog sprite from the
// `marker` set/del frames, never inferred from tiles or walls (decision 17).
//
// Why no stencil mask: a Graphics stencil mask forces a depth-stencil attachment plus a full-frame
// stencil pass on every frame. Measured on the e2e's software renderer it cost ~350 ms of the
// phone-class viewport-fill budget (test 412x869 dpr 2.625); the baked cut-out keeps the same
// pixels and leaves the fill at the pre-fog baseline. The cut-out is rasterized at cell resolution,
// the same resolution as the explored grid the server sends.
//
// The GM has no fog (story 26): the layer hides and the GM never receives `explored`/`vision`/
// `marker` frames anyway. The counts, timings and ids are published on the canvas dataset; the e2e
// reads them and probes the pixels, so the test never touches renderer internals.
import { Container, Graphics, GraphicsContext, Sprite, Texture } from 'pixi.js'
import type { RenderContext, RenderModule } from '../stage.ts'
import type { RootState } from '../../reducer.ts'
import { fogOf } from '../../slices/fog.ts'
import type { FogState, VisionPoly } from '../../slices/fog.ts'
/** Explored-but-not-visible: black at 0.6 alpha, so the map reads dimmed, never hidden. */
export const EXPLORED_ALPHA = 0.6
/** One shared icon context for every marker: a lit window pane with a dark frame. */
const MARKER_ICON = new GraphicsContext()
.roundRect(-7, -7, 14, 14, 2)
.fill(0xffcc33)
.stroke({ width: 2, color: 0x2b1d00 })
export const renderModule: RenderModule = {
name: 'fog',
mount({ app, layers, store }: RenderContext) {
const canvas = app.canvas
// Markers live in their own layer above the fog sprite.
const markerLayer = new Container()
layers.fog.addChild(markerLayer)
let sprite: Sprite | null = null
let texture: Texture | null = null
/** Explored state (`alpha 255` never seen, `alpha 153` explored), at cell resolution. */
let base: HTMLCanvasElement | null = null
let baseContext: CanvasRenderingContext2D | null = null
let baseImage: ImageData | null = null
/** What the sprite shows: `base` with the vision polygons cut out. */
let shown: HTMLCanvasElement | null = null
let shownContext: CanvasRenderingContext2D | null = null
let grid = { cols: 0, rows: 0 }
let cell = 0
let sceneId: number | null = null
/** The union of this player's polygons, kept for every recompose after a cell diff. */
let currentPolys: readonly VisionPoly[] = []
let renderedExplored = -1
let renderedVision = -1
let renderedMarkers = -1
const markerNodes = new Map<string, Graphics>()
// Instrumentation. `cellsPainted` is the cumulative number of cell pixels touched, so a diff
// is visibly cheaper than the snapshot; `fullRedraws` stays at 1 after a connect.
const stats = {
cellsPainted: 0,
fullRedraws: 0,
visionBuilds: 0,
markerUpdates: 0,
lastFresh: 0,
exploredMs: 0,
fullMs: 0,
visionMs: 0,
}
function destroySurface(): void {
sprite?.destroy()
sprite = null
texture?.destroy(true)
texture = null
base = null
baseContext = null
baseImage = null
shown = null
shownContext = null
grid = { cols: 0, rows: 0 }
cell = 0
sceneId = null
renderedExplored = -1
renderedVision = -1
}
function build(fog: FogState, width: number, height: number): void {
const cols = fog.cols
const rows = fog.rows
if (cols <= 0 || rows <= 0) return
base = document.createElement('canvas')
base.width = cols
base.height = rows
const exploredContext = base.getContext('2d')
if (!exploredContext) return
baseContext = exploredContext
baseImage = exploredContext.createImageData(cols, rows)
// Before the first `explored` frame everything is never-seen: opaque black.
exploredContext.fillStyle = '#000'
exploredContext.fillRect(0, 0, cols, rows)
shown = document.createElement('canvas')
shown.width = cols
shown.height = rows
const fogContext = shown.getContext('2d')
if (!fogContext) return
shownContext = fogContext
fogContext.fillStyle = '#000'
fogContext.fillRect(0, 0, cols, rows)
grid = { cols, rows }
cell = fog.cell
texture = Texture.from(shown)
// The cell texture is displayed scaled: smooth beats a pixelated haze at any zoom.
texture.source.scaleMode = 'linear'
sprite = new Sprite(texture)
sprite.width = width
sprite.height = height
sprite.label = 'fog'
layers.fog.addChildAt(sprite, 0)
sceneId = fog.sceneId
renderedExplored = -1
renderedVision = -1
}
/**
* Rebuild the displayed texture from the explored base and the current vision polygons. The
* canvas 2D `destination-out` fill is the polygon cut-out: antialiased at cell resolution and
* one cheap draw, with no mask/stencil state on the render target.
*/
function compose(): number {
if (!shownContext || !base || !shown) return 0
const started = performance.now()
shownContext.globalCompositeOperation = 'copy'
shownContext.drawImage(base, 0, 0)
const polys = currentPolys
if (polys.length > 0 && cell > 0) {
shownContext.globalCompositeOperation = 'destination-out'
shownContext.save()
shownContext.scale(1 / cell, 1 / cell)
// One fill per polygon: overlapping polygons punch the same hole whether their winding
// orders agree or not (a single nonzero fill could cancel an opposite-winding overlap).
for (const poly of polys) {
const [first, ...rest] = poly.pts
if (!first) continue
shownContext.beginPath()
shownContext.moveTo(first[0], first[1])
for (const [x, y] of rest) shownContext.lineTo(x, y)
shownContext.closePath()
shownContext.fill()
}
shownContext.restore()
}
shownContext.globalCompositeOperation = 'source-over'
texture?.source.update()
return performance.now() - started
}
/** Paint the explored state into `base`. Full repaint only for a snapshot or missed revision. */
function paintExplored(fog: FogState): void {
if (!baseContext || !baseImage || !texture || fog.cols !== grid.cols || fog.rows !== grid.rows) {
return
}
const started = performance.now()
const data = baseImage.data
const full = fog.snapshot || fog.exploredVersion !== renderedExplored + 1
const alpha = Math.round(EXPLORED_ALPHA * 255)
if (full) {
for (let i = 3; i < data.length; i += 4) data[i] = 255
for (const index of fog.cells) data[index * 4 + 3] = alpha
baseContext.putImageData(baseImage, 0, 0)
stats.cellsPainted += grid.cols * grid.rows
stats.fullRedraws += 1
} else if (fog.fresh.length > 0) {
let minX = grid.cols
let minY = grid.rows
let maxX = -1
let maxY = -1
for (const index of fog.fresh) {
data[index * 4 + 3] = alpha
const x = index % grid.cols
const y = (index / grid.cols) | 0
if (x < minX) minX = x
if (y < minY) minY = y
if (x > maxX) maxX = x
if (y > maxY) maxY = y
}
stats.cellsPainted += fog.fresh.length
// One write of the dirtied rectangle, not the whole map.
baseContext.putImageData(baseImage, 0, 0, minX, minY, maxX - minX + 1, maxY - minY + 1)
} else {
renderedExplored = fog.exploredVersion
stats.exploredMs = performance.now() - started
return
}
currentPolys = fog.polys
const composeMs = compose()
renderedExplored = fog.exploredVersion
renderedVision = fog.visionVersion
stats.lastFresh = fog.fresh.length
stats.exploredMs = performance.now() - started + composeMs
if (full) stats.fullMs = stats.exploredMs
}
/** Recompose the cut-out; nothing per frame. */
function paintVision(fog: FogState): void {
if (!base) return
currentPolys = fog.polys
stats.visionMs = compose()
renderedVision = fog.visionVersion
stats.visionBuilds += 1
}
/** Apply one `marker` change: only added, removed or moved ids are touched. */
function paintMarkers(fog: FogState): void {
for (const [id, node] of markerNodes) {
if (fog.markers[id] !== undefined) continue
markerLayer.removeChild(node)
node.destroy()
markerNodes.delete(id)
}
for (const [id, pos] of Object.entries(fog.markers)) {
let node = markerNodes.get(id)
if (!node) {
node = new Graphics(MARKER_ICON)
node.label = `marker-${id}`
markerLayer.addChild(node)
markerNodes.set(id, node)
}
if (node.x !== pos[0] || node.y !== pos[1]) node.position.set(pos[0], pos[1])
}
renderedMarkers = fog.markerVersion
stats.markerUpdates += 1
}
function publish(fog: FogState): void {
const datasets = canvas.dataset
const role = store.state.session.role
datasets['fog'] = role === 'gm' ? 'gm' : sceneId === null ? 'idle' : 'player'
datasets['fogCells'] = String(fog.cells.size)
datasets['fogPolys'] = String(fog.polys.length)
datasets['fogMarkers'] = Object.keys(fog.markers).join(' ')
datasets['fogCellsPainted'] = String(stats.cellsPainted)
datasets['fogFullRedraws'] = String(stats.fullRedraws)
datasets['fogVisionBuilds'] = String(stats.visionBuilds)
datasets['fogMarkerUpdates'] = String(stats.markerUpdates)
datasets['fogLastFresh'] = String(stats.lastFresh)
datasets['fogExploredMs'] = stats.exploredMs.toFixed(3)
datasets['fogFullMs'] = stats.fullMs.toFixed(3)
datasets['fogVisionMs'] = stats.visionMs.toFixed(3)
}
function sync(state: RootState): void {
const fog = fogOf(state)
const role = state.session.role
const gm = role === 'gm'
// The GM sees everything: no fog and no marker-only memory (stories 24-26).
if (sprite) sprite.visible = !gm
markerLayer.visible = !gm
if (gm || fog.cols <= 0 || !state.session.scene) {
publish(fog)
return
}
const width = state.session.scene.w
const height = state.session.scene.h
if (sceneId !== fog.sceneId || !sprite) {
destroySurface()
build(fog, width, height)
for (const node of markerNodes.values()) node.destroy()
markerNodes.clear()
} else if (sprite.width !== width || sprite.height !== height) {
sprite.width = width
sprite.height = height
}
if (!sprite) {
publish(fog)
return
}
if (fog.exploredVersion !== renderedExplored) paintExplored(fog)
// A vision frame can arrive before the first explored frame; compose still needs the base.
else if (fog.visionVersion !== renderedVision) paintVision(fog)
if (fog.markerVersion !== renderedMarkers) paintMarkers(fog)
publish(fog)
}
// The stage is created once the session is live, but a resync can beat `app.init`: start from
// whatever the reducer already holds, then follow the event stream.
sync(store.state)
const unsubscribe = store.subscribe(sync)
return () => {
unsubscribe()
for (const node of markerNodes.values()) node.destroy()
markerNodes.clear()
destroySurface()
layers.fog.removeChild(markerLayer)
markerLayer.destroy({ children: true })
}
},
}
+18 -4
View File
@@ -4,7 +4,8 @@
// TileScheduler's 8-wide queue. The decoded textures live in a module-level cache keyed by URL, so
// a reconnect (which keeps the stage and only resets the reducer slices) never refetches a tile.
// A `403` from the server is the gate saying "not yours": it is remembered as denied and never
// retried. Sprites outside the wanted window are removed but their textures are kept.
// retried *while its cells stay unexplored*. When the fog slice reports newly explored cells (#70)
// the gate's answer for those tiles changed, so exactly those denied tiles are asked once more.
//
// The e2e contract on the canvas: `data-tiles` (`loading`/`ready`/`idle`) and
// `data-tile-requests` (how many fetches this page ever made). `ready` means every tile the current
@@ -13,8 +14,9 @@
import { Sprite, Texture } from 'pixi.js'
import type { RenderModule } from '../stage.ts'
import { viewport, visibleTiles } from '../../viewport.ts'
import { TileScheduler } from '../../tiles.ts'
import { TileScheduler, tilesForCells } from '../../tiles.ts'
import type { TileLoadResult } from '../../tiles.ts'
import { fogOf } from '../../slices/fog.ts'
/** Kept across a reconnect (and even a stage rebuild): URL -> decoded texture. */
const textureCache = new Map<string, Texture>()
@@ -115,8 +117,20 @@ export const renderModule: RenderModule = {
}
const unsubscribe = viewport.subscribe(scheduleSync)
// A reconnect is the moment to give transient failures another chance; a 403 stays denied.
const unsubscribeStore = store.subscribe((_state, event) => {
let lastExplored = -1
const unsubscribeStore = store.subscribe((state, event) => {
// Newly explored cells can flip a tile's `403` to an allowed tile (#70): retry exactly the
// denied tiles the new cells touch, once. An unexplored 403 stays denied (no retry loop).
const fog = fogOf(state)
if (fog.exploredVersion !== lastExplored) {
lastExplored = fog.exploredVersion
const scene = viewport.state.scene
if (fog.fresh.length > 0 && scene) {
scheduler.retryDenied(tilesForCells(scene, fog, fog.fresh))
scheduleSync()
}
}
// A reconnect is the moment to give transient failures another chance; a 403 stays denied.
if (event.type === 'frame' && event.frame.t === 'hello') {
scheduler.retryFailed()
scheduleSync()
+207
View File
@@ -0,0 +1,207 @@
// Fog slice (T7, #70; DESIGN 6.1 `explored`/`vision`/`marker`, 7.3). Append-only registration: this
// file was enough; the reducer's glob picked it up and `hello` resets it with every other slice.
//
// The server sends derived, per-recipient memory: `explored` (a full RLE snapshot on connect, cell
// diffs after), `vision` (the union of this player's sight polygons, integer px) and `marker`
// (this player's opaque window-marker ids with an anchor). Nothing here is a secret the client
// must enforce; it is only what the server chose to send (DESIGN 7.3, story 27).
//
// The slice keeps the whole explored set, because a reconnect must rebuild the view from a full
// snapshot, plus the *delta* of the last `explored` frame. The renderer uses the delta to touch only
// the new cells (DESIGN 7.2); a snapshot or a missed revision tells it to redraw everything.
import type { ReducerEvent, RootState, Slice } from '../reducer.ts'
import type { SceneInfo, ServerFrame, Vec2 } from '../protocol.ts'
/** One sight polygon: the token that produced it and its integer-px points (DESIGN 6.1, Q16). */
export interface VisionPoly {
id: string
pts: Vec2[]
}
export interface FogState {
/** The explored cell grid, from `hello.scene`: `cols = ceil(w / cell)`, `rows = ceil(h / cell)`. */
cols: number
rows: number
cell: number
sceneId: number | null
/** Explored cells, row-major (`cy * cols + cx`). Only ever grows between `hello`s. */
cells: Set<number>
/** Cells added by the latest explored update: the only cells a renderer has to touch. */
fresh: number[]
/** The latest explored update was a full `rle` snapshot, not a cell diff. */
snapshot: boolean
/** Bumped when the explored set changes; a renderer tracks what it has already drawn. */
exploredVersion: number
/** This player's current sight polygons (server-clipped already; never another player's). */
polys: VisionPoly[]
/** Bumped when the polygon union changes; the renderer rebuilds the cut-out then. */
visionVersion: number
/** This player's own window markers: opaque id -> integer-px anchor (DESIGN 5.8, 6.1). */
markers: Record<string, Vec2>
/** Bumped when the marker set or an anchor changes. */
markerVersion: number
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value)
}
function isInt(value: unknown): value is number {
return typeof value === 'number' && Number.isInteger(value)
}
function isVec2(value: unknown): value is Vec2 {
return Array.isArray(value) && value.length === 2 && isInt(value[0]) && isInt(value[1])
}
export function emptyFog(): FogState {
return {
cols: 0,
rows: 0,
cell: 0,
sceneId: null,
cells: new Set<number>(),
fresh: [],
snapshot: false,
exploredVersion: 0,
polys: [],
visionVersion: 0,
markers: {},
markerVersion: 0,
}
}
/** The cell grid of a scene, or zero for a missing/invalid one. */
function gridOf(scene: SceneInfo | null): { cols: number; rows: number; cell: number } {
const cell = scene && scene.cell > 0 ? scene.cell : 0
if (!scene || cell <= 0 || !(scene.w > 0) || !(scene.h > 0)) return { cols: 0, rows: 0, cell: 0 }
return { cols: Math.ceil(scene.w / cell), rows: Math.ceil(scene.h / cell), cell }
}
/** `explored {full:true, rle:[[cy, x0, len, x0, len, ...], ...]}` (DESIGN 6.1). */
function applyFull(state: FogState, rle: unknown): boolean {
if (!Array.isArray(rle)) return false
const cells = new Set<number>()
for (const row of rle) {
if (!Array.isArray(row) || row.length < 3) continue
const cy = row[0]
if (!isInt(cy) || cy < 0 || cy >= state.rows) continue
for (let i = 1; i + 1 < row.length; i += 2) {
const x0 = row[i]
const len = row[i + 1]
if (!isInt(x0) || !isInt(len) || len <= 0) continue
const end = Math.min(state.cols, x0 + len)
for (let cx = Math.max(0, x0); cx < end; cx++) cells.add(cy * state.cols + cx)
}
}
state.cells = cells
state.fresh = [...cells]
state.snapshot = true
state.exploredVersion += 1
return true
}
/** `explored {full:false, cells:[[cx, cy], ...]}` (DESIGN 6.1): monotone additions only. */
function applyFresh(state: FogState, list: unknown): boolean {
if (!Array.isArray(list)) return false
const fresh: number[] = []
for (const entry of list) {
if (!isVec2(entry)) continue
const [cx, cy] = entry
if (cx < 0 || cy < 0 || cx >= state.cols || cy >= state.rows) continue
const index = cy * state.cols + cx
if (state.cells.has(index)) continue
state.cells.add(index)
fresh.push(index)
}
state.fresh = fresh
state.snapshot = false
if (fresh.length > 0) state.exploredVersion += 1
return true
}
/** `vision {polys:[{id, pts:[[x,y],...]}]}` (DESIGN 6.1). Malformed polygons are dropped whole. */
function applyVision(state: FogState, polys: unknown): boolean {
if (!Array.isArray(polys)) return false
const next: VisionPoly[] = []
for (const entry of polys) {
if (!isRecord(entry)) continue
const id = entry['id']
const pts = entry['pts']
if (typeof id !== 'string' || !Array.isArray(pts)) continue
if (pts.length < 3 || !pts.every(isVec2)) continue
next.push({ id, pts: pts as Vec2[] })
}
state.polys = next
state.visionVersion += 1
return true
}
/** `marker {full, set:[{id,pos}], del:[id]}` (DESIGN 6.1). A full frame replaces; a diff retracts. */
function applyMarkers(state: FogState, frame: ServerFrame): boolean {
const set = frame['set']
if (!Array.isArray(set)) return false
const full = frame['full'] === true
const next: Record<string, Vec2> = full ? {} : { ...state.markers }
let changed = full
for (const entry of set) {
if (!isRecord(entry)) continue
const id = entry['id']
const pos = entry['pos']
if (typeof id !== 'string' || !isVec2(pos)) continue
const before = next[id]
if (!before || before[0] !== pos[0] || before[1] !== pos[1]) changed = true
next[id] = [pos[0], pos[1]]
}
if (!full) {
const del = frame['del']
if (Array.isArray(del)) {
for (const id of del) {
if (typeof id !== 'string' || next[id] === undefined) continue
delete next[id]
changed = true
}
}
}
state.markers = next
if (changed) state.markerVersion += 1
return true
}
export const slice: Slice<FogState> = {
name: 'fog',
init: emptyFog,
reduce(state: FogState, event: ReducerEvent, root: RootState): void {
if (event.type !== 'frame') return
const frame = event.frame
switch (frame.t) {
case 'hello': {
// `hello` already reset the slice; the scene (set before the slice loop runs) gives the grid.
const grid = gridOf(root.session.scene)
state.cols = grid.cols
state.rows = grid.rows
state.cell = grid.cell
state.sceneId = root.session.scene?.id ?? null
return
}
case 'explored':
if (state.cols === 0) return
if (frame['full'] === true) applyFull(state, frame['rle'])
else applyFresh(state, frame['cells'])
return
case 'vision':
applyVision(state, frame['polys'])
return
case 'marker':
applyMarkers(state, frame)
return
}
},
}
/** The fog slice of a root state (always registered, always present after `initialState`). */
export function fogOf(state: RootState): FogState {
const fog = state.slices['fog'] as FogState | undefined
return fog ?? emptyFog()
}
+45 -1
View File
@@ -9,7 +9,12 @@
// - a `403`/`404` is a permanent `denied` answer: never retried in a loop (the server said no);
// - a transient `error` is retried only when a later viewport sync asks for the tile again;
// - queued tiles that leave the viewport before they start are dropped, so a fast pan never
// prefetches beyond the margin.
// prefetches beyond the margin;
// - a denied tile is asked again only when the fog says its cells just became explored (#70):
// the gate's answer changed, so the old "no" is stale.
import type { SceneInfo } from './protocol.ts'
import { tileUrl } from './viewport.ts'
export const TILE_CONCURRENCY = 8
@@ -29,6 +34,28 @@ function sameList(a: readonly string[], b: readonly string[]): boolean {
return true
}
/**
* The tile urls touched by a set of explored cells (fog slice indices, row-major). v1 has
* `cell == tile_size` (DESIGN 8), but the maths keeps a cell-to-tile mapping general.
*/
export function tilesForCells(
scene: Pick<SceneInfo, 'id' | 'art_version' | 'tile_size'>,
grid: { cols: number; cell: number },
cells: Iterable<number>,
): string[] {
const tileSize = scene.tile_size
if (!(tileSize > 0) || grid.cell <= 0 || grid.cols <= 0) return []
const urls = new Set<string>()
for (const index of cells) {
const cx = index % grid.cols
const cy = (index / grid.cols) | 0
const tx = Math.floor((cx * grid.cell) / tileSize)
const ty = Math.floor((cy * grid.cell) / tileSize)
urls.add(tileUrl(scene, tx, ty))
}
return [...urls]
}
export class TileScheduler {
readonly #load: (url: string) => Promise<TileLoadResult>
readonly #onSettled: ((url: string, result: TileLoadResult) => void) | undefined
@@ -96,6 +123,23 @@ export class TileScheduler {
this.#lastDesired = []
}
/**
* A `403` is permanent *for the explored set the server had then*. When the fog slice reports
* newly explored cells (#70), the tiles those cells touch may have become allowed, so those
* denied urls are forgotten and the next `setDesired` asks for them exactly once more. Nothing
* else is retried: an unexplored 403 stays denied (no retry loop).
*/
retryDenied(urls: Iterable<string>): void {
let changed = false
for (const url of urls) {
if (this.#states.get(url) !== 'denied') continue
this.#states.delete(url)
changed = true
}
// The next setDesired rebuilds the queue, which re-queues the forgotten urls as `queued`.
if (changed) this.#lastDesired = []
}
/** True when every wanted tile settled with an `ok` or `denied` answer. */
isComplete(urls: readonly string[]): boolean {
return urls.every(url => {