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>
</div>
<div id="addFeature">
<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>
</div>
</div>

View file

@ -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;
}
}

View file

@ -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();

View file

@ -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;