From 5b2e9591c2e138e07243b475c16222a8cbfddfc8 Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 2 Nov 2023 00:11:54 +0900 Subject: [PATCH] refactor: use ref readonly RcCompactCell c = ref ... --- .../Draw/RecastDebugDraw.cs | 6 ++-- src/DotRecast.Recast/RcAreas.cs | 14 +++++----- src/DotRecast.Recast/RcCompacts.cs | 4 +-- src/DotRecast.Recast/RcContours.cs | 8 +++--- src/DotRecast.Recast/RcLayers.cs | 8 +++--- src/DotRecast.Recast/RcMeshDetails.cs | 4 +-- src/DotRecast.Recast/RcRegions.cs | 28 +++++++++---------- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs index 1f99bb0..43c7523 100644 --- a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs @@ -486,7 +486,7 @@ public class RecastDebugDraw : DebugDraw { float fx = chf.bmin.X + x * cs; float fz = chf.bmin.Z + y * cs; - RcCompactCell c = chf.cells[x + y * chf.width]; + ref readonly RcCompactCell c = ref chf.cells[x + y * chf.width]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { @@ -859,7 +859,7 @@ public class RecastDebugDraw : DebugDraw { float fx = chf.bmin.X + x * cs; float fz = chf.bmin.Z + y * cs; - RcCompactCell c = chf.cells[x + y * chf.width]; + ref readonly RcCompactCell c = ref chf.cells[x + y * chf.width]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { @@ -912,7 +912,7 @@ public class RecastDebugDraw : DebugDraw { float fx = chf.bmin.X + x * cs; float fz = chf.bmin.Z + y * cs; - RcCompactCell c = chf.cells[x + y * chf.width]; + ref readonly RcCompactCell c = ref chf.cells[x + y * chf.width]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { diff --git a/src/DotRecast.Recast/RcAreas.cs b/src/DotRecast.Recast/RcAreas.cs index e230359..6597383 100644 --- a/src/DotRecast.Recast/RcAreas.cs +++ b/src/DotRecast.Recast/RcAreas.cs @@ -60,7 +60,7 @@ namespace DotRecast.Recast { for (int x = 0; x < xSize; ++x) { - RcCompactCell cell = compactHeightfield.cells[x + z * zStride]; + ref readonly RcCompactCell cell = ref compactHeightfield.cells[x + z * zStride]; for (int spanIndex = cell.index, maxSpanIndex = cell.index + cell.count; spanIndex < maxSpanIndex; ++spanIndex) { if (compactHeightfield.areas[spanIndex] == RC_NULL_AREA) @@ -109,7 +109,7 @@ namespace DotRecast.Recast { for (int x = 0; x < xSize; ++x) { - RcCompactCell cell = compactHeightfield.cells[x + z * zStride]; + ref readonly RcCompactCell cell = ref compactHeightfield.cells[x + z * zStride]; int maxSpanIndex = cell.index + cell.count; for (int spanIndex = cell.index; spanIndex < maxSpanIndex; ++spanIndex) { @@ -177,7 +177,7 @@ namespace DotRecast.Recast { for (int x = xSize - 1; x >= 0; --x) { - RcCompactCell cell = compactHeightfield.cells[x + z * zStride]; + ref readonly RcCompactCell cell = ref compactHeightfield.cells[x + z * zStride]; int maxSpanIndex = cell.index + cell.count; for (int i = cell.index; i < maxSpanIndex; ++i) { @@ -275,7 +275,7 @@ namespace DotRecast.Recast { for (int x = 0; x < xSize; ++x) { - RcCompactCell cell = compactHeightfield.cells[x + z * zStride]; + ref readonly RcCompactCell cell = ref compactHeightfield.cells[x + z * zStride]; int maxSpanIndex = cell.index + cell.count; for (int spanIndex = cell.index; spanIndex < maxSpanIndex; ++spanIndex) { @@ -404,7 +404,7 @@ namespace DotRecast.Recast { for (int x = minX; x <= maxX; ++x) { - RcCompactCell cell = compactHeightfield.cells[x + z * zStride]; + ref readonly RcCompactCell cell = ref compactHeightfield.cells[x + z * zStride]; int maxSpanIndex = cell.index + cell.count; for (int spanIndex = cell.index; spanIndex < maxSpanIndex; ++spanIndex) { @@ -523,7 +523,7 @@ namespace DotRecast.Recast { for (int x = minx; x <= maxx; ++x) { - RcCompactCell cell = compactHeightfield.cells[x + z * zStride]; + ref readonly RcCompactCell cell = ref compactHeightfield.cells[x + z * zStride]; int maxSpanIndex = cell.index + cell.count; for (int spanIndex = cell.index; spanIndex < maxSpanIndex; ++spanIndex) { @@ -644,7 +644,7 @@ namespace DotRecast.Recast { for (int x = minx; x <= maxx; ++x) { - RcCompactCell cell = compactHeightfield.cells[x + z * zStride]; + ref readonly RcCompactCell cell = ref compactHeightfield.cells[x + z * zStride]; int maxSpanIndex = cell.index + cell.count; float cellX = compactHeightfield.bmin.X + ((float)x + 0.5f) * compactHeightfield.cs; diff --git a/src/DotRecast.Recast/RcCompacts.cs b/src/DotRecast.Recast/RcCompacts.cs index d53eae0..426b511 100644 --- a/src/DotRecast.Recast/RcCompacts.cs +++ b/src/DotRecast.Recast/RcCompacts.cs @@ -112,7 +112,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { RcCompactSpan s = chf.spans[i]; @@ -128,7 +128,7 @@ namespace DotRecast.Recast // Iterate over all neighbour spans and check if any of the is // accessible from current cell. - RcCompactCell nc = chf.cells[nx + ny * w]; + ref readonly RcCompactCell nc = ref chf.cells[nx + ny * w]; for (int k = nc.index, nk = nc.index + nc.count; k < nk; ++k) { RcCompactSpan ns = chf.spans[k]; diff --git a/src/DotRecast.Recast/RcContours.cs b/src/DotRecast.Recast/RcContours.cs index 055e168..af5bb56 100644 --- a/src/DotRecast.Recast/RcContours.cs +++ b/src/DotRecast.Recast/RcContours.cs @@ -177,7 +177,7 @@ namespace DotRecast.Recast RcCompactSpan s = chf.spans[i]; if (GetCon(s, dir) != RC_NOT_CONNECTED) { - RcCompactCell nc = chf.cells[nx + ny * chf.width]; + ref readonly RcCompactCell nc = ref chf.cells[nx + ny * chf.width]; ni = nc.index + GetCon(s, dir); } @@ -660,7 +660,7 @@ namespace DotRecast.Recast { int dx = outline.verts[j * 4 + 0] - hole.verts[corner + 0]; int dz = outline.verts[j * 4 + 2] - hole.verts[corner + 2]; - diags[ndiags] = new RcPotentialDiagonal(j, dx * dx + dz * dz); + diags[ndiags] = new RcPotentialDiagonal(j, dx * dx + dz * dz); ndiags++; } } @@ -753,7 +753,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { int res = 0; @@ -793,7 +793,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { if (flags[i] == 0 || flags[i] == 0xf) diff --git a/src/DotRecast.Recast/RcLayers.cs b/src/DotRecast.Recast/RcLayers.cs index 1073794..dd6ee8e 100644 --- a/src/DotRecast.Recast/RcLayers.cs +++ b/src/DotRecast.Recast/RcLayers.cs @@ -80,7 +80,7 @@ namespace DotRecast.Recast for (int x = borderSize; x < w - borderSize; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { @@ -165,7 +165,7 @@ namespace DotRecast.Recast // Remap local sweep ids to region ids. for (int x = borderSize; x < w - borderSize; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { if (srcReg[i] != 0xff) @@ -189,7 +189,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; lregs.Clear(); @@ -475,7 +475,7 @@ namespace DotRecast.Recast { int cx = borderSize + x; int cy = borderSize + y; - RcCompactCell c = chf.cells[cx + cy * w]; + ref readonly RcCompactCell c = ref chf.cells[cx + cy * w]; for (int j = c.index, nj = c.index + c.count; j < nj; ++j) { RcCompactSpan s = chf.spans[j]; diff --git a/src/DotRecast.Recast/RcMeshDetails.cs b/src/DotRecast.Recast/RcMeshDetails.cs index 5ad3106..1c12486 100644 --- a/src/DotRecast.Recast/RcMeshDetails.cs +++ b/src/DotRecast.Recast/RcMeshDetails.cs @@ -1131,7 +1131,7 @@ namespace DotRecast.Recast continue; } - RcCompactCell c = chf.cells[(ax + bs) + (az + bs) * chf.width]; + ref readonly RcCompactCell c = ref chf.cells[(ax + bs) + (az + bs) * chf.width]; for (int i = c.index, ni = c.index + c.count; i < ni && dmin > 0; ++i) { RcCompactSpan s = chf.spans[i]; @@ -1290,7 +1290,7 @@ namespace DotRecast.Recast for (int hx = 0; hx < hp.width; hx++) { int x = hp.xmin + hx + bs; - RcCompactCell c = chf.cells[x + y * chf.width]; + ref readonly RcCompactCell c = ref chf.cells[x + y * chf.width]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { RcCompactSpan s = chf.spans[i]; diff --git a/src/DotRecast.Recast/RcRegions.cs b/src/DotRecast.Recast/RcRegions.cs index 2ccbcb3..a8dd76d 100644 --- a/src/DotRecast.Recast/RcRegions.cs +++ b/src/DotRecast.Recast/RcRegions.cs @@ -49,7 +49,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { RcCompactSpan s = chf.spans[i]; @@ -83,7 +83,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { RcCompactSpan s = chf.spans[i]; @@ -146,7 +146,7 @@ namespace DotRecast.Recast { for (int x = w - 1; x >= 0; --x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { RcCompactSpan s = chf.spans[i]; @@ -225,7 +225,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { RcCompactSpan s = chf.spans[i]; @@ -406,7 +406,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { if (chf.dist[i] >= level && srcReg[i] == 0 && chf.areas[i] != RC_NULL_AREA) @@ -535,7 +535,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { if (chf.areas[i] == RC_NULL_AREA || srcReg[i] != 0) @@ -807,7 +807,7 @@ namespace DotRecast.Recast int ny = y + GetDirOffsetY(dir); if (GetCon(s, dir) != RC_NOT_CONNECTED) { - RcCompactCell nc = chf.cells[nx + ny * chf.width]; + ref readonly RcCompactCell nc = ref chf.cells[nx + ny * chf.width]; ni = nc.index + GetCon(s, dir); } @@ -867,7 +867,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { int r = srcReg[i]; @@ -1190,7 +1190,7 @@ namespace DotRecast.Recast { for (int x = 0; x < w; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; lregs.Clear(); @@ -1445,7 +1445,7 @@ namespace DotRecast.Recast { for (int x = minx; x < maxx; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { if (chf.areas[i] != RC_NULL_AREA) @@ -1531,7 +1531,7 @@ namespace DotRecast.Recast for (int x = borderSize; x < w - borderSize; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { @@ -1609,7 +1609,7 @@ namespace DotRecast.Recast // Remap IDs for (int x = borderSize; x < w - borderSize; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { @@ -1831,7 +1831,7 @@ namespace DotRecast.Recast for (int x = borderSize; x < w - borderSize; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) { @@ -1909,7 +1909,7 @@ namespace DotRecast.Recast // Remap IDs for (int x = borderSize; x < w - borderSize; ++x) { - RcCompactCell c = chf.cells[x + y * w]; + ref readonly RcCompactCell c = ref chf.cells[x + y * w]; for (int i = c.index, ni = c.index + c.count; i < ni; ++i) {