hotfix: reGraph to no override pack object

This commit is contained in:
Azgaar 2022-06-01 22:19:45 +03:00
parent 1967dfe661
commit d602b0793c
3 changed files with 14 additions and 12 deletions

View file

@ -6116,7 +6116,7 @@
<script src="modules/ui/general.js?v=29052022"></script> <script src="modules/ui/general.js?v=29052022"></script>
<script src="modules/ui/options.js?v=29052022"></script> <script src="modules/ui/options.js?v=29052022"></script>
<script src="main.js?v=29052022"></script> <script src="main.js?v=01062022"></script>
<script defer src="modules/relief-icons.js"></script> <script defer src="modules/relief-icons.js"></script>
<script defer src="modules/ui/style.js"></script> <script defer src="modules/ui/style.js"></script>

22
main.js
View file

@ -45,7 +45,7 @@ let landmass = viewbox.append("g").attr("id", "landmass");
let texture = viewbox.append("g").attr("id", "texture"); let texture = viewbox.append("g").attr("id", "texture");
let terrs = viewbox.append("g").attr("id", "terrs"); let terrs = viewbox.append("g").attr("id", "terrs");
let biomes = viewbox.append("g").attr("id", "biomes"); let biomes = viewbox.append("g").attr("id", "biomes");
let cells = viewbox.append("g").attr("id", "cells"); let gridCells = viewbox.append("g").attr("id", "cells");
let gridOverlay = viewbox.append("g").attr("id", "gridOverlay"); let gridOverlay = viewbox.append("g").attr("id", "gridOverlay");
let coordinates = viewbox.append("g").attr("id", "coordinates"); let coordinates = viewbox.append("g").attr("id", "coordinates");
let compass = viewbox.append("g").attr("id", "compass"); let compass = viewbox.append("g").attr("id", "compass");
@ -1161,25 +1161,25 @@ function generatePrecipitation() {
// recalculate Voronoi Graph to pack cells // recalculate Voronoi Graph to pack cells
function reGraph() { function reGraph() {
TIME && console.time("reGraph"); TIME && console.time("reGraph");
const {cells, points, features} = grid; const {cells: gridCells, points, features} = grid;
const newCells = {p: [], g: [], h: []}; // store new data const newCells = {p: [], g: [], h: []}; // store new data
const spacing2 = grid.spacing ** 2; const spacing2 = grid.spacing ** 2;
for (const i of cells.i) { for (const i of gridCells.i) {
const height = cells.h[i]; const height = gridCells.h[i];
const type = cells.t[i]; const type = gridCells.t[i];
if (height < 20 && type !== -1 && type !== -2) continue; // exclude all deep ocean points if (height < 20 && type !== -1 && type !== -2) continue; // exclude all deep ocean points
if (type === -2 && (i % 4 === 0 || features[cells.f[i]].type === "lake")) continue; // exclude non-coastal lake points if (type === -2 && (i % 4 === 0 || features[gridCells.f[i]].type === "lake")) continue; // exclude non-coastal lake points
const [x, y] = points[i]; const [x, y] = points[i];
addNewPoint(i, x, y, height); addNewPoint(i, x, y, height);
// add additional points for cells along coast // add additional points for cells along coast
if (type === 1 || type === -1) { if (type === 1 || type === -1) {
if (cells.b[i]) continue; // not for near-border cells if (gridCells.b[i]) continue; // not for near-border cells
cells.c[i].forEach(function (e) { gridCells.c[i].forEach(function (e) {
if (i > e) return; if (i > e) return;
if (cells.t[e] === type) { if (gridCells.t[e] === type) {
const dist2 = (y - points[e][1]) ** 2 + (x - points[e][0]) ** 2; const dist2 = (y - points[e][1]) ** 2 + (x - points[e][0]) ** 2;
if (dist2 < spacing2) return; // too close to each other if (dist2 < spacing2) return; // too close to each other
const x1 = rn((x + points[e][0]) / 2, 1); const x1 = rn((x + points[e][0]) / 2, 1);
@ -1201,7 +1201,9 @@ function reGraph() {
return Math.min(area, 65535); return Math.min(area, 65535);
} }
pack = calculateVoronoi(newCells.p, grid.boundary); const {cells: packCells, vertices} = calculateVoronoi(newCells.p, grid.boundary);
pack.vertices = vertices;
pack.cells = packCells;
pack.cells.p = newCells.p; pack.cells.p = newCells.p;
pack.cells.g = getTypedArray(grid.points.length).from(newCells.g); pack.cells.g = getTypedArray(grid.points.length).from(newCells.g);
pack.cells.q = d3.quadtree(newCells.p.map(([x, y], i) => [x, y, i])); pack.cells.q = d3.quadtree(newCells.p.map(([x, y], i) => [x, y, i]));

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
// version and caching control // version and caching control
const version = "1.84.02"; // generator version, update each time const version = "1.84.03"; // generator version, update each time
{ {
document.title += " v" + version; document.title += " v" + version;