Skip to content

Commit

Permalink
reduced memory usage of DtLink.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed May 15, 2024
1 parent 52fe012 commit cfec731
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/DotRecast.Detour/DtLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ namespace DotRecast.Detour
/// @see dtMeshTile
public class DtLink
{
public readonly int index; // DtMeshTile.links array index
public long refs; //< Neighbour reference. (The neighbor that is linked to.)
public int next; //< Index of the next link.
public int edge; //< Index of the polygon edge that owns this link.
public int side; //< If a boundary link, defines on which side the link is.
public int bmin; //< If a boundary link, defines the minimum sub-edge area.
public int bmax; //< If a boundary link, defines the maximum sub-edge area.
public byte edge; //< Index of the polygon edge that owns this link.
public byte side; //< If a boundary link, defines on which side the link is.
public byte bmin; //< If a boundary link, defines the minimum sub-edge area.
public byte bmax; //< If a boundary link, defines the maximum sub-edge area.
}
}
18 changes: 9 additions & 9 deletions src/DotRecast.Detour/DtNavMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ void ConnectIntLinks(DtMeshTile tile)
int idx = AllocLink(tile);
DtLink link = tile.links[idx];
link.refs = @base | (long)(poly.neis[j] - 1);
link.edge = j;
link.edge = (byte)j;
link.side = 0xff;
link.bmin = link.bmax = 0;
// Add to linked list.
Expand Down Expand Up @@ -684,8 +684,8 @@ void ConnectExtLinks(DtMeshTile tile, DtMeshTile target, int side)
{
DtLink link = tile.links[idx];
link.refs = connectPoly.refs;
link.edge = j;
link.side = dir;
link.edge = (byte)j;
link.side = (byte)dir;

link.next = poly.firstLink;
poly.firstLink = idx;
Expand All @@ -704,8 +704,8 @@ void ConnectExtLinks(DtMeshTile tile, DtMeshTile target, int side)
tmax = temp;
}

link.bmin = (int)MathF.Round(Math.Clamp(tmin, 0.0f, 1.0f) * 255.0f);
link.bmax = (int)MathF.Round(Math.Clamp(tmax, 0.0f, 1.0f) * 255.0f);
link.bmin = (byte)MathF.Round(Math.Clamp(tmin, 0.0f, 1.0f) * 255.0f);
link.bmax = (byte)MathF.Round(Math.Clamp(tmax, 0.0f, 1.0f) * 255.0f);
}
else if (dir == 2 || dir == 6)
{
Expand All @@ -720,8 +720,8 @@ void ConnectExtLinks(DtMeshTile tile, DtMeshTile target, int side)
tmax = temp;
}

link.bmin = (int)MathF.Round(Math.Clamp(tmin, 0.0f, 1.0f) * 255.0f);
link.bmax = (int)MathF.Round(Math.Clamp(tmax, 0.0f, 1.0f) * 255.0f);
link.bmin = (byte)MathF.Round(Math.Clamp(tmin, 0.0f, 1.0f) * 255.0f);
link.bmax = (byte)MathF.Round(Math.Clamp(tmax, 0.0f, 1.0f) * 255.0f);
}
}
}
Expand Down Expand Up @@ -790,7 +790,7 @@ void ConnectExtOffMeshLinks(DtMeshTile tile, DtMeshTile target, int side)
DtLink link = target.links[idx];
link.refs = refs;
link.edge = 1;
link.side = oppositeSide;
link.side = (byte)oppositeSide;
link.bmin = link.bmax = 0;
// Add to linked list.
link.next = targetPoly.firstLink;
Expand All @@ -805,7 +805,7 @@ void ConnectExtOffMeshLinks(DtMeshTile tile, DtMeshTile target, int side)
link = tile.links[tidx];
link.refs = GetPolyRefBase(target) | (long)targetCon.poly;
link.edge = 0xff;
link.side = (side == -1 ? 0xff : side);
link.side = (byte)(side == -1 ? 0xff : side);
link.bmin = link.bmax = 0;
// Add to linked list.
link.next = landPoly.firstLink;
Expand Down

0 comments on commit cfec731

Please sign in to comment.