From b30234e43bbd66c1cbd6a353f06adffbfae714e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Gergely?= Date: Mon, 13 Sep 2021 00:12:01 +0200 Subject: [PATCH] map position on planet, fix wrong riverbed generation --- index.html | 2 +- main.js | 2 +- modules/submap.js | 28 ++++++++++++++++------------ modules/ui/submap.js | 25 ++++++++++++++++++------- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index 2a8b4e8c..8243ebb9 100644 --- a/index.html +++ b/index.html @@ -1369,8 +1369,8 @@ +

Click to create a new map:

-

Click to create a new map:

diff --git a/main.js b/main.js index 1645e5ab..8d5f55ef 100644 --- a/main.js +++ b/main.js @@ -1715,7 +1715,7 @@ function addZones(number = 1) { queue.push(e); }); } catch (er) { - console.log('WTF: ', q, cellsArray); + console.error('Error in rebel generation: ', q, cellsArray); throw er; } } diff --git a/modules/submap.js b/modules/submap.js index 403ca275..ada728ab 100644 --- a/modules/submap.js +++ b/modules/submap.js @@ -5,7 +5,7 @@ Experimental submaping module window.Submap = (function () { function resample(parentMap, projection, options) { - // generate new map based on (resampling) existing one (parentMap) + // generate new map based on an existing one (resampling parentMap) // parentMap: {seed, grid, pack} from original map // projection: map function from old to new coordinates or backwards // prj(x,y,direction:bool) -> [x',y'] @@ -24,7 +24,6 @@ window.Submap = (function () { applyMapSize(); placePoints(); calculateVoronoi(grid, grid.points); - drawScaleBar(); const resampler = (points, qtree, f) => { @@ -43,13 +42,14 @@ window.Submap = (function () { grid.cells.prec = new Int8Array(n); // precipitation const gridCells = parentMap.grid.cells; - const forwardGridMap = parentMap.grid.points.map(_=>[]); // old -> [newcelllist] + // build cache old -> [newcelllist] + const forwardGridMap = parentMap.grid.points.map(_=>[]); resampler(grid.points, parentMap.pack.cells.q, (id, oldid) => { - const cid = parentMap.pack.cells.g[oldid] + const cid = parentMap.pack.cells.g[oldid]; grid.cells.h[id] = gridCells.h[cid]; grid.cells.temp[id] = gridCells.temp[cid]; grid.cells.prec[id] = gridCells.prec[cid]; - if (options.depressRivers) forwardGridMap[oldid].push(id); + if (options.depressRivers) forwardGridMap[cid].push(id); }) // TODO: add smooth/noise function for h, temp, prec n times @@ -62,9 +62,12 @@ window.Submap = (function () { // and erode riverbeds parentMap.pack.rivers.forEach(r => - r.cells.forEach(oldc => { + r.cells.forEach(oldpc => { + if (oldpc < 0) return; // ignore out of map marker (-1) + const oldc = parentMap.pack.cells.g[oldpc]; const targetCells = forwardGridMap[oldc]; - if (!targetCells) throw "TargetCell shouldn't be empty."; + if (!targetCells) + throw "TargetCell shouldn't be empty."; targetCells.forEach(c => { if (grid.cells.t[c]<1) return; rbeds[c] = 1; @@ -79,12 +82,14 @@ window.Submap = (function () { } markupGridOcean(); - if (options.addLakesInDepressions) + // Warning: addLakesInDeepDepressions can be very slow! + if (options.addLakesInDepressions) { addLakesInDeepDepressions(); - // openNearSeaLakes(); + openNearSeaLakes(); + } + OceanLayers(); - // defineMapSize(); // not needed (not random) - // TODO: update UI inputs before calculating according to new boundaries. + calculateMapCoordinates(); // calculateTemperatures(); // generatePrecipitation(); @@ -92,7 +97,6 @@ window.Submap = (function () { reGraph(); // remove misclassified cells - stage("Define coastline.") drawCoastline(); diff --git a/modules/ui/submap.js b/modules/ui/submap.js index b9331987..4dd62260 100644 --- a/modules/ui/submap.js +++ b/modules/ui/submap.js @@ -19,14 +19,15 @@ const generateSubmap = debounce(async function () { WARN && console.warn("Resampling current map"); closeDialogs("#worldConfigurator, #options3d"); + const checked = id => Boolean(document.getElementById(id).checked) const settings = { - promoteTown: Boolean(document.getElementById("submapPromoteTown").checked), - depressRivers: Boolean(document.getElementById("submapDepressRivers").checked), - copyBurgs: Boolean(document.getElementById("submapCopyBurgs").checked), - addLakesInDepressions: Boolean(document.getElementById("submapAddLakeInDepression").checked), - addMilitary: Boolean(document.getElementById("submapAddMilitary").checked), - addMarkers: Boolean(document.getElementById("submapAddMarkers").checked), - addZones: Boolean(document.getElementById("submapAddZones").checked), + promoteTown: checked("submapPromoteTown"), + depressRivers: checked("submapDepressRivers"), + copyBurgs: checked("submapCopyBurgs"), + addLakesInDepressions: checked("submapAddLakeInDepression"), + addMilitary: checked("submapAddMilitary"), + addMarkers: checked("submapAddMarkers"), + addZones: checked("submapAddZones"), } // Create projection func from current zoom extents @@ -37,6 +38,16 @@ const generateSubmap = debounce(async function () { : [(x-x0) * graphWidth / (x1-x0), (y-y0) * graphHeight / (y1-y0)]; } + // converting map position on the planet + const mapSizeOutput = document.getElementById("mapSizeOutput"); + const latitudeOutput = document.getElementById("latitudeOutput"); + const latN = 90 - (180 - mapSizeInput.value / 100 * 180) * latitudeOutput.value / 100; + const newLatN = latN - y0 / graphHeight * mapSizeOutput.value * 180 / 100; + mapSizeOutput.value /= scale; + latitudeOutput.value = (90 - newLatN) / (180 - mapSizeOutput.value / 100 * 180) * 100; + document.getElementById("mapSizeInput").value = mapSizeOutput.value; + document.getElementById("latitudeInput").value = latitudeOutput.value; + // fix scale distanceScale = distanceScaleInput.value = distanceScaleOutput.value = distanceScaleOutput.value / scale; populationRate = populationRateInput.value = populationRateOutput.value = populationRateOutput.value / scale;