mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-03-23 15:47:24 +01:00
Optimize zones restoration with O(n) map lookup instead of O(n²)
Co-authored-by: Azgaar <26469650+Azgaar@users.noreply.github.com>
This commit is contained in:
parent
83649e45a9
commit
09a4f17270
1 changed files with 8 additions and 1 deletions
|
|
@ -443,9 +443,16 @@ function editHeightmap(options) {
|
|||
Lakes.defineNames();
|
||||
}
|
||||
|
||||
const gridToPackMap = new Map();
|
||||
for (const i of pack.cells.i) {
|
||||
const g = pack.cells.g[i];
|
||||
if (!gridToPackMap.has(g)) gridToPackMap.set(g, []);
|
||||
gridToPackMap.get(g).push(i);
|
||||
}
|
||||
|
||||
for (const zone of pack.zones) {
|
||||
if (!zone.gridCells || !zone.gridCells.length) continue;
|
||||
zone.cells = pack.cells.i.filter(i => zone.gridCells.includes(pack.cells.g[i]));
|
||||
zone.cells = zone.gridCells.flatMap(g => gridToPackMap.get(g) || []);
|
||||
delete zone.gridCells;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue