diff --git a/index.html b/index.html index 4df5a7c1..33c29a5a 100644 --- a/index.html +++ b/index.html @@ -1358,10 +1358,21 @@ -
+
+
+ Depressions filling max iterations: + + +
+ +
+ Depression depth threshold: + + +
diff --git a/main.js b/main.js index 23617a39..0abcf164 100644 --- a/main.js +++ b/main.js @@ -774,9 +774,10 @@ function markup(cells, start, increment, limit) { function addLakesInDeepDepressions() { console.time("addLakesInDeepDepressions"); - const {cells, features, points} = grid; + const {cells, features} = grid; const {c, h, b} = cells; - const ELEVATION_LIMIT = 10; + const ELEVATION_LIMIT = +document.getElementById("lakeElevationLimitOutput").value; + if (ELEVATION_LIMIT === 80) return; for (const i of cells.i) { if (b[i] || h[i] < 20) continue; @@ -785,7 +786,7 @@ function addLakesInDeepDepressions() { if (h[i] > minHeight) continue; let deep = true; - const treshold = h[i] + ELEVATION_LIMIT; + const threshold = h[i] + ELEVATION_LIMIT; const queue = [i]; const checked = []; checked[i] = true; @@ -796,7 +797,7 @@ function addLakesInDeepDepressions() { for (const n of c[q]) { if (checked[n]) continue; - if (h[n] >= treshold) continue; + if (h[n] >= threshold) continue; if (h[n] < 20) { deep = false; break; @@ -830,7 +831,7 @@ function addLakesInDeepDepressions() { console.timeEnd("addLakesInDeepDepressions"); } -// near sea lakes usually get a lot of water inflow, most of them should brake treshold and flow out to sea (see Ancylus Lake) +// near sea lakes usually get a lot of water inflow, most of them should brake threshold and flow out to sea (see Ancylus Lake) function openNearSeaLakes() { if (templateInput.value === "Atoll") return; // no need for Atolls @@ -856,11 +857,11 @@ function openNearSeaLakes() { } } - function removeLake(treshold, lake, ocean) { - cells.h[treshold] = 19; - cells.t[treshold] = -1; - cells.f[treshold] = ocean; - cells.c[treshold].forEach(function (c) { + function removeLake(threshold, lake, ocean) { + cells.h[threshold] = 19; + cells.t[threshold] = -1; + cells.f[threshold] = ocean; + cells.c[threshold].forEach(function (c) { if (cells.h[c] >= 20) cells.t[c] = 1; // mark as coastline }); features[lake].type = "ocean"; // mark former lake as ocean diff --git a/modules/lakes.js b/modules/lakes.js index 261fd485..d127c2cf 100644 --- a/modules/lakes.js +++ b/modules/lakes.js @@ -39,7 +39,7 @@ const prepareLakeData = h => { const cells = pack.cells; - const ELEVATION_LIMIT = 10; + const ELEVATION_LIMIT = +document.getElementById("lakeElevationLimitOutput").value; pack.features.forEach(f => { if (f.type !== "lake") return; @@ -55,8 +55,13 @@ f.height = h[min] - 0.1; // check if lake can be open (not in deep depression) + if (ELEVATION_LIMIT === 80) { + f.closed = false; + return; + } + let deep = true; - const treshold = f.height + ELEVATION_LIMIT; + const threshold = f.height + ELEVATION_LIMIT; const queue = [min]; const checked = []; checked[min] = true; @@ -67,7 +72,7 @@ for (const n of cells.c[q]) { if (checked[n]) continue; - if (h[n] >= treshold) continue; + if (h[n] >= threshold) continue; if (h[n] < 20) { const nFeature = pack.features[cells.f[n]]; diff --git a/modules/river-generator.js b/modules/river-generator.js index 81f3457f..d34c0a0e 100644 --- a/modules/river-generator.js +++ b/modules/river-generator.js @@ -17,7 +17,7 @@ const h = alterHeights(); Lakes.prepareLakeData(h); - resolveDepressions(h, 200); + resolveDepressions(h); drainWater(); defineRivers(); Lakes.cleanupLakeData(); @@ -184,8 +184,12 @@ }; // depression filling algorithm (for a correct water flux modeling) - const resolveDepressions = function (h, maxIterations) { + const resolveDepressions = function (h) { const {cells, features} = pack; + const maxIterations = +document.getElementById("resolveDepressionsStepsOutput").value; + const checkLakeMaxIteration = maxIterations * 0.8; + const elevateLakeMaxIteration = (maxIterations - checkLakeMaxIteration) / 2; + const height = i => features[cells.f[i]].height || h[i]; // height of lake or specific cell const lakes = features.filter(f => f.type === "lake"); @@ -195,8 +199,7 @@ const progress = []; let depressions = Infinity; let prevDepressions = null; - let iteration = 0; - for (; depressions && iteration < maxIterations; iteration++) { + for (let iteration = 0; depressions && iteration < maxIterations; iteration++) { if (progress.length > 5 && d3.sum(progress) > 0) { // bad progress, abort and set heights back h = alterHeights(); @@ -206,13 +209,13 @@ depressions = 0; - if (iteration < 180) { + if (iteration < checkLakeMaxIteration) { for (const l of lakes) { if (l.closed) continue; const minHeight = d3.min(l.shoreline.map(s => h[s])); if (minHeight >= 100 || l.height > minHeight) continue; - if (iteration > 150) { + if (iteration < elevateLakeMaxIteration) { l.shoreline.forEach(i => (h[i] = cells.h[i])); l.height = d3.min(l.shoreline.map(s => h[s])) - 1; l.closed = true; @@ -342,8 +345,8 @@ const rivers = pack.rivers; if (!rivers.length) return; Math.random = aleaPRNG(seed); - const tresholdElement = Math.ceil(rivers.length * 0.15); - const smallLength = rivers.map(r => r.length || 0).sort((a, b) => a - b)[tresholdElement]; + const thresholdElement = Math.ceil(rivers.length * 0.15); + const smallLength = rivers.map(r => r.length || 0).sort((a, b) => a - b)[thresholdElement]; const smallType = {Creek: 9, River: 3, Brook: 3, Stream: 1}; // weighted small river types for (const r of rivers) { diff --git a/modules/ui/tools.js b/modules/ui/tools.js index 1a5dd1a1..4cc390bc 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -541,7 +541,7 @@ function addRiverOnClick() { const h = Rivers.alterHeights(); Lakes.prepareLakeData(h); - Rivers.resolveDepressions(h, 200); + Rivers.resolveDepressions(h); while (i) { cells.r[i] = river;