From bb2041e253063ec670c2da667c0029bb3b328aab Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 7 Nov 2023 22:28:14 +0900 Subject: [PATCH] refactor: added RcCompactSpanBuilder --- src/DotRecast.Recast/RcCompactSpanBuilder.cs | 9 +++++++-- src/DotRecast.Recast/RcCompacts.cs | 14 +++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/DotRecast.Recast/RcCompactSpanBuilder.cs b/src/DotRecast.Recast/RcCompactSpanBuilder.cs index c4ee9bb..00dd583 100644 --- a/src/DotRecast.Recast/RcCompactSpanBuilder.cs +++ b/src/DotRecast.Recast/RcCompactSpanBuilder.cs @@ -9,15 +9,20 @@ public static RcCompactSpanBuilder NewBuilder(ref RcCompactSpan span) { - var builder = new RcCompactSpanBuilder(); + var builder = NewBuilder(); builder.y = span.y; builder.reg = span.reg; builder.con = span.con; builder.h = span.h; return builder; } + + public static RcCompactSpanBuilder NewBuilder() + { + return new RcCompactSpanBuilder(); + } - public RcCompactSpanBuilder() + private RcCompactSpanBuilder() { } diff --git a/src/DotRecast.Recast/RcCompacts.cs b/src/DotRecast.Recast/RcCompacts.cs index 9aa84e1..60a66c5 100644 --- a/src/DotRecast.Recast/RcCompacts.cs +++ b/src/DotRecast.Recast/RcCompacts.cs @@ -69,9 +69,9 @@ namespace DotRecast.Recast //chf.spans = new RcCompactSpan[spanCount]; chf.areas = new int[spanCount]; - var chfSpans = Enumerable + var tempSpans = Enumerable .Range(0, spanCount) - .Select(x => new RcCompactSpanBuilder()) + .Select(x => RcCompactSpanBuilder.NewBuilder()) .ToArray(); // Fill in cells and spans. @@ -93,8 +93,8 @@ namespace DotRecast.Recast { int bot = s.smax; int top = s.next != null ? (int)s.next.smin : MAX_HEIGHT; - chfSpans[idx].y = Math.Clamp(bot, 0, MAX_HEIGHT); - chfSpans[idx].h = Math.Clamp(top - bot, 0, MAX_HEIGHT); + tempSpans[idx].y = Math.Clamp(bot, 0, MAX_HEIGHT); + tempSpans[idx].h = Math.Clamp(top - bot, 0, MAX_HEIGHT); chf.areas[idx] = s.area; idx++; tmpCount++; @@ -116,7 +116,7 @@ namespace DotRecast.Recast ref RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { - ref RcCompactSpanBuilder s = ref chfSpans[i]; + ref RcCompactSpanBuilder s = ref tempSpans[i]; for (int dir = 0; dir < 4; ++dir) { @@ -132,7 +132,7 @@ namespace DotRecast.Recast ref RcCompactCell nc = ref chf.cells[nx + ny * w]; for (int k = nc.index, nk = nc.index + nc.count; k < nk; ++k) { - ref RcCompactSpanBuilder ns = ref chfSpans[k]; + ref RcCompactSpanBuilder ns = ref tempSpans[k]; int bot = Math.Max(s.y, ns.y); int top = Math.Min(s.y + s.h, ns.y + ns.h); @@ -163,7 +163,7 @@ namespace DotRecast.Recast + " (max: " + MAX_LAYERS + ")"); } - chf.spans = chfSpans.Select(x => x.Build()).ToArray(); + chf.spans = tempSpans.Select(x => x.Build()).ToArray(); return chf; }