Avoid LINQ when building map domains.

This commit is contained in:
RoosterDragon
2017-12-15 19:52:56 +00:00
committed by reaperrr
parent dd2ae9fe5e
commit 13edaefcac

View File

@@ -204,7 +204,7 @@ namespace OpenRA.Mods.Common.Traits
var toProcess = new Queue<CPos>(); var toProcess = new Queue<CPos>();
toProcess.Enqueue(MPos.Zero.ToCPos(map)); toProcess.Enqueue(MPos.Zero.ToCPos(map));
// Flood-fill over each domain // Flood-fill over each domain.
while (toProcess.Count != 0) while (toProcess.Count != 0)
{ {
var start = toProcess.Dequeue(); var start = toProcess.Dequeue();
@@ -220,7 +220,7 @@ namespace OpenRA.Mods.Common.Traits
var currentPassable = CanTraverseTile(world, start); var currentPassable = CanTraverseTile(world, start);
// Add all contiguous cells to our domain, and make a note of // Add all contiguous cells to our domain, and make a note of
// any non-contiguous cells for future domains // any non-contiguous cells for future domains.
while (domainQueue.Count != 0) while (domainQueue.Count != 0)
{ {
var n = domainQueue.Dequeue(); var n = domainQueue.Dequeue();
@@ -237,13 +237,15 @@ namespace OpenRA.Mods.Common.Traits
visited[n] = true; visited[n] = true;
domains[n] = domain; domains[n] = domain;
// Don't crawl off the map, or add already-visited cells // PERF: Avoid LINQ.
var neighbors = CVec.Directions.Select(d => n + d) foreach (var direction in CVec.Directions)
.Where(p => visited.Contains(p) && !visited[p]); {
// Don't crawl off the map, or add already-visited cells.
foreach (var neighbor in neighbors) var neighbor = direction + n;
if (visited.Contains(neighbor) && !visited[neighbor])
domainQueue.Enqueue(neighbor); domainQueue.Enqueue(neighbor);
} }
}
domain += 1; domain += 1;
} }