diff --git a/src/modules/heightmap-generator.js b/src/modules/heightmap-generator.js index be6ff09f..ba0ecbd6 100644 --- a/src/modules/heightmap-generator.js +++ b/src/modules/heightmap-generator.js @@ -9,7 +9,7 @@ import {byId} from "utils/shorthands"; import {ERROR} from "../config/logging"; import {lim, minmax} from "../utils/numberUtils"; import {aleaPRNG} from "scripts/aleaPRNG"; -import {openNearSeaLakes, addLakesInDeepDepressions} from "scripts/generation/grid/lakes"; +import {addLakesInDeepDepressions} from "scripts/generation/grid/lakes"; window.HeightmapGenerator = (function () { let grid = null; @@ -78,14 +78,7 @@ window.HeightmapGenerator = (function () { Math.random = aleaPRNG(seed); const rawHeights = id in heightmapTemplates ? fromTemplate(graph, id) : await fromPrecreated(graph, id); - const removedLakesHeights = openNearSeaLakes(rawHeights, graph.cells.c, graph.cells.i, graph.cells.b); - const addedLakesHeights = addLakesInDeepDepressions( - removedLakesHeights, - graph.cells.c, - graph.cells.v, - graph.vertices, - graph.cells.i - ); + const addedLakesHeights = addLakesInDeepDepressions(rawHeights, graph.cells.c, graph.cells.i); TIME && console.timeEnd("defineHeightmap"); diff --git a/src/modules/submap.js b/src/modules/submap.js index 75dc0daf..5f81a6ad 100644 --- a/src/modules/submap.js +++ b/src/modules/submap.js @@ -6,7 +6,7 @@ import {getMiddlePoint} from "utils/lineUtils"; import {rn} from "utils/numberUtils"; import {aleaPRNG} from "scripts/aleaPRNG"; import {renderLayer} from "layers"; -import {markupGridFeatures} from "modules/markup"; +import {markupGridFeatures} from "scripts/generation/markup"; import {generateGrid} from "scripts/generation/graph"; window.Submap = (function () { diff --git a/src/scripts/generation/generation.ts b/src/scripts/generation/generation.ts index b3de2a66..23fd7609 100644 --- a/src/scripts/generation/generation.ts +++ b/src/scripts/generation/generation.ts @@ -64,8 +64,8 @@ async function generate(options?: IGenerationOptions) { // temp rendering for debug // renderLayer("cells"); renderLayer("features"); - // renderLayer("heightmap"); - // renderLayer("rivers", pack); + renderLayer("heightmap"); + renderLayer("rivers", pack); WARN && console.warn(`TOTAL: ${rn((performance.now() - timeStart) / 1000, 2)}s`); // showStatistics(); diff --git a/src/scripts/generation/grid/lakes.ts b/src/scripts/generation/grid/lakes.ts index 1c7b8f35..eb548e4f 100644 --- a/src/scripts/generation/grid/lakes.ts +++ b/src/scripts/generation/grid/lakes.ts @@ -1,77 +1,10 @@ import {TIME} from "config/logging"; -import {getInputNumber, getInputValue} from "utils/nodeUtils"; -import {DISTANCE_FIELD, MAX_HEIGHT, MIN_LAND_HEIGHT} from "config/generation"; -import {drawPolygon} from "utils/debugUtils"; - -const {LAND_COAST, WATER_COAST} = DISTANCE_FIELD; - -// near sea lakes usually get a lot of water inflow -// most of them would brake threshold and flow out to sea (see Ancylus Lake) -// connect these type of lakes to the main water body to improve the heightmap -export function openNearSeaLakes( - heights: Uint8Array, - neighbours: number[][], - indexes: UintArray, - borderCells: IGraphCells["b"] -) { - if (getInputValue("templateInput") === "Atoll") return; // no need for Atolls - - TIME && console.time("openNearSeaLakes"); - const MAX_BREACHABLE_HEIGHT = 22; // max height that can be breached by water - - const features: Dict<"ocean" | "lake"> = {}; - const featureIds: Dict = {}; - let featureId = 0; - - const lakeCoastalCells: Dict = {}; - - for (const cellId of indexes) { - if (featureIds[cellId]) continue; - if (heights[cellId] >= MIN_LAND_HEIGHT) continue; - - featureId += 1; - const breachableCoastalCells: number[] = []; - let isLake = true; // lakes are features surrounded by land cells - - const queue = [cellId]; - featureIds[cellId] = featureId; - - while (queue.length) { - const nextCellId = queue.pop()!; - - for (const neighborId of neighbours[nextCellId]) { - if (isLake && borderCells[neighborId]) isLake = false; - if (featureIds[neighborId]) continue; - const height = heights[neighborId]; - - if (height < MIN_LAND_HEIGHT) { - featureIds[neighborId] = featureId; - queue.push(neighborId); - } else if (isLake && height <= MAX_BREACHABLE_HEIGHT) { - breachableCoastalCells.push(neighborId); - } - } - } - - features[featureId] = isLake ? "lake" : "ocean"; - if (isLake) lakeCoastalCells[featureId] = breachableCoastalCells; - } - - console.log(featureIds, features, lakeCoastalCells); - - TIME && console.timeEnd("openNearSeaLakes"); - return heights; -} +import {getInputNumber} from "utils/nodeUtils"; +import {MAX_HEIGHT, MIN_LAND_HEIGHT} from "config/generation"; // some deeply depressed areas may not be resolved on river generation // this areas tend to collect precipitation, so we can add a lake there to help the resolver -export function addLakesInDeepDepressions( - heights: Uint8Array, - neighbours: number[][], - cellVertices: number[][], - vertices: IGraphVertices, - indexes: UintArray -) { +export function addLakesInDeepDepressions(heights: Uint8Array, neighbours: number[][], indexes: UintArray) { const ELEVATION_LIMIT = getInputNumber("lakeElevationLimitOutput"); if (ELEVATION_LIMIT === MAX_HEIGHT - MIN_LAND_HEIGHT) return heights; // any depression can be resolved @@ -114,9 +47,6 @@ export function addLakesInDeepDepressions( if (inDeepDepression) { currentHeights[cellId] = MIN_LAND_HEIGHT - 1; console.log(`ⓘ Added lake at deep depression. Cell: ${cellId}`); - - const polygon = cellVertices[cellId].map(vertex => vertices.p[vertex]); - drawPolygon(polygon, {stroke: "red", strokeWidth: 1, fill: "none"}); } } diff --git a/src/scripts/generation/pack/pack.ts b/src/scripts/generation/pack/pack.ts index b8cb4b0f..ace524a1 100644 --- a/src/scripts/generation/pack/pack.ts +++ b/src/scripts/generation/pack/pack.ts @@ -26,11 +26,18 @@ export function createPack(grid: IGrid): IPack { pick(cells, "v", "c", "b", "p", "h") ); - const {heights, flux, r, conf, rivers, mergedFeatures} = generateRivers( - grid.cells.prec, - grid.cells.temp, + const { + heights, + flux, + r, + conf, + rivers: rawRivers, + mergedFeatures + } = generateRivers( {...pick(cells, "i", "c", "b", "g", "h", "p"), f: featureIds, t: distanceField, haven}, - features + features, + grid.cells.prec, + grid.cells.temp ); // Biomes.define(newPack, grid); @@ -76,7 +83,7 @@ export function createPack(grid: IGrid): IPack { conf }, features: mergedFeatures, - rivers + rivers: rawRivers }; return pack; diff --git a/src/scripts/generation/pack/rivers.ts b/src/scripts/generation/pack/rivers.ts index c0d39a02..f6e489ae 100644 --- a/src/scripts/generation/pack/rivers.ts +++ b/src/scripts/generation/pack/rivers.ts @@ -13,10 +13,10 @@ const {Rivers} = window; const {LAND_COAST} = DISTANCE_FIELD; export function generateRivers( - precipitation: IGrid["cells"]["prec"], - temperature: IGrid["cells"]["temp"], cells: Pick, - features: TPackFeatures + features: TPackFeatures, + precipitation: IGrid["cells"]["prec"], + temperature: IGrid["cells"]["temp"] ) { TIME && console.time("generateRivers");