Remove a bunch of unnecessary caching

This commit is contained in:
Paul Chote
2010-06-23 20:42:45 +12:00
parent b42589b479
commit 3e664779ef
5 changed files with 22 additions and 26 deletions

View File

@@ -60,8 +60,9 @@ namespace OpenRA
List<CachedPath> CachedPaths = new List<CachedPath>();
const int MaxPathAge = 50; /* x 40ms ticks */
public List<int2> FindUnitPath(int2 from, int2 target, UnitMovementType umt, Actor self)
public List<int2> FindUnitPath(int2 from, int2 target, Actor self)
{
var umt = self.traits.Get<Mobile>().GetMovementType();
using (new PerfSample("find_unit_path"))
{
var cached = CachedPaths.FirstOrDefault(p => p.from == from && p.to == target && p.umt == umt);
@@ -72,9 +73,9 @@ namespace OpenRA
}
var pb = FindBidiPath(
PathSearch.FromPoint(self, target, from, umt, true)
PathSearch.FromPoint(self, target, from, true)
.WithCustomBlocker(AvoidUnitsNear(from, 4, self)),
PathSearch.FromPoint(self, from, target, umt, true)
PathSearch.FromPoint(self, from, target, true)
.WithCustomBlocker(AvoidUnitsNear(from, 4, self))
.InReverse());
@@ -86,7 +87,7 @@ namespace OpenRA
}
}
public List<int2> FindUnitPathToRange( int2 src, int2 target, UnitMovementType umt, int range, Actor self )
public List<int2> FindUnitPathToRange( int2 src, int2 target, int range, Actor self )
{
using( new PerfSample( "find_unit_path_multiple_src" ) )
{
@@ -94,7 +95,7 @@ namespace OpenRA
var tilesInRange = world.FindTilesInCircle(target, range)
.Where( t => mobile.CanEnterCell(t));
var path = FindPath( PathSearch.FromPoints( self, tilesInRange, src, umt, false )
var path = FindPath( PathSearch.FromPoints( self, tilesInRange, src, false )
.WithCustomBlocker(AvoidUnitsNear(src, 4, self))
.InReverse());
path.Reverse();

View File

@@ -50,6 +50,8 @@ namespace OpenRA
cellInfo = InitCellInfo();
queue = new PriorityQueue<PathDistance>();
umt = self.traits.Get<Mobile>().GetMovementType();
buildingInfluence = world.WorldActor.traits.Get<BuildingInfluence>();
unitInfluence = world.WorldActor.traits.Get<UnitInfluence>();
}
@@ -172,31 +174,28 @@ namespace OpenRA
queue.Add( new PathDistance( heuristic( location ), location ) );
}
public static PathSearch Search( Actor self, UnitMovementType umt, bool checkForBlocked )
public static PathSearch Search( Actor self, bool checkForBlocked )
{
var search = new PathSearch(self) {
umt = umt,
checkForBlocked = checkForBlocked };
return search;
}
public static PathSearch FromPoint( Actor self, int2 from, int2 target, UnitMovementType umt, bool checkForBlocked )
public static PathSearch FromPoint( Actor self, int2 from, int2 target, bool checkForBlocked )
{
var search = new PathSearch(self) {
heuristic = DefaultEstimator( target ),
umt = umt,
checkForBlocked = checkForBlocked };
search.AddInitialCell( self.World, from );
return search;
}
public static PathSearch FromPoints(Actor self, IEnumerable<int2> froms, int2 target, UnitMovementType umt, bool checkForBlocked)
public static PathSearch FromPoints(Actor self, IEnumerable<int2> froms, int2 target, bool checkForBlocked)
{
var search = new PathSearch(self)
{
heuristic = DefaultEstimator(target),
umt = umt,
checkForBlocked = checkForBlocked
};

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Traits.Activities
int2? destination;
int nearEnough;
public List<int2> path;
Func<Actor, Mobile, List<int2>> getPath;
Func<Actor, List<int2>> getPath;
public Actor ignoreBuilding;
MovePart move;
@@ -50,9 +50,8 @@ namespace OpenRA.Traits.Activities
public Move( int2 destination, int nearEnough )
: this()
{
this.getPath = ( self, mobile ) => self.World.PathFinder.FindUnitPath(
self.Location, destination,
mobile.GetMovementType(), self );
this.getPath = self => self.World.PathFinder.FindUnitPath(
self.Location, destination, self );
this.destination = destination;
this.nearEnough = nearEnough;
}
@@ -60,9 +59,9 @@ namespace OpenRA.Traits.Activities
public Move(int2 destination, Actor ignoreBuilding)
: this()
{
this.getPath = (self, mobile) =>
this.getPath = self =>
self.World.PathFinder.FindPath(
PathSearch.FromPoint( self, self.Location, destination, mobile.GetMovementType(), false )
PathSearch.FromPoint( self, self.Location, destination, false )
.WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( self.Location, 4, self ))
.WithIgnoredBuilding( ignoreBuilding ));
@@ -74,9 +73,9 @@ namespace OpenRA.Traits.Activities
public Move( Actor target, int range )
: this()
{
this.getPath = ( self, mobile ) => self.World.PathFinder.FindUnitPathToRange(
this.getPath = self => self.World.PathFinder.FindUnitPathToRange(
self.Location, target.Location,
mobile.GetMovementType(), range, self );
range, self );
this.destination = null;
this.nearEnough = range;
}
@@ -84,7 +83,7 @@ namespace OpenRA.Traits.Activities
public Move(Func<List<int2>> getPath)
: this()
{
this.getPath = (_, _2) => getPath();
this.getPath = _ => getPath();
this.destination = null;
this.nearEnough = 0;
}
@@ -111,7 +110,7 @@ namespace OpenRA.Traits.Activities
return this;
}
path = getPath( self, mobile ).TakeWhile( a => a != self.Location ).ToList();
path = getPath( self ).TakeWhile( a => a != self.Location ).ToList();
SanityCheckPath( mobile );
}
@@ -187,7 +186,7 @@ namespace OpenRA.Traits.Activities
return null;
self.World.WorldActor.traits.Get<UnitInfluence>().Remove( self, mobile );
var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList();
var newPath = getPath(self).TakeWhile(a => a != self.Location).ToList();
self.World.WorldActor.traits.Get<UnitInfluence>().Add( self, mobile );
if (newPath.Count != 0)

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Activities
self.QueueActivity(new Move(
() =>
{
return self.World.PathFinder.FindPath(PathSearch.Search(self, UnitMovementType.Wheel, true)
return self.World.PathFinder.FindPath(PathSearch.Search(self, true)
.WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
.FromPoint(self.Location));
}));

View File

@@ -66,8 +66,6 @@ namespace OpenRA.Mods.RA
Actor ClosestProc(Actor self, Actor ignore)
{
var mobile = self.traits.Get<Mobile>();
var refs = self.World.Queries.OwnedBy[self.Owner]
.Where(x => x != ignore && x.traits.Contains<IAcceptOre>())
.ToList();
@@ -75,7 +73,6 @@ namespace OpenRA.Mods.RA
var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self,
refs.Select(r => r.Location + r.traits.Get<IAcceptOre>().DeliverOffset),
self.Location,
mobile.GetMovementType(),
false));
path.Reverse();
if (path.Count != 0)