Convert some keys users of CellLayer to index via map-coords for efficiency.

This commit is contained in:
RoosterDragon
2014-12-05 20:55:18 +00:00
parent b728deb0e1
commit c37a691c33
11 changed files with 140 additions and 88 deletions

View File

@@ -366,8 +366,8 @@ namespace OpenRA
Cells = new CellRegion(TileShape, tl, br);
CustomTerrain = new CellLayer<byte>(this);
foreach (var cell in Cells)
CustomTerrain[cell] = byte.MaxValue;
foreach (var uv in Cells.MapCoords)
CustomTerrain[uv.X, uv.Y] = byte.MaxValue;
}
public Ruleset PreloadRules()
@@ -597,7 +597,12 @@ namespace OpenRA
public bool Contains(CPos cell)
{
var uv = CellToMap(TileShape, cell);
return Bounds.Contains(uv.X, uv.Y);
return Contains(uv.X, uv.Y);
}
public bool Contains(int u, int v)
{
return Bounds.Contains(u, v);
}
public WPos CenterOfCell(CPos cell)
@@ -795,8 +800,11 @@ namespace OpenRA
public byte GetTerrainIndex(CPos cell)
{
var custom = CustomTerrain[cell];
return custom != byte.MaxValue ? custom : cachedTileSet.Value.GetTerrainIndex(MapTiles.Value[cell]);
var uv = Map.CellToMap(TileShape, cell);
var u = uv.X;
var v = uv.Y;
var custom = CustomTerrain[u, v];
return custom != byte.MaxValue ? custom : cachedTileSet.Value.GetTerrainIndex(MapTiles.Value[u, v]);
}
public TerrainTypeInfo GetTerrainInfo(CPos cell)