Detect heightmap based on pack data, convert to warning. (#827)

* Detect heightmap based on pack data, convert to warning.

* removing childMap alltogether
This commit is contained in:
Gergely Mészáros, Ph.D 2022-06-04 18:49:51 +02:00 committed by GitHub
parent 00ced6260b
commit 3694d77b87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,7 @@ main function: resample(options);
*/ */
window.Submap = (function () { window.Submap = (function () {
const isWater = (map, id) => (map.grid.cells.h[map.pack.cells.g[id]] < 20 ? true : false); const isWater = (pack, id) => pack.cells.h[id] < 20;
const inMap = (x, y) => x > 0 && x < graphWidth && y > 0 && y < graphHeight; const inMap = (x, y) => x > 0 && x < graphWidth && y > 0 && y < graphHeight;
function resample(parentMap, options) { function resample(parentMap, options) {
@ -126,7 +126,6 @@ window.Submap = (function () {
// generatePrecipitation(); // generatePrecipitation();
stage("Cell cleanup."); stage("Cell cleanup.");
reGraph(); reGraph();
const childMap = {grid, pack};
// remove misclassified cells // remove misclassified cells
stage("Define coastline."); stage("Define coastline.");
@ -180,9 +179,8 @@ window.Submap = (function () {
let d = Infinity; let d = Infinity;
oldChildren.forEach(oid => { oldChildren.forEach(oid => {
// this should be always true, unless some algo modded the height! // this should be always true, unless some algo modded the height!
if (isWater(parentMap, oid) !== isWater(childMap, id)) { if (isWater(parentMap.pack, oid) !== isWater(pack, id)) {
console.warn(`cell sank because of addLakesInDepressions: ${oid}`); console.warn(`cell sank because of addLakesInDepressions: ${oid}`);
return;
} }
const [oldpx, oldpy] = oldCells.p[oid]; const [oldpx, oldpy] = oldCells.p[oid];
const nd = distance(projection(oldpx, oldpy)); const nd = distance(projection(oldpx, oldpy));
@ -197,7 +195,7 @@ window.Submap = (function () {
} }
} }
if (isWater(childMap, id) !== isWater(parentMap, oldid)) { if (isWater(pack, id) !== isWater(parentMap.pack, oldid)) {
WARN && console.warn("Type discrepancy detected:", id, oldid, `${pack.cells.t[id]} != ${oldCells.t[oldid]}`); WARN && console.warn("Type discrepancy detected:", id, oldid, `${pack.cells.t[id]} != ${oldCells.t[oldid]}`);
} }
@ -360,7 +358,6 @@ window.Submap = (function () {
function copyBurgs(parentMap, projection, options) { function copyBurgs(parentMap, projection, options) {
const cells = pack.cells; const cells = pack.cells;
const childMap = {grid, pack};
pack.burgs = parentMap.pack.burgs; pack.burgs = parentMap.pack.burgs;
// remap burgs to the best new cell // remap burgs to the best new cell
@ -386,7 +383,7 @@ window.Submap = (function () {
// already occupied // already occupied
searchFunc = findNearest(isFreeLand, _ => true, 3); searchFunc = findNearest(isFreeLand, _ => true, 3);
if (isWater(childMap, cityCell) || b.port) if (isWater(pack, cityCell) || b.port)
// burg is in water or port // burg is in water or port
searchFunc = findNearest(isFreeLand, nearCoast, 6); searchFunc = findNearest(isFreeLand, nearCoast, 6);
@ -402,7 +399,7 @@ window.Submap = (function () {
[b.x, b.y] = b.port ? getMiddlePoint(newCell, neighbor) : cells.p[newCell]; [b.x, b.y] = b.port ? getMiddlePoint(newCell, neighbor) : cells.p[newCell];
if (b.port) b.port = cells.f[neighbor]; // copy feature number if (b.port) b.port = cells.f[neighbor]; // copy feature number
b.cell = newCell; b.cell = newCell;
if (b.port && !isWater(childMap, neighbor)) console.error("betrayal! negihbor must be water!", b); if (b.port && !isWater(pack, neighbor)) console.error("betrayal! negihbor must be water!", b);
} else { } else {
b.cell = cityCell; b.cell = cityCell;
} }