diff --git a/OpenRA.Game/Graphics/RgbaColorRenderer.cs b/OpenRA.Game/Graphics/RgbaColorRenderer.cs index 71efd67086..23b5d1bec1 100644 --- a/OpenRA.Game/Graphics/RgbaColorRenderer.cs +++ b/OpenRA.Game/Graphics/RgbaColorRenderer.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; namespace OpenRA.Graphics { @@ -113,6 +114,23 @@ namespace OpenRA.Graphics return new float2(x, y) / d; } + void DrawDisconnectedLine(IEnumerable points, float width, Color color) + { + using (var e = points.GetEnumerator()) + { + if (!e.MoveNext()) + return; + + var lastPoint = e.Current; + while (e.MoveNext()) + { + var point = e.Current; + DrawLine(lastPoint, point, width, color); + lastPoint = point; + } + } + } + void DrawConnectedLine(float2[] points, float width, Color color, bool closed) { // Not a line @@ -184,18 +202,12 @@ namespace OpenRA.Graphics } } - public void DrawLine(float2[] points, float width, Color color, bool connectSegments = false) + public void DrawLine(IEnumerable points, float width, Color color, bool connectSegments = false) { if (!connectSegments) - { - if (points.Length < 2) - return; - - for (var i = 1; i < points.Length; i++) - DrawLine(points[i - 1], points[i], width, color); - } + DrawDisconnectedLine(points, width, color); else - DrawConnectedLine(points, width, color, false); + DrawConnectedLine(points as float2[] ?? points.ToArray(), width, color, false); } public void DrawPolygon(float2[] vertices, float width, Color color) diff --git a/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs b/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs index f79ca19c66..06cb7bd51d 100644 --- a/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs +++ b/OpenRA.Mods.Common/Widgets/LineGraphWidget.cs @@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Widgets lastX = x; lastPoint = point; return origin + new float2(x * xStep, -point * scale); - }).ToArray(), 1, color); + }), 1, color); if (lastPoint != 0f) tiny.DrawText(GetValueFormat().F(lastPoint), origin + new float2(lastX * xStep, -lastPoint * scale - 2), color); diff --git a/OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs b/OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs index 483bfd199f..7d4e075877 100644 --- a/OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs +++ b/OpenRA.Mods.Common/Widgets/PerfGraphWidget.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Widgets foreach (var item in PerfHistory.Items.Values) { cr.DrawLine(item.Samples() - .Select((sample, i) => origin + new float2(i, (float)sample) * basis).ToArray(), + .Select((sample, i) => origin + new float2(i, (float)sample) * basis), 1, item.C); var u = new float2(rect.Left, rect.Top);