Progress bar and steps while generating, loading, opening claims and travelling; saving chip (t30)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+23
-5
@@ -60,7 +60,8 @@ function clearHardSpecks(live) {
|
||||
return n;
|
||||
}
|
||||
// ---------- World generation ----------
|
||||
function generateWorld(seedIn, w, h, onProgress) {
|
||||
function* worldSteps(seedIn, w, h) {
|
||||
yield [0, 'Shaping the land'];
|
||||
worldSeed = seedIn >>> 0;
|
||||
alloc(w, h);
|
||||
RS = (worldSeed ^ 0x9E3779B9) | 1;
|
||||
@@ -146,6 +147,7 @@ function generateWorld(seedIn, w, h, onProgress) {
|
||||
for (let x = Math.max(0, f.x - dw); x <= Math.min(w - 1, f.x + dw); x++) if (Math.abs(x - f.x) < dw - Math.abs(nDetail(x / 20, 3.3)) * 10) desAt[x] = 1;
|
||||
}
|
||||
computeAmbient();
|
||||
yield [0, 'Laying rock and ore'];
|
||||
for (let y = 0; y < h; y++) {
|
||||
const fy = depthU(y); // fraction of the underground depth (negative in the sky)
|
||||
for (let x = 0; x < w; x++) {
|
||||
@@ -231,9 +233,11 @@ function generateWorld(seedIn, w, h, onProgress) {
|
||||
temp[i] = m === MAGMA ? Math.max(AMB[y], 1180) : AMB[y];
|
||||
if (PH[m] === PH_LIQUID && FRZ[m]) life[i] = 255;
|
||||
}
|
||||
if (onProgress && (y & 63) === 0) onProgress(y / h * 0.7);
|
||||
if ((y & 63) === 0) yield [y / h * 0.7, 'Laying rock and ore'];
|
||||
}
|
||||
yield [0.7, 'Carving caves'];
|
||||
clearHardSpecks(false);
|
||||
yield [0.71, 'Snow and trees'];
|
||||
// (tree bases are collected after the trees below)
|
||||
// snow lies on the high ground wherever the air is below freezing
|
||||
for (let x = 1; x < w - 1; x++) {
|
||||
@@ -244,6 +248,7 @@ function generateWorld(seedIn, w, h, onProgress) {
|
||||
const depth = Math.abs(surfY[x + 1] - surfY[x - 1]) <= 3 ? 3 : 1;
|
||||
for (let k = 1; k <= depth; k++) { const i = (sy - k) * w + x; if (mat[i] === EMPTY) { mat[i] = SNOW; flags[i] = F_NAT; temp[i] = AMB[sy - k]; } }
|
||||
}
|
||||
yield [0.72, 'Snow and trees'];
|
||||
// trees
|
||||
for (let x = 12; x < w - 12;) {
|
||||
const sy = surfY[x];
|
||||
@@ -267,6 +272,7 @@ function generateWorld(seedIn, w, h, onProgress) {
|
||||
x += 16 + Math.floor(rng() * 20);
|
||||
} else x += 4;
|
||||
}
|
||||
yield [0.73, 'Springs and water'];
|
||||
// springs: in cave side walls just above the cave floor
|
||||
{
|
||||
const cands = [];
|
||||
@@ -296,7 +302,7 @@ function generateWorld(seedIn, w, h, onProgress) {
|
||||
void picks;
|
||||
}
|
||||
fillNoise();
|
||||
if (onProgress) onProgress(0.75);
|
||||
yield [0.75, 'Settling loose ground'];
|
||||
// settle loose material
|
||||
awake.fill(3);
|
||||
for (let k = 0; k < 260; k++) {
|
||||
@@ -304,8 +310,9 @@ function generateWorld(seedIn, w, h, onProgress) {
|
||||
simMove();
|
||||
let any = 0; for (let c = 0; c < NCH; c++) if (awake[c]) { awake[c]--; any++; }
|
||||
if (!any) break;
|
||||
if (onProgress && (k & 31) === 0) onProgress(0.75 + 0.25 * k / 260);
|
||||
if ((k & 31) === 0) yield [0.75 + 0.24 * k / 260, 'Settling loose ground'];
|
||||
}
|
||||
yield [0.99, 'Finishing'];
|
||||
// re-ambient after settling, then start clean
|
||||
for (let i = 0; i < N; i++) { const m = mat[i]; if (m !== MAGMA) temp[i] = AMB[(i / w) | 0]; life[i] = PH[m] === PH_LIQUID && FRZ[m] ? 255 : 0; }
|
||||
tick = 0;
|
||||
@@ -322,5 +329,16 @@ function generateWorld(seedIn, w, h, onProgress) {
|
||||
stats.dug = stats.moved = stats.placed = stats.ignitions = stats.cast = stats.bars = 0;
|
||||
EV.length = 0;
|
||||
fogInit(); fogLook(bot.x + bot.w / 2, bot.y + bot.h / 2);
|
||||
if (onProgress) onProgress(1);
|
||||
yield [1, 'Finishing'];
|
||||
}
|
||||
|
||||
function generateWorld(seedIn, w, h, onProgress) {
|
||||
for (const [f, label] of worldSteps(seedIn, w, h)) if (onProgress) onProgress(f, label);
|
||||
}
|
||||
async function generateWorldAsync(seedIn, w, h, onProgress) {
|
||||
let last = Date.now();
|
||||
for (const [f, label] of worldSteps(seedIn, w, h)) {
|
||||
if (onProgress) onProgress(f, label);
|
||||
if (Date.now() - last >= 30) { await new Promise(r => setTimeout(r, 0)); last = Date.now(); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user