mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-16 17:31:24 +01:00
Removed priority queue in favor of FlatQueue (#1157)
* removed priority queue in favor of simple array extension as it will be easier to migrate to esm * patch: bump version * spacing * moved references to globalThis * demonstrate module interop * added version to priority-queue and moved to utils to follow dom loading pattern * removed PriorityQueue in favor of FlatQueue * update index.html * never mind that force push I don't know how to amend commits right * missing capitalization * priority set to 0 on 541 --------- Co-authored-by: RyanGuild <ryan.guild@us-ignite.org>
This commit is contained in:
parent
54491cfd09
commit
d7f5cae229
8 changed files with 40 additions and 39 deletions
11
index.html
11
index.html
|
|
@ -8022,7 +8022,6 @@
|
||||||
<script src="libs/jquery-ui.min.js"></script>
|
<script src="libs/jquery-ui.min.js"></script>
|
||||||
<script src="versioning.js"></script>
|
<script src="versioning.js"></script>
|
||||||
<script src="libs/d3.min.js"></script>
|
<script src="libs/d3.min.js"></script>
|
||||||
<script src="libs/priority-queue.min.js"></script>
|
|
||||||
<script src="libs/flatqueue.js"></script>
|
<script src="libs/flatqueue.js"></script>
|
||||||
<script src="libs/delaunator.min.js"></script>
|
<script src="libs/delaunator.min.js"></script>
|
||||||
<script src="libs/indexedDB.js?v=1.99.00"></script>
|
<script src="libs/indexedDB.js?v=1.99.00"></script>
|
||||||
|
|
@ -8053,14 +8052,14 @@
|
||||||
<script src="modules/lakes.js?v=1.99.00"></script>
|
<script src="modules/lakes.js?v=1.99.00"></script>
|
||||||
<script src="modules/biomes.js?v=1.99.00"></script>
|
<script src="modules/biomes.js?v=1.99.00"></script>
|
||||||
<script src="modules/names-generator.js?v=1.105.11"></script>
|
<script src="modules/names-generator.js?v=1.105.11"></script>
|
||||||
<script src="modules/cultures-generator.js?v=1.105.13"></script>
|
<script src="modules/cultures-generator.js?v=1.105.21"></script>
|
||||||
<script src="modules/burgs-and-states.js?v=1.105.7"></script>
|
<script src="modules/burgs-and-states.js?v=1.105.21"></script>
|
||||||
<script src="modules/provinces-generator.js?v=1.104.0"></script>
|
<script src="modules/provinces-generator.js?v=1.105.21"></script>
|
||||||
<script src="modules/routes-generator.js?v=1.104.10"></script>
|
<script src="modules/routes-generator.js?v=1.104.10"></script>
|
||||||
<script src="modules/religions-generator.js?v=1.99.05"></script>
|
<script src="modules/religions-generator.js?v=1.105.21"></script>
|
||||||
<script src="modules/military-generator.js?v=1.104.0"></script>
|
<script src="modules/military-generator.js?v=1.104.0"></script>
|
||||||
<script src="modules/markers-generator.js?v=1.104.0"></script>
|
<script src="modules/markers-generator.js?v=1.104.0"></script>
|
||||||
<script src="modules/zones-generator.js?v=1.104.0"></script>
|
<script src="modules/zones-generator.js?v=1.105.21"></script>
|
||||||
<script src="modules/coa-generator.js?v=1.99.00"></script>
|
<script src="modules/coa-generator.js?v=1.99.00"></script>
|
||||||
<script src="modules/submap.js?v=1.104.0"></script>
|
<script src="modules/submap.js?v=1.104.0"></script>
|
||||||
<script src="libs/alea.min.js?v1.105.0"></script>
|
<script src="libs/alea.min.js?v1.105.0"></script>
|
||||||
|
|
|
||||||
1
libs/priority-queue.min.js
vendored
1
libs/priority-queue.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -286,7 +286,8 @@ window.BurgsAndStates = (() => {
|
||||||
const {cells, states, cultures, burgs} = pack;
|
const {cells, states, cultures, burgs} = pack;
|
||||||
|
|
||||||
cells.state = cells.state || new Uint16Array(cells.i.length);
|
cells.state = cells.state || new Uint16Array(cells.i.length);
|
||||||
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
|
|
||||||
|
const queue = new FlatQueue();
|
||||||
const cost = [];
|
const cost = [];
|
||||||
|
|
||||||
const globalGrowthRate = byId("growthRate").valueAsNumber || 1;
|
const globalGrowthRate = byId("growthRate").valueAsNumber || 1;
|
||||||
|
|
@ -307,12 +308,13 @@ window.BurgsAndStates = (() => {
|
||||||
cells.state[capitalCell] = state.i;
|
cells.state[capitalCell] = state.i;
|
||||||
const cultureCenter = cultures[state.culture].center;
|
const cultureCenter = cultures[state.culture].center;
|
||||||
const b = cells.biome[cultureCenter]; // state native biome
|
const b = cells.biome[cultureCenter]; // state native biome
|
||||||
queue.queue({e: state.center, p: 0, s: state.i, b});
|
queue.push({e: state.center, p: 0, s: state.i, b}, 0);
|
||||||
cost[state.center] = 1;
|
cost[state.center] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const next = queue.dequeue();
|
const next = queue.pop();
|
||||||
|
|
||||||
const {e, p, s, b} = next;
|
const {e, p, s, b} = next;
|
||||||
const {type, culture} = states[s];
|
const {type, culture} = states[s];
|
||||||
|
|
||||||
|
|
@ -335,7 +337,7 @@ window.BurgsAndStates = (() => {
|
||||||
if (!cost[e] || totalCost < cost[e]) {
|
if (!cost[e] || totalCost < cost[e]) {
|
||||||
if (cells.h[e] >= 20) cells.state[e] = s; // assign state to cell
|
if (cells.h[e] >= 20) cells.state[e] = s; // assign state to cell
|
||||||
cost[e] = totalCost;
|
cost[e] = totalCost;
|
||||||
queue.queue({e, p: totalCost, s, b});
|
queue.push({e, p: totalCost, s, b}, totalCost);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -518,7 +518,7 @@ window.Cultures = (function () {
|
||||||
TIME && console.time("expandCultures");
|
TIME && console.time("expandCultures");
|
||||||
const {cells, cultures} = pack;
|
const {cells, cultures} = pack;
|
||||||
|
|
||||||
const queue = new PriorityQueue({comparator: (a, b) => a.priority - b.priority});
|
const queue = new FlatQueue();
|
||||||
const cost = [];
|
const cost = [];
|
||||||
|
|
||||||
const neutralRate = byId("neutralRate")?.valueAsNumber || 1;
|
const neutralRate = byId("neutralRate")?.valueAsNumber || 1;
|
||||||
|
|
@ -538,11 +538,11 @@ window.Cultures = (function () {
|
||||||
|
|
||||||
for (const culture of cultures) {
|
for (const culture of cultures) {
|
||||||
if (!culture.i || culture.removed || culture.lock) continue;
|
if (!culture.i || culture.removed || culture.lock) continue;
|
||||||
queue.queue({cellId: culture.center, cultureId: culture.i, priority: 0});
|
queue.push({cellId: culture.center, cultureId: culture.i, priority: 0}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const {cellId, priority, cultureId} = queue.dequeue();
|
const {cellId, priority, cultureId} = queue.pop();
|
||||||
const {type, expansionism} = cultures[cultureId];
|
const {type, expansionism} = cultures[cultureId];
|
||||||
|
|
||||||
cells.c[cellId].forEach(neibCellId => {
|
cells.c[cellId].forEach(neibCellId => {
|
||||||
|
|
@ -566,7 +566,7 @@ window.Cultures = (function () {
|
||||||
if (!cost[neibCellId] || totalCost < cost[neibCellId]) {
|
if (!cost[neibCellId] || totalCost < cost[neibCellId]) {
|
||||||
if (cells.pop[neibCellId] > 0) cells.culture[neibCellId] = cultureId; // assign culture to populated cell
|
if (cells.pop[neibCellId] > 0) cells.culture[neibCellId] = cultureId; // assign culture to populated cell
|
||||||
cost[neibCellId] = totalCost;
|
cost[neibCellId] = totalCost;
|
||||||
queue.queue({cellId: neibCellId, cultureId, priority: totalCost});
|
queue.push({cellId: neibCellId, cultureId, priority: totalCost}, totalCost);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,18 +77,18 @@ window.Provinces = (function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
// expand generated provinces
|
// expand generated provinces
|
||||||
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
|
const queue = new FlatQueue();
|
||||||
const cost = [];
|
const cost = [];
|
||||||
|
|
||||||
provinces.forEach(p => {
|
provinces.forEach(p => {
|
||||||
if (!p.i || p.removed || isProvinceLocked(p)) return;
|
if (!p.i || p.removed || isProvinceLocked(p)) return;
|
||||||
provinceIds[p.center] = p.i;
|
provinceIds[p.center] = p.i;
|
||||||
queue.queue({e: p.center, p: 0, province: p.i, state: p.state});
|
queue.push({e: p.center, province: p.i, state: p.state, p: 0}, 0);
|
||||||
cost[p.center] = 1;
|
cost[p.center] = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const {e, p, province, state} = queue.dequeue();
|
const {e, p, province, state} = queue.pop();
|
||||||
|
|
||||||
cells.c[e].forEach(e => {
|
cells.c[e].forEach(e => {
|
||||||
if (isProvinceCellLocked(e)) return; // do not overwrite cell of locked provinces
|
if (isProvinceCellLocked(e)) return; // do not overwrite cell of locked provinces
|
||||||
|
|
@ -103,7 +103,7 @@ window.Provinces = (function () {
|
||||||
if (!cost[e] || totalCost < cost[e]) {
|
if (!cost[e] || totalCost < cost[e]) {
|
||||||
if (land) provinceIds[e] = province; // assign province to a cell
|
if (land) provinceIds[e] = province; // assign province to a cell
|
||||||
cost[e] = totalCost;
|
cost[e] = totalCost;
|
||||||
queue.queue({e, p: totalCost, province, state});
|
queue.push({e, province, state, p: totalCost}, totalCost);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -158,9 +158,9 @@ window.Provinces = (function () {
|
||||||
// expand province
|
// expand province
|
||||||
const cost = [];
|
const cost = [];
|
||||||
cost[center] = 1;
|
cost[center] = 1;
|
||||||
queue.queue({e: center, p: 0});
|
queue.push({e: center, p: 0}, 0);
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const {e, p} = queue.dequeue();
|
const {e, p} = queue.pop();
|
||||||
|
|
||||||
cells.c[e].forEach(nextCellId => {
|
cells.c[e].forEach(nextCellId => {
|
||||||
if (provinceIds[nextCellId]) return;
|
if (provinceIds[nextCellId]) return;
|
||||||
|
|
@ -173,7 +173,7 @@ window.Provinces = (function () {
|
||||||
if (!cost[nextCellId] || totalCost < cost[nextCellId]) {
|
if (!cost[nextCellId] || totalCost < cost[nextCellId]) {
|
||||||
if (land && cells.state[nextCellId] === s.i) provinceIds[nextCellId] = provinceId; // assign province to a cell
|
if (land && cells.state[nextCellId] === s.i) provinceIds[nextCellId] = provinceId; // assign province to a cell
|
||||||
cost[nextCellId] = totalCost;
|
cost[nextCellId] = totalCost;
|
||||||
queue.queue({e: nextCellId, p: totalCost});
|
queue.push({e: nextCellId, p: totalCost}, totalCost);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -216,15 +216,15 @@ window.Provinces = (function () {
|
||||||
// check if there is a land way within the same state between two cells
|
// check if there is a land way within the same state between two cells
|
||||||
function isPassable(from, to) {
|
function isPassable(from, to) {
|
||||||
if (cells.f[from] !== cells.f[to]) return false; // on different islands
|
if (cells.f[from] !== cells.f[to]) return false; // on different islands
|
||||||
const queue = [from],
|
const passableQueue = [from],
|
||||||
used = new Uint8Array(cells.i.length),
|
used = new Uint8Array(cells.i.length),
|
||||||
state = cells.state[from];
|
state = cells.state[from];
|
||||||
while (queue.length) {
|
while (passableQueue.length) {
|
||||||
const current = queue.pop();
|
const current = passableQueue.pop();
|
||||||
if (current === to) return true; // way is found
|
if (current === to) return true; // way is found
|
||||||
cells.c[current].forEach(c => {
|
cells.c[current].forEach(c => {
|
||||||
if (used[c] || cells.h[c] < 20 || cells.state[c] !== state) return;
|
if (used[c] || cells.h[c] < 20 || cells.state[c] !== state) return;
|
||||||
queue.push(c);
|
passableQueue.push(c);
|
||||||
used[c] = 1;
|
used[c] = 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -695,7 +695,7 @@ window.Religions = (function () {
|
||||||
const {cells, routes} = pack;
|
const {cells, routes} = pack;
|
||||||
const religionIds = spreadFolkReligions(religions);
|
const religionIds = spreadFolkReligions(religions);
|
||||||
|
|
||||||
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
|
const queue = new FlatQueue();
|
||||||
const cost = [];
|
const cost = [];
|
||||||
|
|
||||||
// limit cost for organized religions growth
|
// limit cost for organized religions growth
|
||||||
|
|
@ -705,14 +705,14 @@ window.Religions = (function () {
|
||||||
.filter(r => r.i && !r.lock && r.type !== "Folk" && !r.removed)
|
.filter(r => r.i && !r.lock && r.type !== "Folk" && !r.removed)
|
||||||
.forEach(r => {
|
.forEach(r => {
|
||||||
religionIds[r.center] = r.i;
|
religionIds[r.center] = r.i;
|
||||||
queue.queue({e: r.center, p: 0, r: r.i, s: cells.state[r.center]});
|
queue.push({e: r.center, p: 0, r: r.i, s: cells.state[r.center]}, 0);
|
||||||
cost[r.center] = 1;
|
cost[r.center] = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
const religionsMap = new Map(religions.map(r => [r.i, r]));
|
const religionsMap = new Map(religions.map(r => [r.i, r]));
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const {e: cellId, p, r, s: state} = queue.dequeue();
|
const {e: cellId, p, r, s: state} = queue.pop();
|
||||||
const {culture, expansion, expansionism} = religionsMap.get(r);
|
const {culture, expansion, expansionism} = religionsMap.get(r);
|
||||||
|
|
||||||
cells.c[cellId].forEach(nextCell => {
|
cells.c[cellId].forEach(nextCell => {
|
||||||
|
|
@ -732,7 +732,7 @@ window.Religions = (function () {
|
||||||
if (cells.culture[nextCell]) religionIds[nextCell] = r; // assign religion to cell
|
if (cells.culture[nextCell]) religionIds[nextCell] = r; // assign religion to cell
|
||||||
cost[nextCell] = totalCost;
|
cost[nextCell] = totalCost;
|
||||||
|
|
||||||
queue.queue({e: nextCell, p: totalCost, r, s: state});
|
queue.push({e: nextCell, p: totalCost, r, s: state}, totalCost);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,11 +209,11 @@ window.Zones = (function () {
|
||||||
const cost = [];
|
const cost = [];
|
||||||
const maxCells = rand(20, 40);
|
const maxCells = rand(20, 40);
|
||||||
|
|
||||||
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
|
const queue = new FlatQueue();
|
||||||
queue.queue({e: burg.cell, p: 0});
|
queue.push({e: burg.cell, p: 0}, 0);
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const next = queue.dequeue();
|
const next = queue.pop();
|
||||||
if (cells.burg[next.e] || cells.pop[next.e]) cellsArray.push(next.e);
|
if (cells.burg[next.e] || cells.pop[next.e]) cellsArray.push(next.e);
|
||||||
usedCells[next.e] = 1;
|
usedCells[next.e] = 1;
|
||||||
|
|
||||||
|
|
@ -224,7 +224,7 @@ window.Zones = (function () {
|
||||||
|
|
||||||
if (!cost[nextCellId] || p < cost[nextCellId]) {
|
if (!cost[nextCellId] || p < cost[nextCellId]) {
|
||||||
cost[nextCellId] = p;
|
cost[nextCellId] = p;
|
||||||
queue.queue({e: nextCellId, p});
|
queue.push({e: nextCellId, p}, p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -251,11 +251,11 @@ window.Zones = (function () {
|
||||||
const cost = [];
|
const cost = [];
|
||||||
const maxCells = rand(5, 25);
|
const maxCells = rand(5, 25);
|
||||||
|
|
||||||
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
|
const queue = new FlatQueue();
|
||||||
queue.queue({e: burg.cell, p: 0});
|
queue.push({e: burg.cell, p: 0}, 0);
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const next = queue.dequeue();
|
const next = queue.pop();
|
||||||
if (cells.burg[next.e] || cells.pop[next.e]) cellsArray.push(next.e);
|
if (cells.burg[next.e] || cells.pop[next.e]) cellsArray.push(next.e);
|
||||||
usedCells[next.e] = 1;
|
usedCells[next.e] = 1;
|
||||||
|
|
||||||
|
|
@ -266,7 +266,7 @@ window.Zones = (function () {
|
||||||
|
|
||||||
if (!cost[e] || p < cost[e]) {
|
if (!cost[e] || p < cost[e]) {
|
||||||
cost[e] = p;
|
cost[e] = p;
|
||||||
queue.queue({e, p});
|
queue.push({e, p}), p;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
*
|
*
|
||||||
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
|
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
|
||||||
*/
|
*/
|
||||||
const VERSION = "1.105.20";
|
|
||||||
|
const VERSION = "1.105.21";
|
||||||
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
|
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue