From 8d3f53ba13306209eaef2446c96844085b5ff2aa Mon Sep 17 00:00:00 2001 From: PopSlime Date: Thu, 20 Mar 2025 21:49:28 +0800 Subject: [PATCH] perf: Improve performance for line renderer --- Assets/Cryville.EEW.Unity/Map/LineRenderer.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Assets/Cryville.EEW.Unity/Map/LineRenderer.cs b/Assets/Cryville.EEW.Unity/Map/LineRenderer.cs index 6191f57..a4ca510 100644 --- a/Assets/Cryville.EEW.Unity/Map/LineRenderer.cs +++ b/Assets/Cryville.EEW.Unity/Map/LineRenderer.cs @@ -150,12 +150,8 @@ namespace Cryville.EEW.Unity.Map { _mesh.Clear(); if (_positions == null) return; if (_positionCount <= 1) return; - float hw = m_width / 2; - int maxVertexCount = 4 * (_positionCount - 1); - var vbuf = ArrayPool.Shared.Rent(maxVertexCount); - var ubuf = ArrayPool.Shared.Rent(maxVertexCount); - var ibuf = ArrayPool.Shared.Rent(3 * (2 + 4 * (_positionCount - 2))); + float hw = m_width / 2; int i, vi = 0, ii = 0, li = 0, ri = 1; float uvScale = 1 / (m_tilingScale * m_width); Vector2 p0 = _positions[0], p1 = default; @@ -163,6 +159,12 @@ namespace Cryville.EEW.Unity.Map { if ((p1 = _positions[i]) != p0) break; } if (i >= _positionCount) return; + + int maxVertexCount = 4 * (_positionCount - 1); + var vbuf = ArrayPool.Shared.Rent(maxVertexCount); + var ubuf = ArrayPool.Shared.Rent(maxVertexCount); + var ibuf = ArrayPool.Shared.Rent(3 * (2 + 4 * (_positionCount - 2))); + Vector2 dp0 = NormalizeSmallVector(p1 - p0), np0 = GetNormal(dp0 * hw); vbuf[vi] = p0 - np0; ubuf[vi++] = new(0, 0); vbuf[vi] = p0 + np0; ubuf[vi++] = new(0, 1);