Use static empty pathfinding path when possible
This commit is contained in:
@@ -25,6 +25,8 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
public class PathFinder
|
||||
{
|
||||
readonly static List<CPos> emptyPath = new List<CPos>(0);
|
||||
|
||||
readonly World world;
|
||||
public PathFinder(World world) { this.world = world; }
|
||||
|
||||
@@ -50,7 +52,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.FrameNumber - cached.tick);
|
||||
if (world.FrameNumber - cached.tick > MaxPathAge)
|
||||
CachedPaths.Remove(cached);
|
||||
return new List<CPos>(cached.result);
|
||||
return emptyPath;
|
||||
}
|
||||
|
||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||
@@ -61,7 +63,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
var passable = mi.GetMovementClass(world.TileSet);
|
||||
if (!domainIndex.IsPassable(from, target, (uint)passable))
|
||||
return new List<CPos>(0);
|
||||
return emptyPath;
|
||||
}
|
||||
|
||||
var pb = FindBidiPath(
|
||||
@@ -103,7 +105,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
var passable = mi.GetMovementClass(world.TileSet);
|
||||
tilesInRange = new List<CPos>(tilesInRange.Where(t => domainIndex.IsPassable(src, t, (uint)passable)));
|
||||
if (tilesInRange.Count() == 0)
|
||||
return new List<CPos>(0);
|
||||
return emptyPath;
|
||||
}
|
||||
|
||||
var path = FindBidiPath(
|
||||
@@ -144,7 +146,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
}
|
||||
|
||||
// no path exists
|
||||
return new List<CPos>(0);
|
||||
return emptyPath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +211,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
return path;
|
||||
}
|
||||
|
||||
return new List<CPos>(0);
|
||||
return emptyPath;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user