From 3aefd2c3787d24a4b4b82ad367f87e25d596fc2b Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 6 Aug 2023 12:05:23 +0900 Subject: [PATCH] change class RcCompactCell -> readonly struct RcCompactCell --- src/DotRecast.Recast/RcCompactCell.cs | 12 +++++++++--- src/DotRecast.Recast/RecastCompact.cs | 14 ++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/DotRecast.Recast/RcCompactCell.cs b/src/DotRecast.Recast/RcCompactCell.cs index 07be110..befed70 100644 --- a/src/DotRecast.Recast/RcCompactCell.cs +++ b/src/DotRecast.Recast/RcCompactCell.cs @@ -21,12 +21,18 @@ freely, subject to the following restrictions: namespace DotRecast.Recast { /** Provides information on the content of a cell column in a compact heightfield. */ - public class RcCompactCell + public readonly struct RcCompactCell { /** Index to the first span in the column. */ - public int index; + public readonly int index; /** Number of spans in the column. */ - public int count; + public readonly int count; + + public RcCompactCell(int index, int count) + { + this.index = index; + this.count = count; + } } } \ No newline at end of file diff --git a/src/DotRecast.Recast/RecastCompact.cs b/src/DotRecast.Recast/RecastCompact.cs index dffe87d..4085fa7 100644 --- a/src/DotRecast.Recast/RecastCompact.cs +++ b/src/DotRecast.Recast/RecastCompact.cs @@ -64,10 +64,6 @@ namespace DotRecast.Recast chf.cells = new RcCompactCell[w * h]; chf.spans = new RcCompactSpan[spanCount]; chf.areas = new int[spanCount]; - for (int i = 0; i < chf.cells.Length; i++) - { - chf.cells[i] = new RcCompactCell(); - } for (int i = 0; i < chf.spans.Length; i++) { @@ -84,9 +80,9 @@ namespace DotRecast.Recast // If there are no spans at this cell, just leave the data to index=0, count=0. if (s == null) continue; - RcCompactCell c = chf.cells[x + y * w]; - c.index = idx; - c.count = 0; + + int tmpIdx = idx; + int tmpCount = 0; while (s != null) { if (s.area != RC_NULL_AREA) @@ -97,11 +93,13 @@ namespace DotRecast.Recast chf.spans[idx].h = Clamp(top - bot, 0, MAX_HEIGHT); chf.areas[idx] = s.area; idx++; - c.count++; + tmpCount++; } s = s.next; } + + chf.cells[x + y * w] = new RcCompactCell(tmpIdx, tmpCount); } }