Sort renderables in-place in WorldRenderer.GenerateRenderables

This commit is contained in:
RoosterDragon
2020-10-11 11:54:35 +01:00
committed by abcdefg30
parent 2adee1e374
commit 71e3ca4493
5 changed files with 8 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Graphics
{
public sealed class WorldRenderer : IDisposable
{
public static readonly Func<IRenderable, int> RenderableScreenZPositionComparisonKey =
public static readonly Func<IRenderable, int> RenderableZPositionComparisonKey =
r => ZPosition(r.Pos, r.ZOffset);
public readonly Size TileSize;
@@ -133,7 +133,9 @@ namespace OpenRA.Graphics
foreach (var e in World.ScreenMap.RenderableEffectsInBox(Viewport.TopLeft, Viewport.BottomRight))
renderablesBuffer.AddRange(e.Render(this));
foreach (var renderable in renderablesBuffer.OrderBy(RenderableScreenZPositionComparisonKey))
renderablesBuffer.Sort((x, y) => RenderableZPositionComparisonKey(x).CompareTo(RenderableZPositionComparisonKey(y)));
foreach (var renderable in renderablesBuffer)
preparedRenderables.Add(renderable.PrepareRender(this));
// PERF: Reuse collection to avoid allocations.