Revert renderable buffer sorting improvements
This commit is contained in:
@@ -133,28 +133,8 @@ namespace OpenRA.Graphics
|
|||||||
foreach (var e in World.ScreenMap.RenderableEffectsInBox(Viewport.TopLeft, Viewport.BottomRight))
|
foreach (var e in World.ScreenMap.RenderableEffectsInBox(Viewport.TopLeft, Viewport.BottomRight))
|
||||||
renderablesBuffer.AddRange(e.Render(this));
|
renderablesBuffer.AddRange(e.Render(this));
|
||||||
|
|
||||||
renderablesBuffer.Sort((a, b) =>
|
// Renderables must be ordered using a stable sorting algorithm to avoid flickering artefacts
|
||||||
{
|
foreach (var renderable in renderablesBuffer.OrderBy(RenderableZPositionComparisonKey))
|
||||||
// Sort is an unstable sort, so elements with the same Z position may get sorted differently each frame.
|
|
||||||
// This leads to flickering when rendering several frames as the elements get swapped at random.
|
|
||||||
// To combat this, use a series of arbitrary tie-breaks to determine the "top-most" element.
|
|
||||||
// This ensures a consistent decision for which one is on top, preventing flicker.
|
|
||||||
var compared = RenderableZPositionComparisonKey(a).CompareTo(RenderableZPositionComparisonKey(b));
|
|
||||||
if (compared != 0)
|
|
||||||
return compared;
|
|
||||||
|
|
||||||
compared = a.Pos.X.CompareTo(b.Pos.X);
|
|
||||||
if (compared != 0)
|
|
||||||
return compared;
|
|
||||||
|
|
||||||
compared = a.Pos.Y.CompareTo(b.Pos.Y);
|
|
||||||
if (compared != 0)
|
|
||||||
return compared;
|
|
||||||
|
|
||||||
return a.Pos.Z.CompareTo(b.Pos.Z);
|
|
||||||
});
|
|
||||||
|
|
||||||
foreach (var renderable in renderablesBuffer)
|
|
||||||
preparedRenderables.Add(renderable.PrepareRender(this));
|
preparedRenderables.Add(renderable.PrepareRender(this));
|
||||||
|
|
||||||
// PERF: Reuse collection to avoid allocations.
|
// PERF: Reuse collection to avoid allocations.
|
||||||
|
|||||||
Reference in New Issue
Block a user