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:
@@ -2,7 +2,7 @@
|
||||
// 8, a decoded-texture cache the tile module keeps across reconnect, no duplicate in-flight fetch,
|
||||
// and a denied tile (403/404) is remembered so the client never retries it in a loop.
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { TILE_CONCURRENCY, TileScheduler } from '../src/tiles.ts'
|
||||
import { TILE_CONCURRENCY, TileScheduler, tilesForCells } from '../src/tiles.ts'
|
||||
import type { TileLoadResult } from '../src/tiles.ts'
|
||||
|
||||
interface Harness {
|
||||
@@ -170,3 +170,42 @@ describe('TileScheduler', () => {
|
||||
expect(h.calls).toEqual([list[0], list[0]])
|
||||
})
|
||||
})
|
||||
|
||||
describe('fog-driven denied retry (#70)', () => {
|
||||
it('re-asks a denied tile exactly once after its cells became explored', async () => {
|
||||
const h = harness()
|
||||
const list = urls(2)
|
||||
h.scheduler.setDesired(list)
|
||||
h.settle(list[0] as string, 'denied')
|
||||
h.settle(list[1] as string, 'ok')
|
||||
await flush()
|
||||
expect(h.calls).toEqual(list)
|
||||
|
||||
// The fog says cells under the first tile became explored: only that denied tile is stale.
|
||||
h.scheduler.retryDenied([list[0] as string])
|
||||
h.scheduler.setDesired(list)
|
||||
expect(h.calls).toEqual([...list, list[0]])
|
||||
h.settleAll('ok')
|
||||
await flush()
|
||||
|
||||
// A plain re-sync (no new cells) must not ask again: the denial is still remembered.
|
||||
h.scheduler.setDesired(list)
|
||||
h.scheduler.retryDenied([])
|
||||
h.scheduler.setDesired(list)
|
||||
expect(h.calls).toEqual([...list, list[0]])
|
||||
})
|
||||
|
||||
it('maps explored cells to the tiles they touch', () => {
|
||||
const scene = { id: 3, art_version: 7, tile_size: 32 }
|
||||
const grid = { cols: 4, cell: 32 }
|
||||
// Cells (1,0) -> tile (1,0), (1,1) -> tile (1,1), (3,1) -> tile (3,1).
|
||||
expect(tilesForCells(scene, grid, [1, 5, 7])).toEqual([
|
||||
'/tiles/3/v7/1_0.png',
|
||||
'/tiles/3/v7/1_1.png',
|
||||
'/tiles/3/v7/3_1.png',
|
||||
])
|
||||
// Two cells in one tile are one url; a smaller cell than a tile still maps correctly.
|
||||
expect(tilesForCells(scene, { cols: 16, cell: 8 }, [0, 1, 2])).toEqual(['/tiles/3/v7/0_0.png'])
|
||||
expect(tilesForCells(scene, { cols: 0, cell: 0 }, [1])).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user