From edc73f2df8050ecffed376bb270a47dcf94758a3 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 8 May 2010 21:43:09 +1200 Subject: [PATCH] zOMG perf --- OpenRA.Editor/Surface.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index 20e8350115..5624c50001 100644 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -63,17 +63,21 @@ namespace OpenRA.Editor for( var u = 0; u < template.Size.X; u++ ) for (var v = 0; v < template.Size.Y; v++) { - var z = u + v * template.Size.X; - if (template.TerrainType.ContainsKey(z)) - Map.MapTiles[u + pos.X, v + pos.Y] = - new TileReference { type = Brush.First, image = (byte)z, index = (byte)z }; + if (Map.IsInMap(new int2(u, v) + pos)) + { + var z = u + v * template.Size.X; + if (template.TerrainType.ContainsKey(z)) + Map.MapTiles[u + pos.X, v + pos.Y] = + new TileReference { type = Brush.First, image = (byte)z, index = (byte)z }; + + var ch = new int2( (pos.X + u) / ChunkSize, (pos.Y + v) / ChunkSize); + if (Chunks.ContainsKey(ch)) + { + Chunks[ch].Dispose(); + Chunks.Remove(ch); + } + } } - - // invalidate tiles that were involved. - - // todo: do this properly. - foreach (var v in Chunks.Values) v.Dispose(); - Chunks.Clear(); } Invalidate();