Use a HashSet for ResourceLayer dirty cells.

This commit is contained in:
Paul Chote
2015-07-05 14:07:14 +01:00
parent f93ad2a9c1
commit 7c0d3f4e40

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
readonly World world; readonly World world;
readonly BuildingInfluence buildingInfluence; readonly BuildingInfluence buildingInfluence;
readonly List<CPos> dirty = new List<CPos>(); readonly HashSet<CPos> dirty = new HashSet<CPos>();
protected readonly CellLayer<CellContents> Content; protected readonly CellLayer<CellContents> Content;
protected readonly CellLayer<CellContents> RenderContent; protected readonly CellLayer<CellContents> RenderContent;
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
public ResourceLayer(Actor self) public ResourceLayer(Actor self)
{ {
world = self.World; world = self.World;
buildingInfluence = world.WorldActor.Trait<BuildingInfluence>(); buildingInfluence = self.Trait<BuildingInfluence>();
Content = new CellLayer<CellContents>(world.Map); Content = new CellLayer<CellContents>(world.Map);
RenderContent = new CellLayer<CellContents>(world.Map); RenderContent = new CellLayer<CellContents>(world.Map);
@@ -102,8 +102,8 @@ namespace OpenRA.Mods.Common.Traits
var temp = Content[cell]; var temp = Content[cell];
temp.Density = Math.Max(density, 1); temp.Density = Math.Max(density, 1);
RenderContent[cell] = Content[cell] = temp; Content[cell] = temp;
UpdateRenderedSprite(cell); dirty.Add(cell);
} }
} }
} }
@@ -200,8 +200,7 @@ namespace OpenRA.Mods.Common.Traits
cell.Density = Math.Min(cell.Type.Info.MaxDensity, cell.Density + n); cell.Density = Math.Min(cell.Type.Info.MaxDensity, cell.Density + n);
Content[p] = cell; Content[p] = cell;
if (!dirty.Contains(p)) dirty.Add(p);
dirty.Add(p);
} }
public bool IsFull(CPos cell) public bool IsFull(CPos cell)
@@ -223,8 +222,7 @@ namespace OpenRA.Mods.Common.Traits
else else
Content[cell] = c; Content[cell] = c;
if (!dirty.Contains(cell)) dirty.Add(cell);
dirty.Add(cell);
return c.Type; return c.Type;
} }
@@ -239,8 +237,7 @@ namespace OpenRA.Mods.Common.Traits
Content[cell] = EmptyCell; Content[cell] = EmptyCell;
world.Map.CustomTerrain[cell] = byte.MaxValue; world.Map.CustomTerrain[cell] = byte.MaxValue;
if (!dirty.Contains(cell)) dirty.Add(cell);
dirty.Add(cell);
} }
public ResourceType GetResource(CPos cell) { return Content[cell].Type; } public ResourceType GetResource(CPos cell) { return Content[cell].Type; }