Use Mobile.Pathfinder to reduce trait look-ups
This commit is contained in:
@@ -25,7 +25,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
readonly HarvesterInfo harvInfo;
|
readonly HarvesterInfo harvInfo;
|
||||||
readonly Mobile mobile;
|
readonly Mobile mobile;
|
||||||
readonly ResourceClaimLayer claimLayer;
|
readonly ResourceClaimLayer claimLayer;
|
||||||
readonly IPathFinder pathFinder;
|
|
||||||
readonly DomainIndex domainIndex;
|
readonly DomainIndex domainIndex;
|
||||||
|
|
||||||
Actor deliverActor;
|
Actor deliverActor;
|
||||||
@@ -43,7 +42,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
harvInfo = self.Info.TraitInfo<HarvesterInfo>();
|
harvInfo = self.Info.TraitInfo<HarvesterInfo>();
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
claimLayer = self.World.WorldActor.Trait<ResourceClaimLayer>();
|
||||||
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
|
||||||
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
||||||
this.deliverActor = deliverActor;
|
this.deliverActor = deliverActor;
|
||||||
}
|
}
|
||||||
@@ -218,7 +216,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
})
|
})
|
||||||
.FromPoint(searchFromLoc)
|
.FromPoint(searchFromLoc)
|
||||||
.FromPoint(self.Location))
|
.FromPoint(self.Location))
|
||||||
path = pathFinder.FindPath(search);
|
path = mobile.Pathfinder.FindPath(search);
|
||||||
|
|
||||||
if (path.Count > 0)
|
if (path.Count > 0)
|
||||||
return path[0];
|
return path[0];
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
static readonly List<CPos> NoPath = new List<CPos>();
|
static readonly List<CPos> NoPath = new List<CPos>();
|
||||||
|
|
||||||
protected readonly Mobile Mobile;
|
protected readonly Mobile Mobile;
|
||||||
readonly IPathFinder pathFinder;
|
|
||||||
readonly DomainIndex domainIndex;
|
readonly DomainIndex domainIndex;
|
||||||
readonly Color? targetLineColor;
|
readonly Color? targetLineColor;
|
||||||
|
|
||||||
@@ -40,7 +39,6 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
this.target = target;
|
this.target = target;
|
||||||
this.targetLineColor = targetLineColor;
|
this.targetLineColor = targetLineColor;
|
||||||
Mobile = self.Trait<Mobile>();
|
Mobile = self.Trait<Mobile>();
|
||||||
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
|
||||||
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
|
||||||
ChildHasPriority = false;
|
ChildHasPriority = false;
|
||||||
|
|
||||||
@@ -136,7 +134,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
using (var fromSrc = PathSearch.FromPoints(self.World, Mobile.Locomotor, self, searchCells, loc, check))
|
using (var fromSrc = PathSearch.FromPoints(self.World, Mobile.Locomotor, self, searchCells, loc, check))
|
||||||
using (var fromDest = PathSearch.FromPoint(self.World, Mobile.Locomotor, self, loc, lastVisibleTargetLocation, check).Reverse())
|
using (var fromDest = PathSearch.FromPoint(self.World, Mobile.Locomotor, self, loc, lastVisibleTargetLocation, check).Reverse())
|
||||||
return pathFinder.FindBidiPath(fromSrc, fromDest);
|
return Mobile.Pathfinder.FindBidiPath(fromSrc, fromDest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<Target> GetTargets(Actor self)
|
public override IEnumerable<Target> GetTargets(Actor self)
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// Prefer refineries with less occupancy (multiplier is to offset distance cost):
|
// Prefer refineries with less occupancy (multiplier is to offset distance cost):
|
||||||
return occupancy * Info.UnloadQueueCostModifier;
|
return occupancy * Info.UnloadQueueCostModifier;
|
||||||
}))
|
}))
|
||||||
path = self.World.WorldActor.Trait<IPathFinder>().FindPath(search);
|
path = mobile.Pathfinder.FindPath(search);
|
||||||
|
|
||||||
if (path.Count != 0)
|
if (path.Count != 0)
|
||||||
return refineries[path.Last()].First().Actor;
|
return refineries[path.Last()].First().Actor;
|
||||||
|
|||||||
@@ -803,12 +803,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (CanEnterCell(above))
|
if (CanEnterCell(above))
|
||||||
return above;
|
return above;
|
||||||
|
|
||||||
var pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
|
||||||
List<CPos> path;
|
List<CPos> path;
|
||||||
using (var search = PathSearch.Search(self.World, Locomotor, self, BlockedByActor.All,
|
using (var search = PathSearch.Search(self.World, Locomotor, self, BlockedByActor.All,
|
||||||
loc => loc.Layer == 0 && CanEnterCell(loc))
|
loc => loc.Layer == 0 && CanEnterCell(loc))
|
||||||
.FromPoint(self.Location))
|
.FromPoint(self.Location))
|
||||||
path = pathFinder.FindPath(search);
|
path = Pathfinder.FindPath(search);
|
||||||
|
|
||||||
if (path.Count > 0)
|
if (path.Count > 0)
|
||||||
return path[0];
|
return path[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user