Loading src/index.ts +10 −2 Original line number Diff line number Diff line Loading @@ -6,9 +6,17 @@ import { spawnWorkers, } from "./worker"; import { client } from "./lib/postgres"; import fs from "node:fs"; import "./lib/check_env"; if (fs.existsSync("frames")) { console.error("/frames/ exists, exiting"); process.exit(1); } fs.mkdirSync("frames"); const MS_PER_FRAME = parseInt(process.env.MS_PER_FRAME); client.connect().then(async () => { Loading Loading @@ -45,7 +53,7 @@ client.connect().then(async () => { const SCRIPT_START = Date.now(); const start = startDate.getTime(); const end = endDate.getTime(); const end = endDate.getTime() + 1; // +1 so the last event isn't excluded by strict < const framesPerWorker = Math.floor((end - start) / (WORKER_COUNT - 1)); const frameStartIncrement = Math.floor(framesPerWorker / MS_PER_FRAME); const framesToGenerate = Math.floor((end - start) / MS_PER_FRAME); Loading @@ -68,7 +76,7 @@ client.connect().then(async () => { type: "assignment", frameStart, start: time, end: time + framesPerWorker, end: Math.min(time + framesPerWorker, end), step: MS_PER_FRAME, }); workerNumber++; Loading src/render_worker.ts +12 −6 Original line number Diff line number Diff line Loading @@ -140,12 +140,18 @@ parentPort?.on("message", (msg: Message) => { nextPixels = getPixelsAsLog(nextTime, nextTime + msg.step); } // Encode current canvas state to PNG and write if (pixels.length > 0) { const data = await canvas.encode("png"); await fs.promises.writeFile( `./frames/${frameFilename(index)}.png`, data as Uint8Array, ); } else { await fs.promises.copyFile( `./frames/${frameFilename(index - 1)}.png`, `./frames/${frameFilename(index)}.png`, ); } parentPort?.postMessage({ type: "progress", Loading Loading
src/index.ts +10 −2 Original line number Diff line number Diff line Loading @@ -6,9 +6,17 @@ import { spawnWorkers, } from "./worker"; import { client } from "./lib/postgres"; import fs from "node:fs"; import "./lib/check_env"; if (fs.existsSync("frames")) { console.error("/frames/ exists, exiting"); process.exit(1); } fs.mkdirSync("frames"); const MS_PER_FRAME = parseInt(process.env.MS_PER_FRAME); client.connect().then(async () => { Loading Loading @@ -45,7 +53,7 @@ client.connect().then(async () => { const SCRIPT_START = Date.now(); const start = startDate.getTime(); const end = endDate.getTime(); const end = endDate.getTime() + 1; // +1 so the last event isn't excluded by strict < const framesPerWorker = Math.floor((end - start) / (WORKER_COUNT - 1)); const frameStartIncrement = Math.floor(framesPerWorker / MS_PER_FRAME); const framesToGenerate = Math.floor((end - start) / MS_PER_FRAME); Loading @@ -68,7 +76,7 @@ client.connect().then(async () => { type: "assignment", frameStart, start: time, end: time + framesPerWorker, end: Math.min(time + framesPerWorker, end), step: MS_PER_FRAME, }); workerNumber++; Loading
src/render_worker.ts +12 −6 Original line number Diff line number Diff line Loading @@ -140,12 +140,18 @@ parentPort?.on("message", (msg: Message) => { nextPixels = getPixelsAsLog(nextTime, nextTime + msg.step); } // Encode current canvas state to PNG and write if (pixels.length > 0) { const data = await canvas.encode("png"); await fs.promises.writeFile( `./frames/${frameFilename(index)}.png`, data as Uint8Array, ); } else { await fs.promises.copyFile( `./frames/${frameFilename(index - 1)}.png`, `./frames/${frameFilename(index)}.png`, ); } parentPort?.postMessage({ type: "progress", Loading