From bab26f529b4b4fbb1cdb42d29fb1cf53fe42a316 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 4 Jun 2023 11:47:41 +0900 Subject: [PATCH] remove new int[] offsets --- src/DotRecast.Recast/RecastCommon.cs | 38 +++++++++++++----------- src/DotRecast.Recast/RecastMeshDetail.cs | 4 +-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/DotRecast.Recast/RecastCommon.cs b/src/DotRecast.Recast/RecastCommon.cs index 050c779..70237c7 100644 --- a/src/DotRecast.Recast/RecastCommon.cs +++ b/src/DotRecast.Recast/RecastCommon.cs @@ -24,11 +24,27 @@ namespace DotRecast.Recast { public static class RecastCommon { + private static readonly int[] DirOffsetX = { -1, 0, 1, 0, }; + private static readonly int[] DirOffsetY = { 0, 1, 0, -1 }; + private static readonly int[] DirForOffset = { 3, 0, -1, 2, 1 }; + + /// Sets the neighbor connection data for the specified direction. + /// @param[in] s The span to update. + /// @param[in] dir The direction to set. [Limits: 0 <= value < 4] + /// @param[in] i The index of the neighbor span. + public static void SetCon(CompactSpan s, int dir, int i) + { + int shift = dir * 6; + int con = s.con; + s.con = (con & ~(0x3f << shift)) | ((i & 0x3f) << shift); + } + /// Gets neighbor connection data for the specified direction. /// @param[in] s The span to check. /// @param[in] dir The direction to check. [Limits: 0 <= value < 4] /// @return The neighbor connection data for the specified direction, /// or #RC_NOT_CONNECTED if there is no connection. + /// public static int GetCon(CompactSpan s, int dir) { int shift = dir * 6; @@ -41,8 +57,7 @@ namespace DotRecast.Recast /// in the direction. public static int GetDirOffsetX(int dir) { - int[] offset = { -1, 0, 1, 0, }; - return offset[dir & 0x03]; + return DirOffsetX[dir & 0x03]; } /// Gets the standard height (z-axis) offset for the specified direction. @@ -51,29 +66,16 @@ namespace DotRecast.Recast /// in the direction. public static int GetDirOffsetY(int dir) { - int[] offset = { 0, 1, 0, -1 }; - return offset[dir & 0x03]; + return DirOffsetY[dir & 0x03]; } /// Gets the direction for the specified offset. One of x and y should be 0. /// @param[in] x The x offset. [Limits: -1 <= value <= 1] /// @param[in] y The y offset. [Limits: -1 <= value <= 1] /// @return The direction that represents the offset. - public static int RcGetDirForOffset(int x, int y) + public static int GetDirForOffset(int x, int y) { - int[] dirs = { 3, 0, -1, 2, 1 }; - return dirs[((y + 1) << 1) + x]; - } - - /// Sets the neighbor connection data for the specified direction. - /// @param[in] s The span to update. - /// @param[in] dir The direction to set. [Limits: 0 <= value < 4] - /// @param[in] i The index of the neighbor span. - public static void SetCon(CompactSpan s, int dir, int i) - { - int shift = dir * 6; - int con = s.con; - s.con = (con & ~(0x3f << shift)) | ((i & 0x3f) << shift); + return DirForOffset[((y + 1) << 1) + x]; } } } \ No newline at end of file diff --git a/src/DotRecast.Recast/RecastMeshDetail.cs b/src/DotRecast.Recast/RecastMeshDetail.cs index c351391..dee52b1 100644 --- a/src/DotRecast.Recast/RecastMeshDetail.cs +++ b/src/DotRecast.Recast/RecastMeshDetail.cs @@ -1203,11 +1203,11 @@ namespace DotRecast.Recast int directDir; if (cx == pcx) { - directDir = RcGetDirForOffset(0, pcy > cy ? 1 : -1); + directDir = GetDirForOffset(0, pcy > cy ? 1 : -1); } else { - directDir = RcGetDirForOffset(pcx > cx ? 1 : -1, 0); + directDir = GetDirForOffset(pcx > cx ? 1 : -1, 0); } // Push the direct dir last so we start with this on next iteration