From ecb367616da5807b33fc25548f0192c7e5b94438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Gergely?= Date: Mon, 13 Sep 2021 01:55:59 +0200 Subject: [PATCH] fix:riverbed generation --- modules/river-generator.js | 10 ++++++---- modules/submap.js | 21 +++++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/modules/river-generator.js b/modules/river-generator.js index b7a862de..752c84a2 100644 --- a/modules/river-generator.js +++ b/modules/river-generator.js @@ -31,10 +31,12 @@ window.Rivers = (function () { TIME && console.timeEnd("generateRivers"); function drainWater() { - const sqrpixel = distanceScale * distanceScale - const MIN_FLUX_TO_FORM_RIVER = 10 * distanceScale; + const pixel2 = distanceScale * distanceScale + //const MIN_FLUX_TO_FORM_RIVER = 10 * distanceScale; + const MIN_FLUX_TO_FORM_RIVER = 30; 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 lakeOutCells = Lakes.setClimateData(h); @@ -167,7 +169,7 @@ window.Rivers = (function () { const mouth = riverCells[riverCells.length - 2]; 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 discharge = cells.fl[mouth]; // m3 in second const length = getApproximateLength(meanderedPoints); diff --git a/modules/submap.js b/modules/submap.js index ada728ab..ef0618f8 100644 --- a/modules/submap.js +++ b/modules/submap.js @@ -53,9 +53,6 @@ window.Submap = (function () { }) // TODO: add smooth/noise function for h, temp, prec n times - stage("Detect features, ocean and generating lakes.") - markFeatures(); - if (options.depressRivers) { stage("Generating riverbeds.") const rbeds = new Uint16Array(grid.cells.i.length); @@ -69,19 +66,24 @@ window.Submap = (function () { if (!targetCells) throw "TargetCell shouldn't be empty."; targetCells.forEach(c => { - if (grid.cells.t[c]<1) return; + if (grid.cells.h[c]<20) return; rbeds[c] = 1; }); }) ); + console.log("rbed stats: ", rbeds.filter(x=>x).length, rbeds.length) // raise every land cell a bit except riverbeds grid.cells.h.forEach((h, i) => { - if (!rbeds[i] || grid.cells.t[i]<1) return; - grid.cells.h[i] = Math.min(grid.cells.h[i]+2, 100); + if (rbeds[i] || h<20) return; + grid.cells.h[i] = Math.min(h+2, 100); }); } + stage("Detect features, ocean and generating lakes.") + markFeatures(); + markupGridOcean(); + // Warning: addLakesInDeepDepressions can be very slow! if (options.addLakesInDepressions) { addLakesInDeepDepressions(); @@ -118,7 +120,7 @@ window.Submap = (function () { resampler(cells.p, oldCells.q, (id, oldid) => { 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]}`); const aid = cells.t[id]<0 ? cells.c[id].find(c=>cells.t[c]<0) @@ -136,11 +138,6 @@ window.Submap = (function () { forwardMap[oldid].push(id) }) - DEBUG && console.log('reversemap:',forwardMap) - DEBUG && console.log('forwardmap:',reverseMap) - - // TODO: errode riverbeds - stage("Regenerating river network.") Rivers.generate(); drawRivers();