Cache IPathFinder in Mobile at creation
Avoiding look-ups on every move order, as well as reducing line lengths.
This commit is contained in:
@@ -52,9 +52,10 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
using (var search =
|
using (var search =
|
||||||
PathSearch.FromPoint(self.World, mobile.Locomotor, self, mobile.ToCell, destination, check)
|
PathSearch.FromPoint(self.World, mobile.Locomotor, self, mobile.ToCell, destination, check)
|
||||||
.WithoutLaneBias())
|
.WithoutLaneBias())
|
||||||
path = self.World.WorldActor.Trait<IPathFinder>().FindPath(search);
|
path = mobile.Pathfinder.FindPath(search);
|
||||||
return path;
|
return path;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.targetLineColor = targetLineColor;
|
this.targetLineColor = targetLineColor;
|
||||||
nearEnough = WDist.Zero;
|
nearEnough = WDist.Zero;
|
||||||
@@ -70,8 +71,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (!this.destination.HasValue)
|
if (!this.destination.HasValue)
|
||||||
return NoPath;
|
return NoPath;
|
||||||
|
|
||||||
return self.World.WorldActor.Trait<IPathFinder>()
|
return mobile.Pathfinder.FindUnitPath(mobile.ToCell, this.destination.Value, self, ignoreActor, check);
|
||||||
.FindUnitPath(mobile.ToCell, this.destination.Value, self, ignoreActor, check);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: Will be recalculated from OnFirstRun if evaluateNearestMovableCell is true
|
// Note: Will be recalculated from OnFirstRun if evaluateNearestMovableCell is true
|
||||||
@@ -87,8 +87,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
|
|
||||||
getPath = check => self.World.WorldActor.Trait<IPathFinder>()
|
getPath = check => mobile.Pathfinder.FindUnitPathToRange(
|
||||||
.FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self, check);
|
mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self, check);
|
||||||
|
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = nearEnough;
|
this.nearEnough = nearEnough;
|
||||||
this.targetLineColor = targetLineColor;
|
this.targetLineColor = targetLineColor;
|
||||||
@@ -103,7 +104,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (!target.IsValidFor(self))
|
if (!target.IsValidFor(self))
|
||||||
return NoPath;
|
return NoPath;
|
||||||
|
|
||||||
return self.World.WorldActor.Trait<IPathFinder>().FindUnitPathToRange(
|
return mobile.Pathfinder.FindUnitPathToRange(
|
||||||
mobile.ToCell, mobile.ToSubCell, target.CenterPosition, range, self, check);
|
mobile.ToCell, mobile.ToSubCell, target.CenterPosition, range, self, check);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -217,6 +217,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public Locomotor Locomotor { get; private set; }
|
public Locomotor Locomotor { get; private set; }
|
||||||
|
|
||||||
|
public IPathFinder Pathfinder { get; private set; }
|
||||||
|
|
||||||
#region IOccupySpace
|
#region IOccupySpace
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
@@ -279,6 +281,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
notifyMoving = self.TraitsImplementing<INotifyMoving>().ToArray();
|
notifyMoving = self.TraitsImplementing<INotifyMoving>().ToArray();
|
||||||
notifyFinishedMoving = self.TraitsImplementing<INotifyFinishedMoving>().ToArray();
|
notifyFinishedMoving = self.TraitsImplementing<INotifyFinishedMoving>().ToArray();
|
||||||
moveWrappers = self.TraitsImplementing<IWrapMove>().ToArray();
|
moveWrappers = self.TraitsImplementing<IWrapMove>().ToArray();
|
||||||
|
Pathfinder = self.World.WorldActor.Trait<IPathFinder>();
|
||||||
Locomotor = self.World.WorldActor.TraitsImplementing<Locomotor>()
|
Locomotor = self.World.WorldActor.TraitsImplementing<Locomotor>()
|
||||||
.Single(l => l.Info.Name == Info.Locomotor);
|
.Single(l => l.Info.Name == Info.Locomotor);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user