FindAndDeliverResources, trivial optimizations.

This commit is contained in:
Vapre
2021-07-16 02:02:57 +02:00
committed by Pavel Penev
parent eff7e803bf
commit 573a6cf645
2 changed files with 19 additions and 12 deletions

View File

@@ -110,11 +110,14 @@ namespace OpenRA.Mods.Common.Traits
// Correct for SubCell offset
target -= world.Map.Grid.OffsetOfSubCell(srcSub);
var rangeLengthSquared = range.LengthSquared;
var map = world.Map;
// Select only the tiles that are within range from the requested SubCell
// This assumes that the SubCell does not change during the path traversal
var tilesInRange = world.Map.FindTilesInCircle(targetCell, range.Length / 1024 + 1)
.Where(t => (world.Map.CenterOfCell(t) - target).LengthSquared <= range.LengthSquared
&& mobile.Info.CanEnterCell(self.World, self, t));
var tilesInRange = map.FindTilesInCircle(targetCell, range.Length / 1024 + 1)
.Where(t => (map.CenterOfCell(t) - target).LengthSquared <= rangeLengthSquared
&& mobile.Info.CanEnterCell(world, self, t));
// See if there is any cell within range that does not involve a cross-domain request
// Really, we only need to check the circle perimeter, but it's not clear that would be a performance win