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.
This commit is contained in:
RoosterDragon
2015-08-18 21:54:09 +01:00
parent ca75b5af30
commit 7eab7220ff

View File

@@ -194,13 +194,15 @@ namespace OpenRA.Mods.Common.Traits
// Determines whether the actor is blocked by other Actors // Determines whether the actor is blocked by other Actors
public bool CanMoveFreelyInto(World world, Actor self, CPos cell, Actor ignoreActor, CellConditions check) 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)) if (SharesCell && world.ActorMap.HasFreeSubCell(cell))
return true; return true;
if (check.HasCellCondition(CellConditions.TransientActors)) foreach (var otherActor in world.ActorMap.GetUnitsAt(cell))
foreach (var otherActor in world.ActorMap.GetUnitsAt(cell)) if (IsBlockedBy(self, otherActor, ignoreActor, check))
if (IsBlockedBy(self, otherActor, ignoreActor, check)) return false;
return false;
return true; return true;
} }