mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-05 12:24:25 +01:00
Heatmap rasters (LOFAR/BTR/DEMON waterfalls) are packed into typed-array jobs and painted by a module worker into an OffscreenCanvas, which hands back an ImageBitmap. The main thread keeps drawing the previous bitmap at its anchor until the new one arrives, keeps one job in flight per plot and falls back to the shared synchronous painter when Worker/OffscreenCanvas is missing or the worker fails. Headless Chrome stays on the synchronous path unless opted in, because workers stall its virtual time. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AS36Eg72iLviiSVbCUVNAi
30 lines
1.2 KiB
JavaScript
30 lines
1.2 KiB
JavaScript
// Module worker: paints waterfall rasters into an OffscreenCanvas and hands
|
|
// the finished bitmap back, so the page's main thread (and the live-sonar
|
|
// audio scheduler on it) never runs the per-cell loop.
|
|
import { paintHeatmap } from "./heatmap-paint.js";
|
|
|
|
const MAX_SURFACES = 16;
|
|
const surfaces = new Map();
|
|
|
|
function surfaceFor(id, width, height) {
|
|
let surface = surfaces.get(id);
|
|
if (surface && surface.canvas.width === width && surface.canvas.height === height) return surface;
|
|
const canvas = new OffscreenCanvas(width, height);
|
|
const context = canvas.getContext("2d");
|
|
const image = context.createImageData(width, height);
|
|
surface = {canvas, context, image, pixels: new Uint32Array(image.data.buffer)};
|
|
surfaces.delete(id);
|
|
surfaces.set(id, surface);
|
|
if (surfaces.size > MAX_SURFACES) surfaces.delete(surfaces.keys().next().value);
|
|
return surface;
|
|
}
|
|
|
|
self.onmessage = ({data}) => {
|
|
const {id, seq, job} = data;
|
|
const surface = surfaceFor(id, job.width, job.rasterHeight);
|
|
paintHeatmap(surface.pixels, job);
|
|
surface.context.putImageData(surface.image, 0, 0);
|
|
const bitmap = surface.canvas.transferToImageBitmap();
|
|
self.postMessage({id, seq, bitmap, anchor: job.anchor}, [bitmap]);
|
|
};
|