From a303299bbb6f6b905c5c8c23ac5d3ecef1ef92c5 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 7 Mar 2010 17:49:12 +1300 Subject: [PATCH] added a random delay before repathing (tunable per-unittype in Mobile). fixes a lot of pathological pathing perf. --- OpenRA.Game/Graphics/WorldRenderer.cs | 2 +- OpenRA.Game/Traits/Activities/Move.cs | 14 ++++++++++++++ OpenRA.Game/Traits/Mobile.cs | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 2f17e32a09..1e090eb923 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -200,7 +200,7 @@ namespace OpenRA.Graphics } } - if (ShowUnitPaths) + //if (ShowUnitPaths) { var mobile = selectedUnit.traits.GetOrDefault(); if (mobile != null) diff --git a/OpenRA.Game/Traits/Activities/Move.cs b/OpenRA.Game/Traits/Activities/Move.cs index 20ab3ddefc..60c6a686f0 100755 --- a/OpenRA.Game/Traits/Activities/Move.cs +++ b/OpenRA.Game/Traits/Activities/Move.cs @@ -151,6 +151,9 @@ namespace OpenRA.Traits.Activities throw new InvalidOperationException( "(Move) Sanity check failed" ); } + bool hasWaited; + int waitTicksRemaining; + int2? PopPath( Actor self, Mobile mobile ) { if( path.Count == 0 ) return null; @@ -163,6 +166,16 @@ namespace OpenRA.Traits.Activities return null; } + if (!hasWaited) + { + var info = self.Info.Traits.Get(); + waitTicksRemaining = info.WaitAverage + self.World.SharedRandom.Next(-info.WaitSpread, info.WaitSpread); + hasWaited = true; + } + + if (--waitTicksRemaining >= 0) + return null; + self.World.WorldActor.traits.Get().Remove( self, mobile ); var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList(); @@ -172,6 +185,7 @@ namespace OpenRA.Traits.Activities return null; } + hasWaited = false; path.RemoveAt( path.Count - 1 ); return nextCell; } diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 71e1c5b7d3..3401102b33 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -26,6 +26,8 @@ namespace OpenRA.Traits public class MobileInfo : ITraitInfo { public readonly UnitMovementType MovementType = UnitMovementType.Wheel; + public readonly int WaitAverage = 60; + public readonly int WaitSpread = 20; public object Create(Actor self) { return new Mobile(self); } }