depressions filling controls UI

This commit is contained in:
Azgaar 2021-06-25 22:27:09 +03:00
parent e6099f62dd
commit d6aac8d12c
5 changed files with 43 additions and 23 deletions

View file

@ -1358,10 +1358,21 @@
<input id="renderOcean" class="checkbox" type="checkbox">
<label for="renderOcean" class="checkbox-label">Render ocean cells</label>
</div>
<div id="allowErosionBox" data-tip="Regenerate rivers and allow water flow to change heights and form lakes">
<div id="allowErosionBox" data-tip="Regenerate rivers and allow water flow to change heights and form new lakes. Better to keep checked">
<input id="allowErosion" class="checkbox" type="checkbox" checked>
<label for="allowErosion" class="checkbox-label">Allow water erosion</label>
</div>
<div data-tip="Maximum number of iterations taken to resolve depressions. Increase if you have rivers ending nowhere">
Depressions filling max iterations:
<input id="resolveDepressionsStepsInput" data-stored="resolveDepressionsSteps" type="range" min=0 max=500 value=250 oninput="resolveDepressionsStepsOutput.value = this.value">
<input id="resolveDepressionsStepsOutput" data-stored="resolveDepressionsSteps" type="number" min=0 max=1000 value=250 oninput="resolveDepressionsStepsInput.value = this.value">
</div>
<div data-tip="Depression depth to form a new lake. Increase to reduce number of lakes added by system">
Depression depth threshold:
<input id="lakeElevationLimitInput" data-stored="lakeElevationLimit" type="range" min=0 max=80 value=20 oninput="lakeElevationLimitOutput.value = this.value">
<input id="lakeElevationLimitOutput" data-stored="lakeElevationLimit" type="number" min=0 max=80 value=20 oninput="lakeElevationLimitInput.value = this.value">
</div>
</div>
<div>

21
main.js
View file

@ -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

View file

@ -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]];

View file

@ -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) {

View file

@ -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;