mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-16 17:31:24 +01:00
v 0.8.26b
This commit is contained in:
parent
46fb2fb1f8
commit
54ec78af54
4 changed files with 32 additions and 5 deletions
|
|
@ -8,6 +8,7 @@
|
|||
console.time('generateRivers');
|
||||
Math.seedrandom(seed);
|
||||
const cells = pack.cells, p = cells.p, features = pack.features;
|
||||
resolveDepressions();
|
||||
features.forEach(f => {delete f.river; delete f.flux;});
|
||||
|
||||
const riversData = []; // rivers data
|
||||
|
|
@ -18,7 +19,7 @@
|
|||
|
||||
void function drainWater() {
|
||||
const land = cells.i.filter(isLand).sort(highest);
|
||||
|
||||
|
||||
land.forEach(function(i) {
|
||||
cells.fl[i] += grid.cells.prec[cells.g[i]]; // flux from precipitation
|
||||
const x = p[i][0], y = p[i][1];
|
||||
|
|
@ -110,6 +111,27 @@
|
|||
console.timeEnd('generateRivers');
|
||||
}
|
||||
|
||||
// depression filling algorithm (for a correct water flux modeling)
|
||||
function resolveDepressions() {
|
||||
console.time('resolveDepressions');
|
||||
const cells = pack.cells;
|
||||
const land = cells.i.filter(i => cells.h[i] >= 20 && cells.h[i] < 95 && !cells.b[i]); // exclude near-border cells
|
||||
land.sort(highest); // highest cells go first
|
||||
|
||||
for (let l = 0, depression = Infinity; depression > 1 && l < 100; l++) {
|
||||
depression = 0;
|
||||
for (const i of land) {
|
||||
const minHeight = d3.min(cells.c[i].map(c => cells.h[c]));
|
||||
if (minHeight === 100) continue; // already max height
|
||||
if (cells.h[i] <= minHeight) {cells.h[i] = minHeight + 1; depression++;}
|
||||
}
|
||||
}
|
||||
|
||||
console.timeEnd('resolveDepressions');
|
||||
//const depressed = cells.i.filter(i => cells.h[i] >= 20 && cells.h[i] < 95 && !cells.b[i] && cells.h[i] <= d3.min(cells.c[i].map(c => cells.h[c])));
|
||||
//debug.selectAll(".deps").data(depressed).enter().append("circle").attr("r", 0.8).attr("cx", d => cells.p[d][0]).attr("cy", d => cells.p[d][1]);
|
||||
}
|
||||
|
||||
// add more river points on 1/3 and 2/3 of length
|
||||
const addMeandring = function(segments, rndFactor = 0.3) {
|
||||
const riverEnhanced = []; // to store enhanced segments
|
||||
|
|
|
|||
|
|
@ -143,9 +143,8 @@ function editHeightmap() {
|
|||
drawCoastline();
|
||||
|
||||
elevateLakes();
|
||||
resolveDepressions();
|
||||
Rivers.generate();
|
||||
|
||||
|
||||
if (!change) {
|
||||
for (const i of pack.cells.i) {
|
||||
const g = pack.cells.g[i];
|
||||
|
|
@ -219,7 +218,6 @@ function editHeightmap() {
|
|||
|
||||
if (change) {
|
||||
elevateLakes();
|
||||
resolveDepressions();
|
||||
Rivers.generate();
|
||||
defineBiomes();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,12 @@ toolsContent.addEventListener("click", function(event) {
|
|||
if (button === "regenerateStateLabels") {BurgsAndStates.drawStateLabels(); if (!layerIsOn("toggleLabels")) toggleLabels();} else
|
||||
if (button === "regenerateReliefIcons") {ReliefIcons(); if (!layerIsOn("toggleRelief")) toggleRelief();} else
|
||||
if (button === "regenerateRoutes") {Routes.regenerate(); if (!layerIsOn("toggleRoutes")) toggleRoutes();} else
|
||||
if (button === "regenerateRivers") {Rivers.generate(); if (!layerIsOn("toggleRivers")) toggleRivers();} else
|
||||
if (button === "regenerateRivers") {
|
||||
const heights = new Uint8Array(pack.cells.h);
|
||||
Rivers.generate();
|
||||
pack.cells.h = new Uint8Array(heights);
|
||||
if (!layerIsOn("toggleRivers")) toggleRivers();
|
||||
} else
|
||||
if (button === "regeneratePopulation") recalculatePopulation();
|
||||
|
||||
// Click to Add buttons
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ function editWorld() {
|
|||
calculateTemperatures();
|
||||
generatePrecipitation();
|
||||
elevateLakes();
|
||||
const heights = new Uint8Array(pack.cells.h);
|
||||
Rivers.generate();
|
||||
pack.cells.h = new Uint8Array(heights);
|
||||
defineBiomes();
|
||||
|
||||
if (layerIsOn("toggleTemp")) drawTemp();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue