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

@@ -70,6 +70,7 @@ namespace OpenRA.Mods.Common.Traits
readonly HarvesterInfo info;
readonly Mobile mobile;
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
bool idleSmart = true;
[Sync] public Actor OwnerLinkedProc = null;
[Sync] public Actor LastLinkedProc = null;
@@ -77,8 +78,17 @@ namespace OpenRA.Mods.Common.Traits
[Sync] int currentUnloadTicks;
public CPos? LastHarvestedCell = null;
public CPos? LastOrderLocation = null;
[Sync] public int ContentValue { get { return contents.Sum(c => c.Key.ValuePerUnit * c.Value); } }
bool idleSmart = true;
[Sync]
public int ContentValue
{
get
{
var value = 0;
foreach (var c in contents)
value += c.Key.ValuePerUnit * c.Value;
return value;
}
}
public Harvester(Actor self, HarvesterInfo info)
{