diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index f94901ee97..e38f64f4f1 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -67,16 +67,7 @@ namespace OpenRA.Graphics IEnumerable images) { foreach (var image in images) - { - var loc = image.Pos; - - if (loc.X > rect.Right || loc.X < rect.Left - image.Sprite.bounds.Width) - continue; - if (loc.Y > rect.Bottom || loc.Y < rect.Top - image.Sprite.bounds.Height) - continue; - - spriteRenderer.DrawSprite(image.Sprite, loc, image.Palette); - } + spriteRenderer.DrawSprite(image.Sprite, image.Pos, image.Palette); } class SpriteComparer : IComparer diff --git a/OpenRA.Game/PathFinder.cs b/OpenRA.Game/PathFinder.cs index c21923d63f..e881673a8b 100644 --- a/OpenRA.Game/PathFinder.cs +++ b/OpenRA.Game/PathFinder.cs @@ -46,10 +46,29 @@ namespace OpenRA : float.PositiveInfinity; } + class CachedPath + { + public int2 from; + public int2 to; + public UnitMovementType umt; + public List result; + public int tick; + } + + List CachedPaths = new List(); + const int MaxPathAge = 50; /* x 40ms ticks */ + public List FindUnitPath( int2 from, int2 target, UnitMovementType umt ) { 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); + } + Game.Debug("FindUnitPath {0} -> {1}".F(from, target)); var pb = FindBidiPath( @@ -57,7 +76,10 @@ namespace OpenRA PathSearch.FromPoint(world, from, target, umt, false).WithCustomBlocker(AvoidUnitsNear(from, 4))); CheckSanePath2(pb, from, target); - return pb; + + CachedPaths.RemoveAll(p => Game.LocalTick - p.tick > MaxPathAge); + CachedPaths.Add(new CachedPath { from = from, to = target, umt = umt, result = pb, tick = Game.LocalTick }); + return new List(pb); } }