♻️ Optimizations of the various system

🍱 Retexture of the enemy portal
This commit is contained in:
2025-08-31 18:26:45 +08:00
parent 09511b37c9
commit b424aafeab
16 changed files with 497 additions and 399 deletions

View File

@@ -43,11 +43,29 @@ public partial class GridManager : Node
public void FreeArea(Vector2I topLeft, Vector2I size, float rotation, GridLayer layer = GridLayer.Building)
{
// Get all cells that should be occupied by this building
var occupiedCells = GridUtils.GetOccupiedCells(topLeft, size, rotation);
foreach (var cell in occupiedCells)
// Create a list to store cells that should be removed
var cellsToRemove = new List<Vector2I>();
// First, find all cells that match this building's position and size
foreach (var cell in _layers[layer].Keys.ToList())
{
if (_layers[layer].ContainsKey(cell))
_layers[layer].Remove(cell);
var (building, buildingSize, buildingRotation) = _layers[layer][cell];
var buildingCells = GridUtils.GetOccupiedCells(cell, buildingSize, buildingRotation);
// If any of the building's cells match our target area, mark all of its cells for removal
if (buildingCells.Any(c => occupiedCells.Contains(c)))
{
cellsToRemove.AddRange(buildingCells);
}
}
// Remove all marked cells
foreach (var cell in cellsToRemove.Distinct())
{
_layers[layer].Remove(cell);
}
}