diff --git a/src/DotRecast.Recast/RcDirtyEntry.cs b/src/DotRecast.Recast/RcDirtyEntry.cs index 065be20..92e7caf 100644 --- a/src/DotRecast.Recast/RcDirtyEntry.cs +++ b/src/DotRecast.Recast/RcDirtyEntry.cs @@ -1,5 +1,6 @@ namespace DotRecast.Recast { + // Struct to keep track of entries in the region table that have been changed. public readonly struct RcDirtyEntry { public readonly int index; diff --git a/src/DotRecast.Recast/RcRegions.cs b/src/DotRecast.Recast/RcRegions.cs index 2b6c2fa..f3e6270 100644 --- a/src/DotRecast.Recast/RcRegions.cs +++ b/src/DotRecast.Recast/RcRegions.cs @@ -429,7 +429,7 @@ namespace DotRecast.Recast } } - List dirtyEntries = new List(); + List dirtyEntries = new List(); int iter = 0; while (stack.Count > 0) { @@ -479,9 +479,7 @@ namespace DotRecast.Recast if (r != 0) { stack[j] = new RcLevelStackEntry(stack[j].x, stack[j].y, -1); // mark as used - dirtyEntries.Add(i); - dirtyEntries.Add(r); - dirtyEntries.Add(d2); + dirtyEntries.Add(new RcDirtyEntry(i, r, d2)); } else { @@ -490,11 +488,11 @@ namespace DotRecast.Recast } // 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]; - srcReg[idx] = dirtyEntries[i + 1]; - srcDist[idx] = dirtyEntries[i + 2]; + int idx = dirtyEntries[i].index; + srcReg[idx] = dirtyEntries[i].region; + srcDist[idx] = dirtyEntries[i].distance2; } if (failed == stack.Count()) @@ -513,10 +511,10 @@ namespace DotRecast.Recast } } - private static void SortCellsByLevel(int startLevel, - RcCompactHeightfield chf, - int[] srcReg, - int nbStacks, List> stacks, + private static void SortCellsByLevel(int startLevel, + RcCompactHeightfield chf, + int[] srcReg, + int nbStacks, List> stacks, int loglevelsPerStack) // the levels per stack (2 in our case) as a bit shift { int w = chf.width; @@ -559,8 +557,8 @@ namespace DotRecast.Recast } } - private static void AppendStacks(List srcStack, - List dstStack, + private static void AppendStacks(List srcStack, + List dstStack, int[] srcReg) { for (int j = 0; j < srcStack.Count; j++)