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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user