From 7eab7220ff018b18470d199f3377ad609e177136 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Tue, 18 Aug 2015 21:54:09 +0100 Subject: [PATCH] In CanMoveFreelyInto, check if transient actor checks are needed at the start. When transient actors checks are not needed, all control flows in the method return true. Therefore, we can return true directly in this case. Checking this condition is cheaper than checking for a free sub-cell, so this allows us a faster exit when we don't need to check for transient actors. --- OpenRA.Mods.Common/Traits/Mobile.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index b2f0030907..507136e3a8 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -194,13 +194,15 @@ namespace OpenRA.Mods.Common.Traits // Determines whether the actor is blocked by other Actors public bool CanMoveFreelyInto(World world, Actor self, CPos cell, Actor ignoreActor, CellConditions check) { + if (!check.HasCellCondition(CellConditions.TransientActors)) + return true; + if (SharesCell && world.ActorMap.HasFreeSubCell(cell)) return true; - if (check.HasCellCondition(CellConditions.TransientActors)) - foreach (var otherActor in world.ActorMap.GetUnitsAt(cell)) - if (IsBlockedBy(self, otherActor, ignoreActor, check)) - return false; + foreach (var otherActor in world.ActorMap.GetUnitsAt(cell)) + if (IsBlockedBy(self, otherActor, ignoreActor, check)) + return false; return true; }