Added comments in performance sensitive code.

This commit is contained in:
RoosterDragon
2015-12-04 19:38:20 +00:00
parent aaa82339d1
commit b0619a3e25
22 changed files with 76 additions and 11 deletions

View File

@@ -33,6 +33,7 @@ namespace OpenRA.Mods.Common.Traits
{
public static bool HasCellCondition(this CellConditions c, CellConditions cellCondition)
{
// PERF: Enum.HasFlag is slower and requires allocations.
return (c & cellCondition) == cellCondition;
}
}
@@ -132,6 +133,8 @@ namespace OpenRA.Mods.Common.Traits
internal readonly TerrainInfo[] TerrainInfos;
internal WorldMovementInfo(World world, MobileInfo info)
{
// PERF: This struct allows us to cache the terrain info for the tileset used by the world.
// This allows us to speed up some performance-sensitive pathfinding calculations.
World = world;
TerrainInfos = info.TilesetTerrainInfo[world.TileSet];
}
@@ -217,6 +220,7 @@ namespace OpenRA.Mods.Common.Traits
if (SharesCell && world.ActorMap.HasFreeSubCell(cell))
return true;
// PERF: Avoid LINQ.
foreach (var otherActor in world.ActorMap.GetActorsAt(cell))
if (IsBlockedBy(self, otherActor, ignoreActor, check))
return false;
@@ -242,6 +246,7 @@ namespace OpenRA.Mods.Common.Traits
return true;
// If the other actor in our way cannot be crushed, we are blocked.
// PERF: Avoid LINQ.
var crushables = otherActor.TraitsImplementing<ICrushable>();
var lacksCrushability = true;
foreach (var crushable in crushables)

View File

@@ -114,6 +114,7 @@ namespace OpenRA.Mods.Common.Traits
}
else
{
// PERF: Minimize lookup cost by combining all state into one, and using an array rather than a dictionary.
var state = stateByPlayerIndex[i];
frozenActor = state.FrozenActor;
isVisible = !frozenActor.Visible;

View File

@@ -48,6 +48,7 @@ namespace OpenRA.Mods.Common.Traits
public override void Tick(Actor self)
{
// PERF: Avoid LINQ.
isActive = false;
foreach (var x in self.World.ActorsWithTrait<Production>())
{

View File

@@ -226,6 +226,8 @@ namespace OpenRA.Mods.Common.Traits
void DirtyCells(IEnumerable<PPos> cells)
{
// PERF: Many cells in the shroud change every tick. We only track the changes here and defer the real work
// we need to do until we render. This allows us to avoid wasted work.
cellsDirty.UnionWith(cells);
}