Batch shroud cell changes.

By maintaining a set of changed cells we can avoid repeating work for cells that change multiple times before being rendered. The shroud renderer and radar widget now delay their work until they must render, and thus process each changed cell only once. This avoids significant repetition that was causing major slowdown when many actors were in the world.
This commit is contained in:
RoosterDragon
2015-03-23 22:27:02 +00:00
parent 9a780ba07d
commit 1584018dcd
3 changed files with 95 additions and 47 deletions

View File

@@ -9,6 +9,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
@@ -33,6 +34,8 @@ namespace OpenRA.Mods.Common.Widgets
readonly WorldRenderer worldRenderer;
readonly RadarPings radarPings;
readonly HashSet<CPos> dirtyShroudCells = new HashSet<CPos>();
float radarMinimapHeight;
int frame;
bool hasRadar;
@@ -130,6 +133,11 @@ namespace OpenRA.Mods.Common.Widgets
}
}
void MarkShroudDirty(IEnumerable<CPos> cellsChanged)
{
dirtyShroudCells.UnionWith(cellsChanged);
}
public override string GetCursor(int2 pos)
{
if (world == null || !hasRadar)
@@ -194,6 +202,15 @@ namespace OpenRA.Mods.Common.Widgets
if (world == null)
return;
if (renderShroud != null)
{
foreach (var cell in dirtyShroudCells)
UpdateShroudCell(cell);
dirtyShroudCells.Clear();
}
radarSheet.CommitData();
var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight) / 2);
var s = new float2(mapRect.Size.Width, mapRect.Size.Height * radarMinimapHeight);
@@ -255,7 +272,7 @@ namespace OpenRA.Mods.Common.Widgets
if (newRenderShroud != renderShroud)
{
if (renderShroud != null)
renderShroud.CellEntryChanged -= UpdateShroudCell;
renderShroud.CellsChanged -= MarkShroudDirty;
if (newRenderShroud != null)
{
@@ -264,9 +281,11 @@ namespace OpenRA.Mods.Common.Widgets
OpenRA.Graphics.Util.FastCopyIntoSprite(shroudSprite, bitmap);
// Update the notification binding
newRenderShroud.CellEntryChanged += UpdateShroudCell;
newRenderShroud.CellsChanged += MarkShroudDirty;
}
dirtyShroudCells.Clear();
renderShroud = newRenderShroud;
}
@@ -299,8 +318,6 @@ namespace OpenRA.Mods.Common.Widgets
}
}
}
radarSheet.CommitData();
}
var targetFrame = enabled ? AnimationLength : 0;