Change terrain type from string based dictionaries to arrays

This commit is contained in:
Pavlos Touboulidis
2014-05-25 15:46:36 +03:00
parent b8cdb224d1
commit 092352729f
23 changed files with 265 additions and 137 deletions

View File

@@ -59,10 +59,6 @@ namespace OpenRA.Mods.RA
int[,] domains;
Dictionary<int, HashSet<int>> transientConnections;
// Each terrain has an offset corresponding to its location in a
// movement class bitmask. This caches each offset.
Dictionary<string, int> terrainOffsets;
public MovementClassDomainIndex(World world, uint movementClass)
{
bounds = world.Map.Bounds;
@@ -70,14 +66,6 @@ namespace OpenRA.Mods.RA
domains = new int[(bounds.Width + bounds.X), (bounds.Height + bounds.Y)];
transientConnections = new Dictionary<int, HashSet<int>>();
terrainOffsets = new Dictionary<string, int>();
var terrains = world.TileSet.Terrain.OrderBy(t => t.Key).ToList();
foreach (var terrain in terrains)
{
var terrainOffset = terrains.FindIndex(x => x.Key == terrain.Key);
terrainOffsets[terrain.Key] = terrainOffset;
}
BuildDomains(world);
}
@@ -181,8 +169,7 @@ namespace OpenRA.Mods.RA
bool CanTraverseTile(World world, CPos p)
{
var currentTileType = WorldUtils.GetTerrainType(world, p);
var terrainOffset = terrainOffsets[currentTileType];
var terrainOffset = world.GetTerrainIndex(p);
return (movementClass & (1 << terrainOffset)) > 0;
}