refactor: add RcDirtyEntry

This commit is contained in:
ikpil 2024-01-19 00:06:04 +09:00 committed by Ikpil
parent d7244bd0ff
commit 66a3d73b8f
2 changed files with 13 additions and 14 deletions

View File

@ -1,5 +1,6 @@
namespace DotRecast.Recast namespace DotRecast.Recast
{ {
// Struct to keep track of entries in the region table that have been changed.
public readonly struct RcDirtyEntry public readonly struct RcDirtyEntry
{ {
public readonly int index; public readonly int index;

View File

@ -429,7 +429,7 @@ namespace DotRecast.Recast
} }
} }
List<int> dirtyEntries = new List<int>(); List<RcDirtyEntry> dirtyEntries = new List<RcDirtyEntry>();
int iter = 0; int iter = 0;
while (stack.Count > 0) while (stack.Count > 0)
{ {
@ -479,9 +479,7 @@ namespace DotRecast.Recast
if (r != 0) if (r != 0)
{ {
stack[j] = new RcLevelStackEntry(stack[j].x, stack[j].y, -1); // mark as used stack[j] = new RcLevelStackEntry(stack[j].x, stack[j].y, -1); // mark as used
dirtyEntries.Add(i); dirtyEntries.Add(new RcDirtyEntry(i, r, d2));
dirtyEntries.Add(r);
dirtyEntries.Add(d2);
} }
else else
{ {
@ -490,11 +488,11 @@ namespace DotRecast.Recast
} }
// Copy entries that differ between src and dst to keep them in sync. // Copy entries that differ between src and dst to keep them in sync.
for (int i = 0; i < dirtyEntries.Count; i += 3) for (int i = 0; i < dirtyEntries.Count; i++)
{ {
int idx = dirtyEntries[i]; int idx = dirtyEntries[i].index;
srcReg[idx] = dirtyEntries[i + 1]; srcReg[idx] = dirtyEntries[i].region;
srcDist[idx] = dirtyEntries[i + 2]; srcDist[idx] = dirtyEntries[i].distance2;
} }
if (failed == stack.Count()) if (failed == stack.Count())
@ -513,10 +511,10 @@ namespace DotRecast.Recast
} }
} }
private static void SortCellsByLevel(int startLevel, private static void SortCellsByLevel(int startLevel,
RcCompactHeightfield chf, RcCompactHeightfield chf,
int[] srcReg, int[] srcReg,
int nbStacks, List<List<RcLevelStackEntry>> stacks, int nbStacks, List<List<RcLevelStackEntry>> stacks,
int loglevelsPerStack) // the levels per stack (2 in our case) as a bit shift int loglevelsPerStack) // the levels per stack (2 in our case) as a bit shift
{ {
int w = chf.width; int w = chf.width;
@ -559,8 +557,8 @@ namespace DotRecast.Recast
} }
} }
private static void AppendStacks(List<RcLevelStackEntry> srcStack, private static void AppendStacks(List<RcLevelStackEntry> srcStack,
List<RcLevelStackEntry> dstStack, List<RcLevelStackEntry> dstStack,
int[] srcReg) int[] srcReg)
{ {
for (int j = 0; j < srcStack.Count; j++) for (int j = 0; j < srcStack.Count; j++)