Faster roof scan and heat pass with identical results (t21)

- The roof is rescanned only in area columns that changed since the last scan: a quiet Huge
  world goes from 4.60 to 1.88 ms per scan (every 20 ticks).
- The heat pass skips react() for solids and powders below their first reaction threshold:
  Huge world digging 2.54 -> 2.34 ms/tick, quiet 1.39 -> 1.18.
- Every suite's output is identical apart from timing lines; seeds make the same worlds.
- test/t_sim_optimizations.js checks the dirty roof against a full scan and the heat loop
  against the reference loop byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 22:18:50 -04:00
co-authored by Claude Opus 5.5
parent cce81e4eca
commit 9937683a2c
9 changed files with 160 additions and 11 deletions
+4 -1
View File
@@ -13,7 +13,7 @@ let ents = []; // loose objects (bars)
let bgm; // background layer: trees. Liquids, powders and gases pass in front of it.
let flyers = []; // grains in flight, blown out of the bot
let ghostBlocks = new Map(), ghostMolds = [];
let awake, hot, hotLvl, powderArea;
let awake, hot, hotLvl, powderArea, roofDirty;
let tick = 0, tickStamp = 1;
let machines = [null], molds = [], nets = [null], pcells = new Set(), powerDirty = true;
let beltL = [], beltR = [], tubeLists = [[], [], [], [], []];
@@ -50,6 +50,7 @@ function alloc(w, h) {
surfY = new Int16Array(w); roofY = new Int16Array(w); dirtY = new Int16Array(w); graniteY = new Int16Array(w); basaltY = new Int16Array(w); magmaY = new Int16Array(w);
AMB = new Float32Array(h);
awake = new Uint8Array(NCH); hot = new Uint8Array(NCH); hotLvl = new Uint8Array(NCH);
roofDirty = new Uint8Array(CW).fill(1);
powderArea = new Uint8Array(NCH).fill(1); // unknown areas get one visit before being ruled out
machines = [null]; molds = []; nets = [null]; pcells = new Set(); powerDirty = true;
beltL = []; beltR = []; tubeLists = [[], [], [], [], []]; brokenMachines = [];
@@ -85,6 +86,7 @@ function fillNoise() {
// ---------- Waking ----------
function wakeXY(x, y) {
const cx = x >> 5, cy = y >> 5, c = cy * CW + cx;
roofDirty[cx] = 1;
awake[c] = 3;
const lx = x & 31, ly = y & 31;
if (lx === 0) { if (cx > 0) awake[c - 1] = 3; } else if (lx === 31 && cx < CW - 1) awake[c + 1] = 3;
@@ -92,6 +94,7 @@ function wakeXY(x, y) {
}
function wakeHeatXY(x, y) {
const c = (y >> 5) * CW + (x >> 5);
roofDirty[x >> 5] = 1;
hot[c] = 6; hotLvl[c] = 2;
}
function wakeIdx(i) { wakeXY(i % W, (i / W) | 0); }