Cache CandidateMovementCells within the same tick.
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
@@ -119,15 +120,23 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return TickChild(self);
|
return TickChild(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<CPos> searchCells = new List<CPos>();
|
||||||
|
int searchCellsTick = -1;
|
||||||
|
|
||||||
List<CPos> CalculatePathToTarget(Actor self, BlockedByActor check)
|
List<CPos> CalculatePathToTarget(Actor self, BlockedByActor check)
|
||||||
{
|
{
|
||||||
var targetCells = CandidateMovementCells(self);
|
|
||||||
var searchCells = new List<CPos>();
|
|
||||||
var loc = self.Location;
|
var loc = self.Location;
|
||||||
|
|
||||||
foreach (var cell in targetCells)
|
// PERF: Assume that CandidateMovementCells doesn't change within a tick to avoid repeated queries
|
||||||
if (domainIndex.IsPassable(loc, cell, Mobile.Info.LocomotorInfo) && Mobile.CanEnterCell(cell))
|
// when Move enumerates different BlockedByActor values
|
||||||
searchCells.Add(cell);
|
if (searchCellsTick != self.World.WorldTick)
|
||||||
|
{
|
||||||
|
searchCells.Clear();
|
||||||
|
searchCellsTick = self.World.WorldTick;
|
||||||
|
foreach (var cell in CandidateMovementCells(self))
|
||||||
|
if (domainIndex.IsPassable(loc, cell, Mobile.Info.LocomotorInfo) && Mobile.CanEnterCell(cell))
|
||||||
|
searchCells.Add(cell);
|
||||||
|
}
|
||||||
|
|
||||||
if (!searchCells.Any())
|
if (!searchCells.Any())
|
||||||
return NoPath;
|
return NoPath;
|
||||||
|
|||||||
Reference in New Issue
Block a user