mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
depressions filling controls UI
This commit is contained in:
parent
e6099f62dd
commit
d6aac8d12c
5 changed files with 43 additions and 23 deletions
|
|
@ -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]];
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue