detect depressions on river flow and return

This commit is contained in:
Azgaar 2021-06-08 23:32:46 +03:00
parent 05e6cc388e
commit e7cf6e4f5a

View file

@ -6,9 +6,8 @@
const generate = function (allowErosion = true) { const generate = function (allowErosion = true) {
TIME && console.time("generateRivers"); TIME && console.time("generateRivers");
Math.random = aleaPRNG(seed); Math.random = aleaPRNG(seed);
const cells = pack.cells, const {cells, features} = pack;
p = cells.p, const p = cells.p;
features = pack.features;
const riversData = []; // rivers data const riversData = []; // rivers data
cells.fl = new Uint16Array(cells.i.length); // water flux array cells.fl = new Uint16Array(cells.i.length); // water flux array
@ -93,7 +92,11 @@
} }
// downhill cell (make sure it's not in the source lake) // downhill cell (make sure it's not in the source lake)
const min = lakeOutCells[i] ? cells.c[i].filter(c => !lakes.map(lake => lake.i).includes(cells.f[c])).sort((a, b) => h[a] - h[b])[0] : cells.c[i].sort((a, b) => h[a] - h[b])[0]; const filtered = lakeOutCells[i] ? cells.c[i].filter(c => !lakes.map(lake => lake.i).includes(cells.f[c])) : cells.c[i];
const min = filtered.sort((a, b) => h[a] - h[b])[0];
// cells is depressed
if (h[i] <= h[min]) return;
if (cells.fl[i] < MIN_FLUX_TO_FORM_RIVER) { if (cells.fl[i] < MIN_FLUX_TO_FORM_RIVER) {
if (h[min] >= 20) cells.fl[min] += cells.fl[i]; if (h[min] >= 20) cells.fl[min] += cells.fl[i];
@ -244,10 +247,7 @@
prevDepressions = depressions; prevDepressions = depressions;
} }
console.log(iteration); depressions && WARN && console.warn(`Unresolved depressions: ${depressions}. Edit heightmap to fix`);
if (!depressions) return;
WARN && console.warn(`Unresolved depressions: ${depressions}. Edit heightmap to fix`);
}; };
// add more river points on 1/3 and 2/3 of length // add more river points on 1/3 and 2/3 of length