Avoid allocations when generating RadarSignatureCells.

The RadarWidget can supply a reusable buffer to each trait to avoid individual traits having to return new enumerables. Additionally, this allows the two traits to avoid LINQ and further allocations as they can manually enumerate and populate the buffer themselves.
This commit is contained in:
RoosterDragon
2017-11-23 19:00:28 +00:00
committed by abcdefg30
parent c69df4eedf
commit 0899d02377
4 changed files with 17 additions and 17 deletions

View File

@@ -15,6 +15,7 @@ using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
using OpenRA.Widgets;
@@ -361,6 +362,8 @@ namespace OpenRA.Mods.Common.Widgets
var stride = radarSheet.Size.Width;
Array.Clear(radarData, 4 * actorSprite.Bounds.Top * stride, 4 * actorSprite.Bounds.Height * stride);
var cells = new List<Pair<CPos, Color>>();
unsafe
{
fixed (byte* colorBytes = &radarData[0])
@@ -372,7 +375,9 @@ namespace OpenRA.Mods.Common.Widgets
if (!t.Actor.IsInWorld || world.FogObscures(t.Actor))
continue;
foreach (var cell in t.Trait.RadarSignatureCells(t.Actor))
cells.Clear();
t.Trait.PopulateRadarSignatureCells(t.Actor, cells);
foreach (var cell in cells)
{
if (!world.Map.Contains(cell.First))
continue;