added a random delay before repathing (tunable per-unittype in Mobile). fixes a lot of pathological pathing perf.

This commit is contained in:
Chris Forbes
2010-03-07 17:49:12 +13:00
parent 2547045881
commit a303299bbb
3 changed files with 17 additions and 1 deletions

View File

@@ -200,7 +200,7 @@ namespace OpenRA.Graphics
}
}
if (ShowUnitPaths)
//if (ShowUnitPaths)
{
var mobile = selectedUnit.traits.GetOrDefault<Mobile>();
if (mobile != null)

View File

@@ -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<MobileInfo>();
waitTicksRemaining = info.WaitAverage + self.World.SharedRandom.Next(-info.WaitSpread, info.WaitSpread);
hasWaited = true;
}
if (--waitTicksRemaining >= 0)
return null;
self.World.WorldActor.traits.Get<UnitInfluence>().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;
}

View File

@@ -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); }
}