From af5b70d7f4809d7f5301d245a58e4edaff2df997 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 13 Jan 2024 22:06:06 +0900 Subject: [PATCH] small refactoring --- src/DotRecast.Detour.Dynamic/DtDynamicTile.cs | 2 +- src/DotRecast.Recast/RcBuilder.cs | 20 +++++++++---------- src/DotRecast.Recast/RcVoxelizations.cs | 11 ++++------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/DotRecast.Detour.Dynamic/DtDynamicTile.cs b/src/DotRecast.Detour.Dynamic/DtDynamicTile.cs index e038fed..82fb905 100644 --- a/src/DotRecast.Detour.Dynamic/DtDynamicTile.cs +++ b/src/DotRecast.Detour.Dynamic/DtDynamicTile.cs @@ -100,7 +100,7 @@ namespace DotRecast.Detour.Dynamic Math.Min(DtDynamicNavMesh.MAX_VERTS_PER_POLY, config.vertsPerPoly), config.detailSampleDistance, config.detailSampleMaxError, true, true, true, default, true); - RcBuilderResult r = builder.Build(vt.tileX, vt.tileZ, null, rcConfig, heightfield, context); + RcBuilderResult r = builder.Build(context, vt.tileX, vt.tileZ, null, rcConfig, heightfield); if (config.keepIntermediateResults) { recastResult = r; diff --git a/src/DotRecast.Recast/RcBuilder.cs b/src/DotRecast.Recast/RcBuilder.cs index 2edf3b3..4c91cf8 100644 --- a/src/DotRecast.Recast/RcBuilder.cs +++ b/src/DotRecast.Recast/RcBuilder.cs @@ -166,14 +166,14 @@ namespace DotRecast.Recast // // Step 1. Rasterize input polygon soup. // - RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(geom, builderCfg, ctx); - return Build(builderCfg.tileX, builderCfg.tileZ, geom, cfg, solid, ctx); + RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(ctx, geom, builderCfg); + return Build(ctx, builderCfg.tileX, builderCfg.tileZ, geom, cfg, solid); } - public RcBuilderResult Build(int tileX, int tileZ, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid, RcContext ctx) + public RcBuilderResult Build(RcContext ctx, int tileX, int tileZ, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid) { - FilterHeightfield(solid, cfg, ctx); - RcCompactHeightfield chf = BuildCompactHeightfield(geom, cfg, ctx, solid); + FilterHeightfield(ctx, solid, cfg); + RcCompactHeightfield chf = BuildCompactHeightfield(ctx, geom, cfg, solid); // Partition the heightfield so that we can use simple algorithm later to triangulate the walkable areas. // There are 3 partitioning methods, each with some pros and cons: @@ -247,7 +247,7 @@ namespace DotRecast.Recast /* * Step 2. Filter walkable surfaces. */ - private void FilterHeightfield(RcHeightfield solid, RcConfig cfg, RcContext ctx) + private void FilterHeightfield(RcContext ctx, RcHeightfield solid, RcConfig cfg) { // Once all geometry is rasterized, we do initial pass of filtering to // remove unwanted overhangs caused by the conservative rasterization @@ -271,7 +271,7 @@ namespace DotRecast.Recast /* * Step 3. Partition walkable surface to simple regions. */ - private RcCompactHeightfield BuildCompactHeightfield(IInputGeomProvider geom, RcConfig cfg, RcContext ctx, RcHeightfield solid) + private RcCompactHeightfield BuildCompactHeightfield(RcContext ctx, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid) { // Compact the heightfield so that it is faster to handle from now on. // This will result more cache coherent data as well as the neighbours @@ -295,9 +295,9 @@ namespace DotRecast.Recast public RcHeightfieldLayerSet BuildLayers(IInputGeomProvider geom, RcBuilderConfig builderCfg) { RcContext ctx = new RcContext(); - RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(geom, builderCfg, ctx); - FilterHeightfield(solid, builderCfg.cfg, ctx); - RcCompactHeightfield chf = BuildCompactHeightfield(geom, builderCfg.cfg, ctx, solid); + RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(ctx, geom, builderCfg); + FilterHeightfield(ctx, solid, builderCfg.cfg); + RcCompactHeightfield chf = BuildCompactHeightfield(ctx, geom, builderCfg.cfg, solid); RcLayers.BuildHeightfieldLayers(ctx, chf, builderCfg.cfg.BorderSize, builderCfg.cfg.WalkableHeight, out var lset); return lset; diff --git a/src/DotRecast.Recast/RcVoxelizations.cs b/src/DotRecast.Recast/RcVoxelizations.cs index 608be4f..3cc9b90 100644 --- a/src/DotRecast.Recast/RcVoxelizations.cs +++ b/src/DotRecast.Recast/RcVoxelizations.cs @@ -25,7 +25,7 @@ namespace DotRecast.Recast { public static class RcVoxelizations { - public static RcHeightfield BuildSolidHeightfield(IInputGeomProvider geomProvider, RcBuilderConfig builderCfg, RcContext ctx) + public static RcHeightfield BuildSolidHeightfield(RcContext ctx, IInputGeomProvider geomProvider, RcBuilderConfig builderCfg) { RcConfig cfg = builderCfg.cfg; @@ -34,13 +34,10 @@ namespace DotRecast.Recast // Allocate array that can hold triangle area types. // If you have multiple meshes you need to process, allocate - // and array which can hold the max number of triangles you need to - // process. + // and array which can hold the max number of triangles you need to process. - // Find triangles which are walkable based on their slope and rasterize - // them. - // If your input data is multiple meshes, you can transform them here, - // calculate + // Find triangles which are walkable based on their slope and rasterize them. + // If your input data is multiple meshes, you can transform them here, calculate // the are type for each of the meshes and rasterize them. foreach (RcTriMesh geom in geomProvider.Meshes()) {