From 28e69c73324078502b2d9999e04a22993620c9c6 Mon Sep 17 00:00:00 2001 From: Fabio Pedretti Date: Tue, 20 Oct 2026 11:42:42 +0200 Subject: [PATCH] Scan only the bounding box of the area in CityPainter The whole map was scanned for each district. --- .../maps/random/rmgen/painter/CityPainter.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/binaries/data/mods/public/maps/random/rmgen/painter/CityPainter.js b/binaries/data/mods/public/maps/random/rmgen/painter/CityPainter.js index 56da017b0c..54dbe7c38d 100644 --- a/binaries/data/mods/public/maps/random/rmgen/painter/CityPainter.js +++ b/binaries/data/mods/public/maps/random/rmgen/painter/CityPainter.js @@ -42,9 +42,22 @@ CityPainter.prototype.paint = function(area) const processed = new Array(mapSize).fill(0).map(() => new Uint8Array(mapSize)); - for (let x = 0; x < mapSize; x += 0.5) + const areaPoints = area.getPoints(); + if (!areaPoints.length) + return; + + // Scan only the bounding box of the area in the rotated frame + const box = getBoundingBox(areaPoints.map(point => point.clone().rotateAround(-this.angle, mapCenter))); + + // The margin covers the rounding + const startX = Math.clamp(Math.floor((box.min.x - 2) * 2) / 2, 0, mapSize); + const startY = Math.clamp(Math.floor((box.min.y - 2) * 2) / 2, 0, mapSize); + const endX = Math.clamp(box.max.x + 2, 0, mapSize); + const endY = Math.clamp(box.max.y + 2, 0, mapSize); + + for (let x = startX; x < endX; x += 0.5) { - for (let y = 0; y < mapSize; y += 0.5) + for (let y = startY; y < endY; y += 0.5) { const point = new Vector2D(x, y).rotateAround(this.angle, mapCenter).round(); if (!area.contains(point) || processed[point.x][point.y] || !g_Map.validTilePassable(point))