From 26387de8592c536f29b230e5b41593fcdcb2bef6 Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 10 Oct 2023 23:47:20 +0900 Subject: [PATCH] refactor: Move constants from class DtNavMesh to class DtDetailTriEdgeFlags - moved constraints DT_DETAIL_EDGE_BOUNDARY --- src/DotRecast.Detour/DtDetailTriEdgeFlags.cs | 7 +++++++ src/DotRecast.Detour/DtNavMesh.cs | 12 +++++------- src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 src/DotRecast.Detour/DtDetailTriEdgeFlags.cs diff --git a/src/DotRecast.Detour/DtDetailTriEdgeFlags.cs b/src/DotRecast.Detour/DtDetailTriEdgeFlags.cs new file mode 100644 index 0000000..cfd420e --- /dev/null +++ b/src/DotRecast.Detour/DtDetailTriEdgeFlags.cs @@ -0,0 +1,7 @@ +namespace DotRecast.Detour +{ + public static class DtDetailTriEdgeFlags + { + public const int DT_DETAIL_EDGE_BOUNDARY = 0x01; + } +} \ No newline at end of file diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index 74c6120..def7423 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -24,14 +24,11 @@ using DotRecast.Core; namespace DotRecast.Detour { - - public class DtNavMesh { public const int DT_SALT_BITS = 16; public const int DT_TILE_BITS = 28; public const int DT_POLY_BITS = 20; - public const int DT_DETAIL_EDGE_BOUNDARY = 0x01; /// A flag that indicates that an entity links to an external entity. /// (E.g. A polygon edge is a portal that links to another polygon.) @@ -1128,8 +1125,9 @@ namespace DotRecast.Detour */ RcVec3f ClosestPointOnDetailEdges(DtMeshTile tile, DtPoly poly, RcVec3f pos, bool onlyBoundary) { - int ANY_BOUNDARY_EDGE = (DT_DETAIL_EDGE_BOUNDARY << 0) | (DT_DETAIL_EDGE_BOUNDARY << 2) - | (DT_DETAIL_EDGE_BOUNDARY << 4); + int ANY_BOUNDARY_EDGE = (DtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY << 0) | + (DtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY << 2) | + (DtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY << 4); int ip = poly.index; float dmin = float.MaxValue; float tmin = 0; @@ -1175,7 +1173,7 @@ namespace DotRecast.Detour for (int k = 0, j = 2; k < 3; j = k++) { - if ((GetDetailTriEdgeFlags(tris[ti + 3], j) & DT_DETAIL_EDGE_BOUNDARY) == 0 + if ((GetDetailTriEdgeFlags(tris[ti + 3], j) & DtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY) == 0 && (onlyBoundary || tris[ti + j] < tris[ti + k])) { // Only looking at boundary edges and this is internal, or @@ -1224,7 +1222,7 @@ namespace DotRecast.Detour public bool GetPolyHeight(DtMeshTile tile, DtPoly poly, RcVec3f pos, out float height) { height = 0; - + // Off-mesh connections do not have detail polys and getting height // over them does not make sense. if (poly.GetPolyType() == DtPolyTypes.DT_POLYTYPE_OFFMESH_CONNECTION) diff --git a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs index c8e1f31..a1ce604 100644 --- a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs @@ -395,7 +395,7 @@ public class RecastDebugDraw : DebugDraw for (int m = 0, n = 2; m < 3; n = m++) { - if ((DtNavMesh.GetDetailTriEdgeFlags(tile.data.detailTris[t + 3], n) & DtNavMesh.DT_DETAIL_EDGE_BOUNDARY) == 0) + if ((DtNavMesh.GetDetailTriEdgeFlags(tile.data.detailTris[t + 3], n) & DtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY) == 0) continue; if (((tile.data.detailTris[t + 3] >> (n * 2)) & 0x3) == 0)