Merge pull request #10376 from RoosterDragon/repulse-perf
Speed up Aircraft.Repulse.
This commit is contained in:
@@ -97,6 +97,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
UpgradeManager um;
|
UpgradeManager um;
|
||||||
IDisposable reservation;
|
IDisposable reservation;
|
||||||
|
IEnumerable<int> speedModifiers;
|
||||||
|
|
||||||
[Sync] public int Facing { get; set; }
|
[Sync] public int Facing { get; set; }
|
||||||
[Sync] public WPos CenterPosition { get; private set; }
|
[Sync] public WPos CenterPosition { get; private set; }
|
||||||
@@ -124,7 +125,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
IsPlane = !info.CanHover;
|
IsPlane = !info.CanHover;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Created(Actor self) { um = self.TraitOrDefault<UpgradeManager>(); }
|
public void Created(Actor self)
|
||||||
|
{
|
||||||
|
um = self.TraitOrDefault<UpgradeManager>();
|
||||||
|
speedModifiers = self.TraitsImplementing<ISpeedModifier>().ToArray().Select(sm => sm.GetSpeedModifier());
|
||||||
|
}
|
||||||
|
|
||||||
public void AddedToWorld(Actor self)
|
public void AddedToWorld(Actor self)
|
||||||
{
|
{
|
||||||
@@ -183,17 +188,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (altitude != Info.CruiseAltitude.Length)
|
if (altitude != Info.CruiseAltitude.Length)
|
||||||
return WVec.Zero;
|
return WVec.Zero;
|
||||||
|
|
||||||
var repulsionForce = self.World.FindActorsInCircle(self.CenterPosition, Info.IdealSeparation)
|
// PERF: Avoid LINQ.
|
||||||
.Where(a =>
|
var repulsionForce = WVec.Zero;
|
||||||
|
foreach (var actor in self.World.FindActorsInCircle(self.CenterPosition, Info.IdealSeparation))
|
||||||
{
|
{
|
||||||
if (a.IsDead)
|
if (actor.IsDead)
|
||||||
return false;
|
continue;
|
||||||
|
|
||||||
var ai = a.Info.TraitInfoOrDefault<AircraftInfo>();
|
var ai = actor.Info.TraitInfoOrDefault<AircraftInfo>();
|
||||||
return ai != null && ai.Repulsable && ai.CruiseAltitude == Info.CruiseAltitude;
|
if (ai == null || !ai.Repulsable || ai.CruiseAltitude != Info.CruiseAltitude)
|
||||||
})
|
continue;
|
||||||
.Select(GetRepulsionForce)
|
|
||||||
.Aggregate(WVec.Zero, (a, b) => a + b);
|
repulsionForce += GetRepulsionForce(actor);
|
||||||
|
}
|
||||||
|
|
||||||
if (Info.CanHover)
|
if (Info.CanHover)
|
||||||
return repulsionForce;
|
return repulsionForce;
|
||||||
@@ -279,12 +286,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public int MovementSpeed
|
public int MovementSpeed
|
||||||
{
|
{
|
||||||
get
|
get { return Util.ApplyPercentageModifiers(Info.Speed, speedModifiers); }
|
||||||
{
|
|
||||||
var modifiers = self.TraitsImplementing<ISpeedModifier>()
|
|
||||||
.Select(m => m.GetSpeedModifier());
|
|
||||||
return Util.ApplyPercentageModifiers(Info.Speed, modifiers);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return NoCells; }
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return NoCells; }
|
||||||
|
|||||||
Reference in New Issue
Block a user