mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-11-08 10:09:16 +00:00
Scan only the bounding box of the area in CityPainter
The whole map was scanned for each district.
This commit is contained in:
1 parent
cedd5e89a0
commit
28e69c7332
1 file changed
+15
-2
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user