mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-23 12:31:24 +01:00
fix:riverbed generation
This commit is contained in:
parent
aee8c974a1
commit
ecb367616d
2 changed files with 15 additions and 16 deletions
|
|
@ -31,10 +31,12 @@ window.Rivers = (function () {
|
||||||
TIME && console.timeEnd("generateRivers");
|
TIME && console.timeEnd("generateRivers");
|
||||||
|
|
||||||
function drainWater() {
|
function drainWater() {
|
||||||
const sqrpixel = distanceScale * distanceScale
|
const pixel2 = distanceScale * distanceScale
|
||||||
const MIN_FLUX_TO_FORM_RIVER = 10 * distanceScale;
|
//const MIN_FLUX_TO_FORM_RIVER = 10 * distanceScale;
|
||||||
|
const MIN_FLUX_TO_FORM_RIVER = 30;
|
||||||
const prec = grid.cells.prec;
|
const prec = grid.cells.prec;
|
||||||
const area = c => pack.cells.area[c] * sqrpixel;
|
// const area = c => pack.cells.area[c] * pixel2;
|
||||||
|
const area = pack.cells.area;
|
||||||
const land = cells.i.filter(i => h[i] >= 20).sort((a, b) => h[b] - h[a]);
|
const land = cells.i.filter(i => h[i] >= 20).sort((a, b) => h[b] - h[a]);
|
||||||
const lakeOutCells = Lakes.setClimateData(h);
|
const lakeOutCells = Lakes.setClimateData(h);
|
||||||
|
|
||||||
|
|
@ -167,7 +169,7 @@ window.Rivers = (function () {
|
||||||
const mouth = riverCells[riverCells.length - 2];
|
const mouth = riverCells[riverCells.length - 2];
|
||||||
const parent = riverParents[key] || 0;
|
const parent = riverParents[key] || 0;
|
||||||
|
|
||||||
const widthFactor = (!parent || parent === riverId ? 3.6 : 3) / distanceScale;
|
const widthFactor = (!parent || parent === riverId ? 1.2 : 1);
|
||||||
const meanderedPoints = addMeandering(riverCells);
|
const meanderedPoints = addMeandering(riverCells);
|
||||||
const discharge = cells.fl[mouth]; // m3 in second
|
const discharge = cells.fl[mouth]; // m3 in second
|
||||||
const length = getApproximateLength(meanderedPoints);
|
const length = getApproximateLength(meanderedPoints);
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,6 @@ window.Submap = (function () {
|
||||||
})
|
})
|
||||||
// TODO: add smooth/noise function for h, temp, prec n times
|
// TODO: add smooth/noise function for h, temp, prec n times
|
||||||
|
|
||||||
stage("Detect features, ocean and generating lakes.")
|
|
||||||
markFeatures();
|
|
||||||
|
|
||||||
if (options.depressRivers) {
|
if (options.depressRivers) {
|
||||||
stage("Generating riverbeds.")
|
stage("Generating riverbeds.")
|
||||||
const rbeds = new Uint16Array(grid.cells.i.length);
|
const rbeds = new Uint16Array(grid.cells.i.length);
|
||||||
|
|
@ -69,19 +66,24 @@ window.Submap = (function () {
|
||||||
if (!targetCells)
|
if (!targetCells)
|
||||||
throw "TargetCell shouldn't be empty.";
|
throw "TargetCell shouldn't be empty.";
|
||||||
targetCells.forEach(c => {
|
targetCells.forEach(c => {
|
||||||
if (grid.cells.t[c]<1) return;
|
if (grid.cells.h[c]<20) return;
|
||||||
rbeds[c] = 1;
|
rbeds[c] = 1;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
console.log("rbed stats: ", rbeds.filter(x=>x).length, rbeds.length)
|
||||||
// raise every land cell a bit except riverbeds
|
// raise every land cell a bit except riverbeds
|
||||||
grid.cells.h.forEach((h, i) => {
|
grid.cells.h.forEach((h, i) => {
|
||||||
if (!rbeds[i] || grid.cells.t[i]<1) return;
|
if (rbeds[i] || h<20) return;
|
||||||
grid.cells.h[i] = Math.min(grid.cells.h[i]+2, 100);
|
grid.cells.h[i] = Math.min(h+2, 100);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage("Detect features, ocean and generating lakes.")
|
||||||
|
markFeatures();
|
||||||
|
|
||||||
markupGridOcean();
|
markupGridOcean();
|
||||||
|
|
||||||
// Warning: addLakesInDeepDepressions can be very slow!
|
// Warning: addLakesInDeepDepressions can be very slow!
|
||||||
if (options.addLakesInDepressions) {
|
if (options.addLakesInDepressions) {
|
||||||
addLakesInDeepDepressions();
|
addLakesInDeepDepressions();
|
||||||
|
|
@ -118,7 +120,7 @@ window.Submap = (function () {
|
||||||
|
|
||||||
resampler(cells.p, oldCells.q, (id, oldid) => {
|
resampler(cells.p, oldCells.q, (id, oldid) => {
|
||||||
if (cells.t[id] * oldCells.t[oldid] < 0) {
|
if (cells.t[id] * oldCells.t[oldid] < 0) {
|
||||||
// missmaped cell: water instead of land or vice versa
|
// fix missmaped cell: water instead of land or vice versa
|
||||||
WARN && console.warn('Type discrepancy detected:', id, oldid, `${pack.cells.t[id]} != ${oldCells.t[oldid]}`);
|
WARN && console.warn('Type discrepancy detected:', id, oldid, `${pack.cells.t[id]} != ${oldCells.t[oldid]}`);
|
||||||
const aid = cells.t[id]<0
|
const aid = cells.t[id]<0
|
||||||
? cells.c[id].find(c=>cells.t[c]<0)
|
? cells.c[id].find(c=>cells.t[c]<0)
|
||||||
|
|
@ -136,11 +138,6 @@ window.Submap = (function () {
|
||||||
forwardMap[oldid].push(id)
|
forwardMap[oldid].push(id)
|
||||||
})
|
})
|
||||||
|
|
||||||
DEBUG && console.log('reversemap:',forwardMap)
|
|
||||||
DEBUG && console.log('forwardmap:',reverseMap)
|
|
||||||
|
|
||||||
// TODO: errode riverbeds
|
|
||||||
|
|
||||||
stage("Regenerating river network.")
|
stage("Regenerating river network.")
|
||||||
Rivers.generate();
|
Rivers.generate();
|
||||||
drawRivers();
|
drawRivers();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue