Change indexes into tile arrays to be stored as bytes to save memory.

The index value needs only be big enough to handle all defined terrain types. This is a low number so we can save memory by defining it as a byte. This particularly saves memory for the CustomTerrain field in the Map class, which defines a cell layer for the map using tile indexes, so we can reduce the size of that layer 4x as a result.
This commit is contained in:
RoosterDragon
2014-10-03 20:55:00 +01:00
parent 268c63f7df
commit 59b3cd154d
9 changed files with 39 additions and 36 deletions

View File

@@ -121,7 +121,7 @@ namespace OpenRA
[FieldLoader.Ignore] public Lazy<CellLayer<TerrainTile>> MapTiles;
[FieldLoader.Ignore] public Lazy<CellLayer<ResourceTile>> MapResources;
[FieldLoader.Ignore] public CellLayer<int> CustomTerrain;
[FieldLoader.Ignore] public CellLayer<byte> CustomTerrain;
[FieldLoader.Ignore] Lazy<TileSet> cachedTileSet;
[FieldLoader.Ignore] Lazy<Ruleset> rules;
@@ -280,9 +280,9 @@ namespace OpenRA
var br = Map.MapToCell(TileShape, new CPos(Bounds.Right - 1, Bounds.Bottom - 1));
Cells = new CellRegion(TileShape, tl, br);
CustomTerrain = new CellLayer<int>(this);
CustomTerrain = new CellLayer<byte>(this);
foreach (var cell in Cells)
CustomTerrain[cell] = -1;
CustomTerrain[cell] = byte.MaxValue;
}
public Ruleset PreloadRules()
@@ -672,10 +672,10 @@ namespace OpenRA
}
}
public int GetTerrainIndex(CPos cell)
public byte GetTerrainIndex(CPos cell)
{
var custom = CustomTerrain[cell];
return custom != -1 ? custom : cachedTileSet.Value.GetTerrainIndex(MapTiles.Value[cell]);
return custom != byte.MaxValue ? custom : cachedTileSet.Value.GetTerrainIndex(MapTiles.Value[cell]);
}
public TerrainTypeInfo GetTerrainInfo(CPos cell)