Spaces:
Running
Running
File size: 1,017 Bytes
49ef597 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | // node tools/run_headless.mjs [seconds] : run the mission without a page and print what happened (the smoke test).
import { readFileSync } from "node:fs";
import { loadModel } from "../core/model.js";
import { Mission } from "../core/mission.js";
const secs = +(process.argv[2] || 120);
const m = loadModel(JSON.parse(readFileSync(new URL("../core/model.json", import.meta.url))));
const mis = new Mission(m, 0);
let f, last = "";
const t0 = performance.now();
while (mis.t < secs) {
f = mis.step();
const ev = f.stats.events.at(-1);
if (ev && JSON.stringify(ev) !== last) { last = JSON.stringify(ev); console.log(`${ev.t.toFixed(1).padStart(6)} s ${ev.what}`); }
if (f.toys.every(t => t.state === "delivered")) break;
}
const wall = (performance.now() - t0) / 1000;
console.log(`\n${f.stats.delivered}/${f.toys.length} toys in ${f.t.toFixed(0)} s simulated, ${wall.toFixed(1)} s wall` +
` | ${f.stats.msPerPlan.toFixed(0)} ms per plan | furniture contact ticks ${f.stats.contacts} | phase ${f.phase}`);
|