/** * 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 960 columns wide however * big the window is, and blitted up; the HUD, the crosshair and the minimap * stay on the visible canvas at full resolution, where sharpness actually * shows. Fidelity is cheap here and frame rate is not: this game can be * stick figures if that is what runs. * * The ladder is the knob the frame governor turns: a rung coarser is about a * fifth fewer rays, and the rungs are in order of what they cost, so going * down one can never cost more. Nothing here touches what is sent, predicted * or simulated — it is a count of columns out of a canvas size and a level. */ /** Internal widths, finest first. The first rung is what every window gets. */ export const WIDTHS = [960, 800, 672, 544, 448]; 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 }; }