From 4c3930043e1bd009456f68e985d7abaee2072631 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Wed, 30 Jun 2010 20:25:11 +1200 Subject: [PATCH] Reenable path cache to catch the most stupid path fails (doesn't help the most common fails) --- OpenRA.Game/PathFinder.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/OpenRA.Game/PathFinder.cs b/OpenRA.Game/PathFinder.cs index dcaf7e4dbd..93eb77a28d 100644 --- a/OpenRA.Game/PathFinder.cs +++ b/OpenRA.Game/PathFinder.cs @@ -43,6 +43,7 @@ namespace OpenRA public int2 to; public List result; public int tick; + public Actor actor; } List CachedPaths = new List(); @@ -50,16 +51,14 @@ namespace OpenRA public List FindUnitPath(int2 from, int2 target, Actor self) { - // Todo: Reenable cache on something that isn't umt - //var umt = self.traits.Get().GetMovementType(); using (new PerfSample("find_unit_path")) { - //var cached = CachedPaths.FirstOrDefault(p => p.from == from && p.to == target && p.umt == umt); - //if (cached != null) - //{ - // cached.tick = Game.LocalTick; - // return new List(cached.result); - //} + var cached = CachedPaths.FirstOrDefault(p => p.from == from && p.to == target && p.actor == self); + if (cached != null) + { + cached.tick = Game.LocalTick; + return new List(cached.result); + } var pb = FindBidiPath( PathSearch.FromPoint(self, target, from, true) @@ -70,8 +69,8 @@ namespace OpenRA CheckSanePath2(pb, from, target); - //CachedPaths.RemoveAll(p => Game.LocalTick - p.tick > MaxPathAge); - //CachedPaths.Add(new CachedPath { from = from, to = target, umt = umt, result = pb, tick = Game.LocalTick }); + CachedPaths.RemoveAll(p => Game.LocalTick - p.tick > MaxPathAge); + CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = Game.LocalTick }); return new List(pb); } }