Transparently cache results of GetTerrainIndex in Map.
This method performs an expensive calculation and is called often during pathfinding. We create a cache of the terrain indicies for the map to vastly reduce the cost.
This commit is contained in:
@@ -74,7 +74,7 @@ namespace OpenRA
|
||||
public readonly bool PickAny;
|
||||
public readonly string Category;
|
||||
|
||||
TerrainTileInfo[] tileInfo;
|
||||
readonly TerrainTileInfo[] tileInfo;
|
||||
|
||||
public TerrainTemplateInfo(ushort id, string[] images, int2 size, byte[] tiles)
|
||||
{
|
||||
@@ -177,7 +177,7 @@ namespace OpenRA
|
||||
public readonly bool IgnoreTileSpriteOffsets;
|
||||
|
||||
[FieldLoader.Ignore]
|
||||
public readonly Dictionary<ushort, TerrainTemplateInfo> Templates = new Dictionary<ushort, TerrainTemplateInfo>();
|
||||
public readonly IReadOnlyDictionary<ushort, TerrainTemplateInfo> Templates;
|
||||
|
||||
[FieldLoader.Ignore]
|
||||
public readonly TerrainTypeInfo[] TerrainInfo;
|
||||
@@ -217,7 +217,7 @@ namespace OpenRA
|
||||
|
||||
// Templates
|
||||
Templates = yaml["Templates"].ToDictionary().Values
|
||||
.Select(y => new TerrainTemplateInfo(this, y)).ToDictionary(t => t.Id);
|
||||
.Select(y => new TerrainTemplateInfo(this, y)).ToDictionary(t => t.Id).AsReadOnly();
|
||||
}
|
||||
|
||||
public TileSet(string name, string id, string palette, TerrainTypeInfo[] terrainInfo)
|
||||
|
||||
Reference in New Issue
Block a user