/** * How big the world is drawn, before it is scaled onto the screen. * * A raycaster does not need device pixels. Every column is a ray marched * through the grid, so the cost of the frame is the width of the canvas, and * a retina window asks for three thousand of them — 1512 rays and as many * fills at every frame, sixty times a second, for a picture made of flat * shaded columns that upscales almost invisibly. * * So the world is drawn into an offscreen canvas of a fixed width and * blitted up, and the HUD, the crosshair and the minimap stay on the visible * canvas at full resolution, where sharpness actually shows. * * The ladder is the knob the frame governor turns: one step coarser is one * step fewer rays. Nothing here touches what is sent, predicted or * simulated — it is a choice of how many columns to draw, out of the window * size and a level, and nothing else. */ /** Internal widths, finest first. A step is about a fifth of the rays. */ export const WIDTHS = [1280, 1080, 960, 800, 672, 544, 448]; /** The finest level a window of this many CSS pixels across starts at. */ export const startLevel = (cssWidth) => (cssWidth >= 1200 ? 0 : 2); const clamp = (n, low, high) => (n < low ? low : n > high ? high : n); /** * The size to draw the world at: never wider than the canvas actually has * pixels for — upscaling a 448px render onto a 360px phone would be paying * for columns nobody can see — and never so small it stops being a picture. * The aspect is the canvas's own, so the blit only ever scales. */ export function renderSize(deviceWidth, deviceHeight, level) { const want = WIDTHS[clamp(level | 0, 0, WIDTHS.length - 1)]; const width = Math.max(240, Math.min(want, Math.round(deviceWidth) || 240)); const height = Math.max( 1, Math.round(width * (deviceHeight > 0 && deviceWidth > 0 ? deviceHeight / deviceWidth : 0.6)), ); return { width, height }; }