Throughput in the info overlay: grains per second and backing-up glow (t49)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 16:21:48 -04:00
co-authored by Claude Opus 5.5
parent 54e7756ead
commit 9fc1b92080
14 changed files with 131 additions and 16 deletions
+34
View File
@@ -75,6 +75,40 @@ function drawJoinMarks() {
for (let end = 0; end < 2; end++) if (nearMiss(bx, by, end, ghostBlocks.size ? ghostBlocks : null)) drawJoinMark(bx, by, end, code, vv);
}
}
// Throughput (t49, info overlay): grains per second at the open outlet end of every line, and
// an orange glow on transport blocks that are loaded but not moving, where a line backs up.
function flowLoaded(b, code) {
const bx = b % BW, by = (b / BW) | 0;
let n = 0;
for (let k = 0; k < BS; k++) {
const x = bx * BS + k, i = code === BP_SCREW ? (by * BS + 1) * W + x : (beltFaceY(code, bx, by, x) - 1) * W + x;
if (i >= 0 && i < N && PH[mat[i]] === PH_POWDER) n++;
}
return n >= 3;
}
function drawFlowRates() {
const ctx = R.ctx, v = viewCells(), s = BS * R.zp;
const bx0 = Math.max(0, Math.floor(R.camX / BS)), bx1 = Math.min(BW - 1, Math.floor((R.camX + v.w) / BS));
const by0 = Math.max(0, Math.floor(R.camY / BS)), by1 = Math.min(BH - 1, Math.floor((R.camY + v.h) / BS));
ctx.save();
ctx.font = `600 ${Math.max(10, Math.min(14, s * 0.45))}px ui-monospace, monospace`; ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
for (let by = by0; by <= by1; by++) for (let bx = bx0; bx <= bx1; bx++) {
const b = by * BW + bx, code = blockP[b], ends = pieceEnds(code, blockV[b]);
if (!ends.length) continue;
const rate = flowRate[b] || 0;
if (rate < 0.5 && flowLoaded(b, code)) {
const p = worldToScreenPx(bx * BS, by * BS);
ctx.fillStyle = 'rgba(255,150,60,0.32)'; ctx.fillRect(p.x, p.y, s, s);
}
const out = ends[1].outlet ? 1 : 0;
if (endJoin(bx, by, out) >= 0) continue;
const e = ends[out], c = worldToScreenPx(bx * BS + BS / 2 + e.dx * BS * 0.95, by * BS + BS / 2 + e.dy * BS * 0.95 - (e.dy ? 0 : BS * 0.9));
const label = rate >= 10 ? `${Math.round(rate)}/s` : `${rate.toFixed(1)}/s`, tw = ctx.measureText(label).width;
ctx.fillStyle = 'rgba(14,12,11,0.8)'; ctx.fillRect(c.x - tw / 2 - 4, c.y - 9, tw + 8, 18);
ctx.fillStyle = rate > 0 ? '#e7dccb' : '#ef9a6a'; ctx.fillText(label, c.x, c.y + 1);
}
ctx.restore();
}
// Outline a run of blocks: strong while it is being edited, faint when pointed at
function drawRunOutline(run, strong) {
if (!run || !run.length) return;