From d6d83c00e8e9e2f184a49a1db6a345bc683538c8 Mon Sep 17 00:00:00 2001 From: Fabio Pedretti Date: Thu, 1 Oct 2026 13:04:02 +0200 Subject: [PATCH] Use a single flat array for the visited vertices Replace the array of Uint8Arrays, which was rebuilt with fill().map() on every iteration, by one flat Uint8Array that is allocated once and cleared at the start of each iteration. --- .../maps/random/rmgen/painter/SmoothingPainter.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/binaries/data/mods/public/maps/random/rmgen/painter/SmoothingPainter.js b/binaries/data/mods/public/maps/random/rmgen/painter/SmoothingPainter.js index 6883b0dd33..2249854705 100644 --- a/binaries/data/mods/public/maps/random/rmgen/painter/SmoothingPainter.js +++ b/binaries/data/mods/public/maps/random/rmgen/painter/SmoothingPainter.js @@ -26,20 +26,23 @@ SmoothingPainter.prototype.paint = function(area) const brushPoints = getPointsInBoundingBox(getBoundingBox( new Array(2).fill(0).map((zero, i) => new Vector2D(1, 1).mult(this.size).mult(i ? 1 : -1)))); + const vertexSize = g_Map.height.length; + + // Additional complexity to process all 4 vertices of each tile, i.e the last row too + const seen = new Uint8Array(vertexSize * vertexSize); + for (let i = 0; i < this.iterations; ++i) { - // Additional complexity to process all 4 vertices of each tile, i.e the last row too - const vertexSize = g_Map.height.length; - const seen = new Array(vertexSize).fill(0).map(zero => new Uint8Array(vertexSize).fill(0)); + seen.fill(0); for (const point of area.getPoints()) for (const tileVertex of g_TileVertices) { const vertex = Vector2D.add(point, tileVertex); - if (!g_Map.validHeight(vertex) || seen[vertex.x][vertex.y]) + if (!g_Map.validHeight(vertex) || seen[vertex.x * vertexSize + vertex.y]) continue; - seen[vertex.x][vertex.y] = 1; + seen[vertex.x * vertexSize + vertex.y] = 1; let sumWeightedHeights = 0; let sumWeights = 0;