From 7c0d3f4e4007226e23d2c9b39a594c6aedf341f3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 5 Jul 2015 14:07:14 +0100 Subject: [PATCH] Use a HashSet for ResourceLayer dirty cells. --- .../Traits/World/ResourceLayer.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs index 636a76b079..ca19cc7dd6 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits readonly World world; readonly BuildingInfluence buildingInfluence; - readonly List dirty = new List(); + readonly HashSet dirty = new HashSet(); protected readonly CellLayer Content; protected readonly CellLayer RenderContent; @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits public ResourceLayer(Actor self) { world = self.World; - buildingInfluence = world.WorldActor.Trait(); + buildingInfluence = self.Trait(); Content = new CellLayer(world.Map); RenderContent = new CellLayer(world.Map); @@ -102,8 +102,8 @@ namespace OpenRA.Mods.Common.Traits var temp = Content[cell]; temp.Density = Math.Max(density, 1); - RenderContent[cell] = Content[cell] = temp; - UpdateRenderedSprite(cell); + Content[cell] = temp; + dirty.Add(cell); } } } @@ -200,8 +200,7 @@ namespace OpenRA.Mods.Common.Traits cell.Density = Math.Min(cell.Type.Info.MaxDensity, cell.Density + n); Content[p] = cell; - if (!dirty.Contains(p)) - dirty.Add(p); + dirty.Add(p); } public bool IsFull(CPos cell) @@ -223,8 +222,7 @@ namespace OpenRA.Mods.Common.Traits else Content[cell] = c; - if (!dirty.Contains(cell)) - dirty.Add(cell); + dirty.Add(cell); return c.Type; } @@ -239,8 +237,7 @@ namespace OpenRA.Mods.Common.Traits Content[cell] = EmptyCell; 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; }