From 17f13dd68183b7ed97afa9d2b281ffc30d88cef3 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 20 Jan 2024 00:56:31 +0900 Subject: [PATCH] refactor: Remove unused List overlaps in the MergeAndFilterLayerRegions function. --- src/DotRecast.Recast/RcRegions.cs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/DotRecast.Recast/RcRegions.cs b/src/DotRecast.Recast/RcRegions.cs index f3e6270..bcde43c 100644 --- a/src/DotRecast.Recast/RcRegions.cs +++ b/src/DotRecast.Recast/RcRegions.cs @@ -1163,7 +1163,7 @@ namespace DotRecast.Recast } } - private static int MergeAndFilterLayerRegions(RcContext ctx, int minRegionArea, int maxRegionId, RcCompactHeightfield chf, int[] srcReg, List overlaps) + private static bool MergeAndFilterLayerRegions(RcContext ctx, int minRegionArea, ref int maxRegionId, RcCompactHeightfield chf, int[] srcReg) { int w = chf.width; int h = chf.height; @@ -1398,7 +1398,7 @@ namespace DotRecast.Recast } } - return maxRegionId; + return true; } /// @par @@ -1781,7 +1781,7 @@ namespace DotRecast.Recast } } - public static void BuildLayerRegions(RcContext ctx, RcCompactHeightfield chf, int minRegionArea) + public static bool BuildLayerRegions(RcContext ctx, RcCompactHeightfield chf, int minRegionArea) { using var timer = ctx.ScopedTimer(RcTimerLabel.RC_TIMER_BUILD_REGIONS); @@ -1924,13 +1924,15 @@ namespace DotRecast.Recast } } - ctx.StartTimer(RcTimerLabel.RC_TIMER_BUILD_REGIONS_FILTER); - - // Merge monotone regions to layers and remove small regions. - List overlaps = new List(); - chf.maxRegions = MergeAndFilterLayerRegions(ctx, minRegionArea, id, chf, srcReg, overlaps); - - ctx.StopTimer(RcTimerLabel.RC_TIMER_BUILD_REGIONS_FILTER); + using (var timerFilter = ctx.ScopedTimer(RcTimerLabel.RC_TIMER_BUILD_REGIONS_FILTER)) + { + // Merge monotone regions to layers and remove small regions. + chf.maxRegions = id; + if (!MergeAndFilterLayerRegions(ctx, minRegionArea, ref chf.maxRegions, chf, srcReg)) + { + return false; + } + } // Store the result out. for (int i = 0; i < chf.spanCount; ++i) @@ -1940,6 +1942,8 @@ namespace DotRecast.Recast .WithReg(srcReg[i]) .Build(); } + + return true; } } } \ No newline at end of file