mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 20:11:24 +01:00
refactoring for row based code
This commit is contained in:
parent
b640f977b9
commit
db49f1c924
7 changed files with 50 additions and 21 deletions
11
main.js
11
main.js
|
|
@ -631,6 +631,7 @@ void (function addDragToUpload() {
|
|||
});
|
||||
})();
|
||||
|
||||
const gridOptimizationRequired = () => window[document.getElementById('gridAlgorithm').value] == voronoiPoints;
|
||||
async function generate(options) {
|
||||
try {
|
||||
const timeStart = performance.now();
|
||||
|
|
@ -1166,23 +1167,27 @@ function generatePrecipitation() {
|
|||
}
|
||||
|
||||
// recalculate Voronoi Graph to pack cells
|
||||
// pars: optimize -> optimize cells structure, copy original graph otherwise.
|
||||
function reGraph() {
|
||||
TIME && console.time("reGraph");
|
||||
const {cells: gridCells, points, features} = grid;
|
||||
const newCells = {p: [], g: [], h: []}; // store new data
|
||||
const spacing2 = grid.spacing ** 2;
|
||||
const optimize = gridOptimizationRequired()
|
||||
|
||||
for (const i of gridCells.i) {
|
||||
const height = gridCells.h[i];
|
||||
const type = gridCells.t[i];
|
||||
if (height < 20 && type !== -1 && type !== -2) continue; // exclude all deep ocean points
|
||||
if (type === -2 && (i % 4 === 0 || features[gridCells.f[i]].type === "lake")) continue; // exclude non-coastal lake points
|
||||
if (optimize) {
|
||||
if (height < 20 && type !== -1 && type !== -2) continue; // exclude all deep ocean points
|
||||
if (type === -2 && (i % 4 === 0 || features[gridCells.f[i]].type === "lake")) continue; // exclude non-coastal lake points
|
||||
}
|
||||
const [x, y] = points[i];
|
||||
|
||||
addNewPoint(i, x, y, height);
|
||||
|
||||
// add additional points for cells along coast
|
||||
if (type === 1 || type === -1) {
|
||||
if (optimize && (type === 1 || type === -1)) {
|
||||
if (gridCells.b[i]) continue; // not for near-border cells
|
||||
gridCells.c[i].forEach(function (e) {
|
||||
if (i > e) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue