HashSet<byte> => BitArray resourceTypeIndices
BitArray can store 256 bits in 32 bytes plus overhead (pointer & length), which gives it better memory locality too (<= 2 locations in memory). Also, the actual count will be much less, probably at most around a dozen. This might not impact performance, but the AI is dumb & HashSet<byte> is clearly inefficient.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common;
|
||||
@@ -158,7 +159,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
bool enabled;
|
||||
int ticks;
|
||||
|
||||
HashSet<byte> resourceTypeIndices;
|
||||
BitArray resourceTypeIndices;
|
||||
|
||||
RushFuzzy rushFuzzy = new RushFuzzy();
|
||||
|
||||
@@ -208,10 +209,9 @@ namespace OpenRA.Mods.RA.AI
|
||||
|
||||
random = new MersenneTwister((int)p.PlayerActor.ActorID);
|
||||
|
||||
resourceTypeIndices = new HashSet<byte>(
|
||||
Map.Rules.Actors["world"].Traits
|
||||
.WithInterface<ResourceTypeInfo>()
|
||||
.Select(t => world.TileSet.GetTerrainIndex(t.TerrainType)));
|
||||
resourceTypeIndices = new BitArray(world.TileSet.TerrainInfo.Length); // Big enough
|
||||
foreach (var t in Map.Rules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>())
|
||||
resourceTypeIndices.Set(world.TileSet.GetTerrainIndex(t.TerrainType), true);
|
||||
}
|
||||
|
||||
ActorInfo ChooseRandomUnitToBuild(ProductionQueue queue)
|
||||
@@ -371,7 +371,7 @@ namespace OpenRA.Mods.RA.AI
|
||||
|
||||
// Try and place the refinery near a resource field
|
||||
var nearbyResources = Map.FindTilesInCircle(baseCenter, Info.MaxBaseRadius)
|
||||
.Where(a => resourceTypeIndices.Contains(Map.GetTerrainIndex(a)))
|
||||
.Where(a => resourceTypeIndices.Get(Map.GetTerrainIndex(a)))
|
||||
.Shuffle(random);
|
||||
|
||||
foreach (var c in nearbyResources)
|
||||
|
||||
Reference in New Issue
Block a user