Use DomainIndex to fix naval transport path perf.

This commit is contained in:
Paul Chote
2014-01-12 22:35:06 +13:00
parent 29e689178d
commit d2fa1a12f9

View File

@@ -20,6 +20,8 @@ namespace OpenRA.Mods.RA.Activities
readonly Target target; readonly Target target;
readonly Mobile mobile; readonly Mobile mobile;
readonly PathFinder pathFinder; readonly PathFinder pathFinder;
readonly DomainIndex domainIndex;
readonly int movementClass;
Activity inner; Activity inner;
CPos cachedTargetPosition; CPos cachedTargetPosition;
@@ -32,6 +34,8 @@ namespace OpenRA.Mods.RA.Activities
mobile = self.Trait<Mobile>(); mobile = self.Trait<Mobile>();
pathFinder = self.World.WorldActor.Trait<PathFinder>(); pathFinder = self.World.WorldActor.Trait<PathFinder>();
domainIndex = self.World.WorldActor.TraitOrDefault<DomainIndex>();
movementClass = mobile.Info.GetMovementClass(self.World.TileSet);
repath = true; repath = true;
} }
@@ -50,6 +54,19 @@ namespace OpenRA.Mods.RA.Activities
adjacentCells = Util.AdjacentCells(target).ToArray(); adjacentCells = Util.AdjacentCells(target).ToArray();
repath = false; repath = false;
var loc = self.Location;
var searchCells = new List<CPos>();
foreach (var cell in adjacentCells)
{
if (cell == loc)
return NextActivity;
else if (domainIndex == null || domainIndex.IsPassable(loc, cell, (uint)movementClass))
searchCells.Add(cell);
}
if (searchCells.Any())
{
var ps1 = new PathSearch(self.World, mobile.Info, self) var ps1 = new PathSearch(self.World, mobile.Info, self)
{ {
checkForBlocked = true, checkForBlocked = true,
@@ -57,13 +74,8 @@ namespace OpenRA.Mods.RA.Activities
inReverse = true inReverse = true
}; };
foreach (var cell in adjacentCells) foreach (var cell in searchCells)
{
if (cell == self.Location)
return NextActivity;
else
ps1.AddInitialCell(cell); ps1.AddInitialCell(cell);
}
ps1.heuristic = PathSearch.DefaultEstimator(mobile.toCell); ps1.heuristic = PathSearch.DefaultEstimator(mobile.toCell);
var ps2 = PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, target.CenterPosition.ToCPos(), true); var ps2 = PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, target.CenterPosition.ToCPos(), true);
@@ -71,6 +83,7 @@ namespace OpenRA.Mods.RA.Activities
inner = mobile.MoveTo(() => ret); inner = mobile.MoveTo(() => ret);
} }
}
// Force a repath once the actor reaches the next cell // Force a repath once the actor reaches the next cell
if (!repath && cachedTargetPosition != targetPosition) if (!repath && cachedTargetPosition != targetPosition)