From c24398e32c180f2374abb4726ccb2f80002d9ced Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sat, 4 May 2019 12:11:21 +0200 Subject: [PATCH] Repulsion performance optimizations `cruising` is updated on every position change, so we can safely re-use it instead of performing another DAT check. Additionally, if repulsion force is horizontally zero, it's guaranteed to be WVec.Zero, so we can save that conversion too. --- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index a9f1fbf3cb..098470f514 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -350,7 +350,7 @@ namespace OpenRA.Mods.Common.Traits public void Repulse() { var repulsionForce = GetRepulsionForce(); - if (repulsionForce.HorizontalLengthSquared == 0) + if (repulsionForce == WVec.Zero) return; var speed = Info.RepulsionSpeed != -1 ? Info.RepulsionSpeed : MovementSpeed; @@ -369,9 +369,8 @@ namespace OpenRA.Mods.Common.Traits return WVec.Zero; } - // Repulsion only applies when we're flying! - var altitude = self.World.Map.DistanceAboveTerrain(CenterPosition).Length; - if (altitude != Info.CruiseAltitude.Length) + // Repulsion only applies when we're flying at CruiseAltitude! + if (!cruising) return WVec.Zero; // PERF: Avoid LINQ. @@ -1038,6 +1037,7 @@ namespace OpenRA.Mods.Common.Traits { if (!cruising) return; + cruising = false; if (conditionManager != null && cruisingToken != ConditionManager.InvalidConditionToken) cruisingToken = conditionManager.RevokeCondition(self, cruisingToken);