mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: voronoi
This commit is contained in:
parent
e59b536e83
commit
00d8d28d76
16 changed files with 1912 additions and 171 deletions
|
|
@ -6,7 +6,7 @@ import {initLayers, renderLayer, restoreLayers} from "layers";
|
|||
// @ts-expect-error js module
|
||||
import {drawCoastline} from "modules/coastline";
|
||||
import {calculateMapCoordinates, defineMapSize} from "modules/coordinates";
|
||||
import {markupGridFeatures} from "modules/markup";
|
||||
import {markupGridFeatures, reMarkFeatures} from "modules/markup";
|
||||
// @ts-expect-error js module
|
||||
import {drawScaleBar, Rulers} from "modules/measurers";
|
||||
// @ts-expect-error js module
|
||||
|
|
@ -55,7 +55,8 @@ export async function generate(options?: IGenerationOptions) {
|
|||
|
||||
const updatedGrid = await updateGrid(grid, precreatedGraph);
|
||||
|
||||
reGraph(updatedGrid);
|
||||
const pack = reGraph(updatedGrid);
|
||||
reMarkFeatures(pack, grid);
|
||||
drawCoastline();
|
||||
|
||||
Rivers.generate();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {DISTANCE_FIELD, MIN_LAND_HEIGHT} from "config/generation";
|
|||
const {LAND_COAST, WATER_COAST, DEEPER_WATER} = DISTANCE_FIELD;
|
||||
|
||||
// recalculate Voronoi Graph to pack cells
|
||||
export function reGraph(grid: IGrid) {
|
||||
export function reGraph(grid: IGrid): IPackBase {
|
||||
TIME && console.time("reGraph");
|
||||
const {cells: gridCells, points, features} = grid;
|
||||
const newCells: {p: TPoints; g: number[]; h: number[]} = {p: [], g: [], h: []}; // store new data
|
||||
|
|
@ -56,14 +56,20 @@ export function reGraph(grid: IGrid) {
|
|||
return Math.min(area, UINT16_MAX);
|
||||
}
|
||||
|
||||
const {cells: packCells, vertices} = calculateVoronoi(newCells.p, grid.boundary);
|
||||
pack.vertices = vertices;
|
||||
pack.cells = packCells;
|
||||
pack.cells.p = newCells.p;
|
||||
pack.cells.g = createTypedArray({maxValue: grid.points.length, from: newCells.g});
|
||||
pack.cells.q = d3.quadtree(newCells.p.map(([x, y], i) => [x, y, i]));
|
||||
pack.cells.h = new Uint8Array(newCells.h);
|
||||
pack.cells.area = createTypedArray({maxValue: UINT16_MAX, from: pack.cells.i}).map(getCellArea);
|
||||
const {cells, vertices} = calculateVoronoi(newCells.p, grid.boundary);
|
||||
|
||||
const pack: IPackBase = {
|
||||
vertices,
|
||||
cells: {
|
||||
...cells,
|
||||
p: newCells.p,
|
||||
g: createTypedArray({maxValue: grid.points.length, from: newCells.g}),
|
||||
q: d3.quadtree(newCells.p.map(([x, y], i) => [x, y, i])),
|
||||
h: new Uint8Array(newCells.h),
|
||||
area: createTypedArray({maxValue: UINT16_MAX, from: cells.i}).map(getCellArea)
|
||||
}
|
||||
};
|
||||
|
||||
TIME && console.timeEnd("reGraph");
|
||||
return pack;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue