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
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common;
|
using OpenRA.Mods.Common;
|
||||||
@@ -158,7 +159,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
bool enabled;
|
bool enabled;
|
||||||
int ticks;
|
int ticks;
|
||||||
|
|
||||||
HashSet<byte> resourceTypeIndices;
|
BitArray resourceTypeIndices;
|
||||||
|
|
||||||
RushFuzzy rushFuzzy = new RushFuzzy();
|
RushFuzzy rushFuzzy = new RushFuzzy();
|
||||||
|
|
||||||
@@ -208,10 +209,9 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
|
|
||||||
random = new MersenneTwister((int)p.PlayerActor.ActorID);
|
random = new MersenneTwister((int)p.PlayerActor.ActorID);
|
||||||
|
|
||||||
resourceTypeIndices = new HashSet<byte>(
|
resourceTypeIndices = new BitArray(world.TileSet.TerrainInfo.Length); // Big enough
|
||||||
Map.Rules.Actors["world"].Traits
|
foreach (var t in Map.Rules.Actors["world"].Traits.WithInterface<ResourceTypeInfo>())
|
||||||
.WithInterface<ResourceTypeInfo>()
|
resourceTypeIndices.Set(world.TileSet.GetTerrainIndex(t.TerrainType), true);
|
||||||
.Select(t => world.TileSet.GetTerrainIndex(t.TerrainType)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorInfo ChooseRandomUnitToBuild(ProductionQueue queue)
|
ActorInfo ChooseRandomUnitToBuild(ProductionQueue queue)
|
||||||
@@ -371,7 +371,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
|
|
||||||
// Try and place the refinery near a resource field
|
// Try and place the refinery near a resource field
|
||||||
var nearbyResources = Map.FindTilesInCircle(baseCenter, Info.MaxBaseRadius)
|
var nearbyResources = Map.FindTilesInCircle(baseCenter, Info.MaxBaseRadius)
|
||||||
.Where(a => resourceTypeIndices.Contains(Map.GetTerrainIndex(a)))
|
.Where(a => resourceTypeIndices.Get(Map.GetTerrainIndex(a)))
|
||||||
.Shuffle(random);
|
.Shuffle(random);
|
||||||
|
|
||||||
foreach (var c in nearbyResources)
|
foreach (var c in nearbyResources)
|
||||||
|
|||||||
Reference in New Issue
Block a user