mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: river generation start
This commit is contained in:
parent
4833a8ab35
commit
4e65616dbc
11 changed files with 285 additions and 265 deletions
|
|
@ -1,20 +1,16 @@
|
|||
/*////////////////////////////////////////////////////////////////
|
||||
aleaPRNG 1.1
|
||||
//////////////////////////////////////////////////////////////////
|
||||
https://github.com/macmcmeans/aleaPRNG/blob/master/aleaPRNG-1.1.js
|
||||
//////////////////////////////////////////////////////////////////
|
||||
Original work copyright © 2010 Johannes Baagøe, under MIT license
|
||||
This is a derivative work copyright (c) 2017-2020, W. Mac" McMeans, under BSD license.
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
////////////////////////////////////////////////////////////////*/
|
||||
export function aleaPRNG() {
|
||||
return (function (args) {
|
||||
"use strict";
|
||||
// @ts-nocheck
|
||||
|
||||
// aleaPRNG 1.1: https://github.com/macmcmeans/aleaPRNG/blob/master/aleaPRNG-1.1.js
|
||||
// Original work copyright © 2010 Johannes Baagøe, under MIT license
|
||||
// This is a derivative work copyright (c) 2017-2020, W. Mac" McMeans, under BSD license.
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
export function aleaPRNG(args) {
|
||||
return (function (args) {
|
||||
const version = "aleaPRNG 1.1.0";
|
||||
|
||||
var s0,
|
||||
|
|
@ -1,7 +1,4 @@
|
|||
import * as d3 from "d3";
|
||||
|
||||
import {ERROR} from "config/logging";
|
||||
import {clipPoly} from "utils/lineUtils";
|
||||
|
||||
export function getFeatureVertices({
|
||||
firstCell,
|
||||
|
|
@ -22,26 +19,6 @@ export function getFeatureVertices({
|
|||
const startingVertex = findStartingVertex({startingCell, featureIds, featureId, vertices, cells, packCellsNumber});
|
||||
const featureVertices = connectVertices({vertices, startingVertex, featureIds, featureId});
|
||||
|
||||
// temp: draw feature vertices
|
||||
cells.v[firstCell]
|
||||
.map(v => vertices.p[v])
|
||||
.forEach(([x, y]) => {
|
||||
d3.select("#debug").append("circle").attr("cx", x).attr("cy", y).attr("r", 0.2).attr("fill", "yellow");
|
||||
});
|
||||
|
||||
const [cx, cy] = vertices.p[startingVertex];
|
||||
d3.select("#debug").append("circle").attr("cx", cx).attr("cy", cy).attr("r", 1.5).attr("fill", "red");
|
||||
|
||||
const lineGen = d3.line();
|
||||
const points = clipPoly(featureVertices.map(v => vertices.p[v]));
|
||||
const path = lineGen(points)!;
|
||||
d3.select("#debug")
|
||||
.attr("fill", "none")
|
||||
.attr("stroke", "black")
|
||||
.attr("stroke-width", 0.1)
|
||||
.append("path")
|
||||
.attr("d", path);
|
||||
|
||||
return featureVertices;
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +83,7 @@ function findStartingVertex({
|
|||
throw new Error(`Markup: firstCell ${startingCell} of feature ${featureId} has no neighbors of other features`);
|
||||
}
|
||||
|
||||
const index = neibCells.indexOf(d3.min(otherFeatureNeibs)!);
|
||||
const index = neibCells.indexOf(Math.min(...otherFeatureNeibs)!);
|
||||
return cellVertices[index];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as d3 from "d3";
|
|||
import {ERROR, INFO, WARN} from "config/logging";
|
||||
import {closeDialogs} from "dialogs/utils";
|
||||
import {openDialog} from "dialogs";
|
||||
import {initLayers, restoreLayers} from "layers";
|
||||
import {initLayers, renderLayer, restoreLayers} from "layers";
|
||||
// @ts-expect-error js module
|
||||
import {drawCoastline} from "layers/renderers/drawCoastline";
|
||||
// @ts-expect-error js module
|
||||
|
|
@ -16,7 +16,6 @@ import {applyMapSize, randomizeOptions} from "modules/ui/options";
|
|||
import {applyStyleOnLoad} from "modules/ui/stylePresets";
|
||||
// @ts-expect-error js module
|
||||
import {addZones} from "modules/zones";
|
||||
// @ts-expect-error js module
|
||||
import {aleaPRNG} from "scripts/aleaPRNG";
|
||||
import {hideLoading, showLoading} from "scripts/loading";
|
||||
import {clearMainTip, tip} from "scripts/tooltips";
|
||||
|
|
@ -63,6 +62,11 @@ async function generate(options?: IGenerationOptions) {
|
|||
grid = newGrid;
|
||||
pack = newPack;
|
||||
|
||||
// temp rendering for debug
|
||||
renderLayer("coastline", pack.vertices, pack.features);
|
||||
renderLayer("heightmap");
|
||||
renderLayer("rivers", pack);
|
||||
|
||||
WARN && console.warn(`TOTAL: ${rn((performance.now() - timeStart) / 1000, 2)}s`);
|
||||
showStatistics();
|
||||
INFO && console.groupEnd();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import * as d3 from "d3";
|
||||
|
||||
import {renderLayer} from "layers";
|
||||
// @ts-expect-error js module
|
||||
import {drawCoastline} from "layers/renderers/drawCoastline";
|
||||
import {markupPackFeatures} from "modules/markup";
|
||||
|
|
@ -23,49 +22,54 @@ export function createPack(grid: IGrid): IPack {
|
|||
const {vertices, cells} = repackGrid(grid);
|
||||
|
||||
const markup = markupPackFeatures(grid, vertices, pick(cells, "v", "c", "b", "p", "h"));
|
||||
const {features, featureIds, distanceField, haven, harbor} = markup;
|
||||
|
||||
renderLayer("coastline", vertices, markup.features);
|
||||
const riverCells = {...cells, f: featureIds, t: distanceField, haven};
|
||||
Rivers.generate(grid, {cells: riverCells, features}, true);
|
||||
|
||||
// drawCoastline({vertices, cells}); // split into vertices definition and rendering
|
||||
|
||||
// Rivers.generate(newPack, grid);
|
||||
// renderLayer("rivers", newPack);
|
||||
// Lakes.defineGroup(newPack);
|
||||
// Biomes.define(newPack, grid);
|
||||
|
||||
// const rankCellsData = pick(newPack.cells, "i", "f", "fl", "conf", "r", "h", "area", "biome", "haven", "harbor");
|
||||
// rankCells(newPack.features!, rankCellsData);
|
||||
|
||||
Cultures.generate();
|
||||
Cultures.expand();
|
||||
BurgsAndStates.generate();
|
||||
Religions.generate();
|
||||
BurgsAndStates.defineStateForms();
|
||||
BurgsAndStates.generateProvinces();
|
||||
BurgsAndStates.defineBurgFeatures();
|
||||
// Cultures.generate();
|
||||
// Cultures.expand();
|
||||
// BurgsAndStates.generate();
|
||||
// Religions.generate();
|
||||
// BurgsAndStates.defineStateForms();
|
||||
// BurgsAndStates.generateProvinces();
|
||||
// BurgsAndStates.defineBurgFeatures();
|
||||
|
||||
renderLayer("states");
|
||||
renderLayer("borders");
|
||||
BurgsAndStates.drawStateLabels();
|
||||
// renderLayer("states");
|
||||
// renderLayer("borders");
|
||||
// BurgsAndStates.drawStateLabels();
|
||||
|
||||
Rivers.specify();
|
||||
Lakes.generateName();
|
||||
// Rivers.specify();
|
||||
// Lakes.generateName();
|
||||
|
||||
Military.generate();
|
||||
Markers.generate();
|
||||
addZones();
|
||||
// Military.generate();
|
||||
// Markers.generate();
|
||||
// addZones();
|
||||
|
||||
OceanLayers(newGrid);
|
||||
// OceanLayers(newGrid);
|
||||
|
||||
drawScaleBar(window.scale);
|
||||
Names.getMapName();
|
||||
// drawScaleBar(window.scale);
|
||||
// Names.getMapName();
|
||||
|
||||
const pack = {
|
||||
const pack: IPack = {
|
||||
vertices,
|
||||
cells
|
||||
cells: {
|
||||
...cells,
|
||||
f: featureIds,
|
||||
t: distanceField,
|
||||
haven,
|
||||
harbor
|
||||
},
|
||||
features
|
||||
};
|
||||
|
||||
return pack as IPack;
|
||||
return pack;
|
||||
}
|
||||
|
||||
// repack grid cells: discart deep water cells, add land cells along the coast
|
||||
|
|
@ -133,6 +137,3 @@ function repackGrid(grid: IGrid) {
|
|||
TIME && console.timeEnd("repackGrid");
|
||||
return pack;
|
||||
}
|
||||
function drawLayer(arg0: string, vertices: IGraphVertices, features: TPackFeatures) {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue