// Exercise the published work ceilings with actual admitted inputs. Keep these fixtures pinned when a // ceiling rises so old and new implementations can still be compared on exactly the same work. import { example } from './bench-sources.mjs'; export function workSource(area) { if (area === 'fluid') { // 100 × 100 cells × 200 frames × 8 substeps × (15 pressure sweeps + 10 other updates). const source = example('campfire.fluid.json'); const effect = Object.values(source.effects)[0]; Object.assign(source, { width: 100, height: 100 }); Object.assign(effect, { frames: 200, loop: false, substeps: 8, iterations: 15 }); return source; } if (area === 'powder') { // A busy ordinary (drop) grid. The last of 100 sampled frames is tick 5,000. return { format: 'pixelforge-powder', version: 1, name: 'full-grid', base: 'sandbox', width: 200, height: 200, scene: [{ material: 'stone', rect: [0, 197, 200, 3] }, { material: 'sand', rect: [0, 0, 200, 85], fill: 0.45 }, { material: 'water', rect: [0, 40, 200, 125], replace: false }], clips: { fall: { frames: 100, every: 50, start: 50 } } }; } if (area === 'bodies') { // The meter includes crowd pairs, impulse iterations and each circle's swept picture. Its public // stats report 1,562,500 updates per frame at these dimensions. return { format: 'pixelforge-bodies', version: 1, name: 'full-crowd', width: 61, height: 52, palette: { y: '#ffdc40' }, effects: { fall: { frames: 256, substeps: 15, iterations: 14, gravity: [0, 0.08], walls: ['left', 'right', 'bottom'], bodies: [{ name: 'dot', shape: 'circle', radius: 0.5, at: [4, 3], grid: { count: [14, 18], step: [3, 2] }, fill: 'y' }] } } }; } if (area === 'fx') { // All 400 particles are alive for 200 frames. Thinning to eight delivered frames leaves the // simulation count unchanged and respects the separate 20,000 delivered-operation ceiling. return { format: 'pixelforge-fx', version: 1, name: 'full-burst', width: 40, height: 40, palette: { y: '#ffdc40' }, symbols: { dot: ['y'] }, effects: { glow: { frames: 200, loop: false, seed: 7, emitters: [{ name: 'lit', at: [20, 20], area: [16, 16], burst: 400, life: 200, speed: 0, shapes: ['dot'] }] } } }; } throw new Error('unrecognized work meter ' + area); } export function workCases() { const limits = { fluid: 400000000, bodies: 400000000, powder: 200000000, fx: 80000 }; const cases = Object.entries(limits).map(([area, limit]) => ({ id: area + '/work-' + limit, what: area + ' at its original ' + limit + ' work limit', area, size: 'work limit', runs: 1, warmup: 0, setup: async load => { const source = workSource(area), { COMPILERS } = await load('src/presets.js'); return { source, compile: COMPILERS[source.format] }; }, run: ({ compile, source }) => { const value = compile(source, area === 'fx' ? { frames: 8 } : area === 'bodies' ? { stats: true } : {}); if (area === 'bodies' && value.work.estimatedUpdates !== limit) throw new Error('body fixture meters ' + value.work.estimatedUpdates + ' updates'); if (area === 'fx' && value.metadata.effects.glow.operations !== limit) throw new Error('FX fixture must simulate ' + limit + ' operations'); return { frames: value.recipe.frames.length, value }; } })); cases.push({ id: 'fx/work-84000', area: 'fx', size: 'work limit', what: 'FX at its 84,000 simulated drawing-operation ceiling', runs: 1, warmup: 0, setup: async load => { const source = workSource('fx'); source.effects.glow.emitters[0].burst = 420; return { source, compile: (await load('src/fx.js')).compileEffects }; }, run: ({ compile, source }) => { const value = compile(source, { frames: 8 }); if (value.metadata.effects.glow.operations !== 84000) throw new Error('the burst must simulate 84,000 operations'); return { frames: value.recipe.frames.length, value }; }, previousLimit: error => error.name === 'PixelError' && error.path === 'fx.effects.glow' && error.message === "fx.effects.glow: the effect simulates all 200 of its frames, kept or not, and needs about 84,000 drawing operations (420 a frame) of the 80,000 a compile may simulate: lower burst, rate or trail, or the effect's frames (190 fit)" }); cases.push({ id: 'fx/cropped-particles', area: 'fx', what: '80,000 spinning particle stamps clipped at the canvas edge', runs: 1, warmup: 0, setup: async load => { const source = workSource('fx'); source.palette.b = '#5278ad'; source.symbols.dot = ['...yyy...', '..yyyyy..', '.byyyyyb.', 'byyyyyyyb', 'byyyyyyyb', 'byyyyyyyb', '.byyyyyb.', '..byyyb..', '...bbb...']; Object.assign(source.effects.glow.emitters[0], { at: [2, 14], area: [1, 3], angle: 90, spin: 10 }); return { compile: (await load('src/fx.js')).compileEffects, source }; }, run: ({ compile, source }) => { const value = compile(source, { frames: 8, stats: true }); if (value.metadata.effects.glow.operations !== 80000) throw new Error('the clipped burst must simulate 80,000 particles'); return { frames: value.recipe.frames.length, value }; } }); cases.push({ id: 'sequence/bodies-500000000', area: 'bodies at video resolution', size: 'work limit', what: '250 body frames drawn at 2000 × 1000, including every PNG', runs: 1, warmup: 0, setup: async load => { const source = example('bouncing-pixel.bodies.json'); Object.values(source.effects)[0].frames = 250; return { sequence: (await load('src/sequence.js')).createBodiesSequence, source }; }, run: ({ sequence, source }) => { const value = sequence(source, { fps: 25, size: [2000, 1000] }, { budget: 500000000 }); if (value.info.differentFrames !== 250) throw new Error('the sequence must deliver all 250 different frames'); return { frames: value.info.differentFrames, value }; } }); return cases; }