Reduce allocations in the main game loop.

- Cache the shroud projection even for flat maps to avoid allocating single element arrays.
- Avoid LINQ in shroud and map projection queries to avoid enumerator allocations.
- Avoid LINQ in calculation of sync values.
- Cache enumerables in ProductionQueue.
- Cache delegate in HackyAI.
This commit is contained in:
RoosterDragon
2015-08-12 23:45:11 +01:00
parent 1e817fad76
commit d415d3ba4e
7 changed files with 105 additions and 65 deletions

View File

@@ -40,7 +40,17 @@ namespace OpenRA.Mods.Common.Traits
public class RepairableBuilding : UpgradableTrait<RepairableBuildingInfo>, ITick
{
[Sync]
public int RepairersHash { get { return Repairers.Aggregate(0, (code, player) => code ^ Sync.HashPlayer(player)); } }
public int RepairersHash
{
get
{
var hash = 0;
foreach (var player in Repairers)
hash ^= Sync.HashPlayer(player);
return hash;
}
}
public readonly List<Player> Repairers = new List<Player>();
readonly Health health;
@@ -94,7 +104,9 @@ namespace OpenRA.Mods.Common.Traits
Repairers.RemoveAll(isNotActiveAlly);
// If after the previous operation there's no repairers left, stop
if (!Repairers.Any()) return;
if (Repairers.Count == 0)
return;
var buildingValue = self.GetSellValue();
// The cost is the same regardless of the amount of people repairing