remove int[] offset = new int[] { 0, 1, 0, -1 };

This commit is contained in:
ikpil 2023-06-05 14:37:44 +09:00
parent bab26f529b
commit 1f80b70461
2 changed files with 25 additions and 29 deletions

View File

@ -30,10 +30,11 @@ namespace DotRecast.Detour.TileCache
{ {
public class TileCacheBuilder public class TileCacheBuilder
{ {
const int DT_TILECACHE_NULL_AREA = 0; public const int DT_TILECACHE_NULL_AREA = 0;
const int DT_TILECACHE_WALKABLE_AREA = 63; public const int DT_TILECACHE_WALKABLE_AREA = 63;
const int DT_TILECACHE_NULL_IDX = 0xffff; public const int DT_TILECACHE_NULL_IDX = 0xffff;
private static readonly int[] DirOffsetX = { -1, 0, 1, 0, };
private static readonly int[] DirOffsetY = { 0, 1, 0, -1 };
private readonly TileCacheLayerHeaderReader reader = new TileCacheLayerHeaderReader(); private readonly TileCacheLayerHeaderReader reader = new TileCacheLayerHeaderReader();
@ -336,17 +337,15 @@ namespace DotRecast.Detour.TileCache
int ib = bx + by * w; int ib = bx + by * w;
return layer.regs[ib]; return layer.regs[ib];
} }
private int GetDirOffsetX(int dir) private int GetDirOffsetX(int dir)
{ {
int[] offset = new int[] { -1, 0, 1, 0, }; return DirOffsetX[dir & 0x03];
return offset[dir & 0x03];
} }
private int GetDirOffsetY(int dir) private int GetDirOffsetY(int dir)
{ {
int[] offset = new int[] { 0, 1, 0, -1 }; return DirOffsetY[dir & 0x03];
return offset[dir & 0x03];
} }
private void WalkContour(TileCacheLayer layer, int x, int y, TempContour cont) private void WalkContour(TileCacheLayer layer, int x, int y, TempContour cont)

View File

@ -29,22 +29,20 @@ namespace DotRecast.Recast
private static readonly int[] DirForOffset = { 3, 0, -1, 2, 1 }; private static readonly int[] DirForOffset = { 3, 0, -1, 2, 1 };
/// Sets the neighbor connection data for the specified direction. /// Sets the neighbor connection data for the specified direction.
/// @param[in] s The span to update. /// @param[in] span The span to update.
/// @param[in] dir The direction to set. [Limits: 0 <= value < 4] /// @param[in] direction The direction to set. [Limits: 0 <= value < 4]
/// @param[in] i The index of the neighbor span. /// @param[in] neighborIndex The index of the neighbor span.
public static void SetCon(CompactSpan s, int dir, int i) public static void SetCon(CompactSpan span, int direction, int neighborIndex)
{ {
int shift = dir * 6; int shift = direction * 6;
int con = s.con; int con = span.con;
s.con = (con & ~(0x3f << shift)) | ((i & 0x3f) << shift); span.con = (con & ~(0x3f << shift)) | ((neighborIndex & 0x3f) << shift);
} }
/// Gets neighbor connection data for the specified direction. /// Gets neighbor connection data for the specified direction.
/// @param[in] s The span to check. /// @param[in] span The span to check.
/// @param[in] dir The direction to check. [Limits: 0 <= value < 4] /// @param[in] direction The direction to check. [Limits: 0 <= value < 4]
/// @return The neighbor connection data for the specified direction, /// @return The neighbor connection data for the specified direction, or #RC_NOT_CONNECTED if there is no connection.
/// or #RC_NOT_CONNECTED if there is no connection.
///
public static int GetCon(CompactSpan s, int dir) public static int GetCon(CompactSpan s, int dir)
{ {
int shift = dir * 6; int shift = dir * 6;
@ -52,26 +50,25 @@ namespace DotRecast.Recast
} }
/// Gets the standard width (x-axis) offset for the specified direction. /// Gets the standard width (x-axis) offset for the specified direction.
/// @param[in] dir The direction. [Limits: 0 <= value < 4] /// @param[in] direction The direction. [Limits: 0 <= value < 4]
/// @return The width offset to apply to the current cell position to move /// @return The width offset to apply to the current cell position to move in the direction.
/// in the direction.
public static int GetDirOffsetX(int dir) public static int GetDirOffsetX(int dir)
{ {
return DirOffsetX[dir & 0x03]; return DirOffsetX[dir & 0x03];
} }
// TODO (graham): Rename this to rcGetDirOffsetZ
/// Gets the standard height (z-axis) offset for the specified direction. /// Gets the standard height (z-axis) offset for the specified direction.
/// @param[in] dir The direction. [Limits: 0 <= value < 4] /// @param[in] direction The direction. [Limits: 0 <= value < 4]
/// @return The height offset to apply to the current cell position to move /// @return The height offset to apply to the current cell position to move in the direction.
/// in the direction.
public static int GetDirOffsetY(int dir) public static int GetDirOffsetY(int dir)
{ {
return DirOffsetY[dir & 0x03]; return DirOffsetY[dir & 0x03];
} }
/// Gets the direction for the specified offset. One of x and y should be 0. /// 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] offsetX The x offset. [Limits: -1 <= value <= 1]
/// @param[in] y The y offset. [Limits: -1 <= value <= 1] /// @param[in] offsetZ The z offset. [Limits: -1 <= value <= 1]
/// @return The direction that represents the offset. /// @return The direction that represents the offset.
public static int GetDirForOffset(int x, int y) public static int GetDirForOffset(int x, int y)
{ {