map position on planet, fix wrong riverbed generation

This commit is contained in:
Mészáros Gergely 2021-09-13 00:12:01 +02:00
parent 1d1cd0bb71
commit b30234e43b
4 changed files with 36 additions and 21 deletions

View file

@ -1369,8 +1369,8 @@
<button id="addMarker" data-tip="Click on map to place a marker. Hold Shift to add multiple. Shortcut: Shift + 5">Marker</button> <button id="addMarker" data-tip="Click on map to place a marker. Hold Shift to add multiple. Shortcut: Shift + 5">Marker</button>
</div> </div>
<div id="addFeature">
<p>Click to create a new map:</p> <p>Click to create a new map:</p>
<div id="addFeature">
<button id="openSubmapOptions" data-tip="Click to generate new (sub)map from the current viewport" onclick="openSubmapOptions()">Submap</button> <button id="openSubmapOptions" data-tip="Click to generate new (sub)map from the current viewport" onclick="openSubmapOptions()">Submap</button>
</div> </div>
</div> </div>

View file

@ -1715,7 +1715,7 @@ function addZones(number = 1) {
queue.push(e); queue.push(e);
}); });
} catch (er) { } catch (er) {
console.log('WTF: ', q, cellsArray); console.error('Error in rebel generation: ', q, cellsArray);
throw er; throw er;
} }
} }

View file

@ -5,7 +5,7 @@ Experimental submaping module
window.Submap = (function () { window.Submap = (function () {
function resample(parentMap, projection, options) { 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 // parentMap: {seed, grid, pack} from original map
// projection: map function from old to new coordinates or backwards // projection: map function from old to new coordinates or backwards
// prj(x,y,direction:bool) -> [x',y'] // prj(x,y,direction:bool) -> [x',y']
@ -24,7 +24,6 @@ window.Submap = (function () {
applyMapSize(); applyMapSize();
placePoints(); placePoints();
calculateVoronoi(grid, grid.points); calculateVoronoi(grid, grid.points);
drawScaleBar(); drawScaleBar();
const resampler = (points, qtree, f) => { const resampler = (points, qtree, f) => {
@ -43,13 +42,14 @@ window.Submap = (function () {
grid.cells.prec = new Int8Array(n); // precipitation grid.cells.prec = new Int8Array(n); // precipitation
const gridCells = parentMap.grid.cells; 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) => { 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.h[id] = gridCells.h[cid];
grid.cells.temp[id] = gridCells.temp[cid]; grid.cells.temp[id] = gridCells.temp[cid];
grid.cells.prec[id] = gridCells.prec[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 // TODO: add smooth/noise function for h, temp, prec n times
@ -62,9 +62,12 @@ window.Submap = (function () {
// and erode riverbeds // and erode riverbeds
parentMap.pack.rivers.forEach(r => 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]; const targetCells = forwardGridMap[oldc];
if (!targetCells) throw "TargetCell shouldn't be empty."; if (!targetCells)
throw "TargetCell shouldn't be empty.";
targetCells.forEach(c => { targetCells.forEach(c => {
if (grid.cells.t[c]<1) return; if (grid.cells.t[c]<1) return;
rbeds[c] = 1; rbeds[c] = 1;
@ -79,12 +82,14 @@ window.Submap = (function () {
} }
markupGridOcean(); markupGridOcean();
if (options.addLakesInDepressions) // Warning: addLakesInDeepDepressions can be very slow!
if (options.addLakesInDepressions) {
addLakesInDeepDepressions(); addLakesInDeepDepressions();
// openNearSeaLakes(); openNearSeaLakes();
}
OceanLayers(); OceanLayers();
// defineMapSize(); // not needed (not random)
// TODO: update UI inputs before calculating according to new boundaries.
calculateMapCoordinates(); calculateMapCoordinates();
// calculateTemperatures(); // calculateTemperatures();
// generatePrecipitation(); // generatePrecipitation();
@ -92,7 +97,6 @@ window.Submap = (function () {
reGraph(); reGraph();
// remove misclassified cells // remove misclassified cells
stage("Define coastline.") stage("Define coastline.")
drawCoastline(); drawCoastline();

View file

@ -19,14 +19,15 @@ const generateSubmap = debounce(async function () {
WARN && console.warn("Resampling current map"); WARN && console.warn("Resampling current map");
closeDialogs("#worldConfigurator, #options3d"); closeDialogs("#worldConfigurator, #options3d");
const checked = id => Boolean(document.getElementById(id).checked)
const settings = { const settings = {
promoteTown: Boolean(document.getElementById("submapPromoteTown").checked), promoteTown: checked("submapPromoteTown"),
depressRivers: Boolean(document.getElementById("submapDepressRivers").checked), depressRivers: checked("submapDepressRivers"),
copyBurgs: Boolean(document.getElementById("submapCopyBurgs").checked), copyBurgs: checked("submapCopyBurgs"),
addLakesInDepressions: Boolean(document.getElementById("submapAddLakeInDepression").checked), addLakesInDepressions: checked("submapAddLakeInDepression"),
addMilitary: Boolean(document.getElementById("submapAddMilitary").checked), addMilitary: checked("submapAddMilitary"),
addMarkers: Boolean(document.getElementById("submapAddMarkers").checked), addMarkers: checked("submapAddMarkers"),
addZones: Boolean(document.getElementById("submapAddZones").checked), addZones: checked("submapAddZones"),
} }
// Create projection func from current zoom extents // 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)]; : [(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 // fix scale
distanceScale = distanceScaleInput.value = distanceScaleOutput.value = distanceScaleOutput.value / scale; distanceScale = distanceScaleInput.value = distanceScaleOutput.value = distanceScaleOutput.value / scale;
populationRate = populationRateInput.value = populationRateOutput.value = populationRateOutput.value / scale; populationRate = populationRateInput.value = populationRateOutput.value = populationRateOutput.value / scale;