Skip to content

Commit

Permalink
Changed vertCount and triCount to byte in DtPolyDetail
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Jul 2, 2024
1 parent ba68157 commit a282a80
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Changed to consolidate vector-related functions into one place.
- Changed stack handling from List to a fixed-size array with manual index management for optimization in `RcLayers.BuildHeightfieldLayers()`
- Changed to use Span<byte> and stackalloc for improved performance and memory management in `RcLayers.BuildHeightfieldLayers()`
- Changed vertCount and triCount to byte in `DtPolyDetail`

### Removed
- Removed RcMeshDetails.VdistSq2(float[], float[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public GraphMeshData Read(ZipArchive file, string filename, GraphMeta meta, int
ymax = Math.Max(ymax, verts[nodes[i].verts[1] * 3 + 1]);
ymax = Math.Max(ymax, verts[nodes[i].verts[2] * 3 + 1]);
int vertBase = 0;
int vertCount = 0;
byte vertCount = 0;
int triBase = i;
int triCount = 1;
byte triCount = 1;
detailNodes[i] = new DtPolyDetail(vertBase, triBase, vertCount, triCount);
detailTris[4 * i] = 0;
detailTris[4 * i + 1] = 1;
Expand Down
8 changes: 4 additions & 4 deletions src/DotRecast.Detour/DtNavMeshBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ public static DtMeshData CreateNavMeshData(DtNavMeshCreateParams option)
int ndv = option.detailMeshes[i * 4 + 1];
int nv = navPolys[i].vertCount;
int vertBase = vbase;
int vertCount = (ndv - nv);
byte vertCount = (byte)(ndv - nv);
int triBase = option.detailMeshes[i * 4 + 2];
int triCount = option.detailMeshes[i * 4 + 3];
byte triCount = (byte)option.detailMeshes[i * 4 + 3];
navDMeshes[i] = new DtPolyDetail(vertBase, triBase, vertCount, triCount);
// Copy vertices except the first 'nv' verts which are equal to
// nav poly verts.
Expand All @@ -580,9 +580,9 @@ public static DtMeshData CreateNavMeshData(DtNavMeshCreateParams option)
{
int nv = navPolys[i].vertCount;
int vertBase = 0;
int vertCount = 0;
byte vertCount = 0;
int triBase = tbase;
int triCount = (nv - 2);
byte triCount = (byte)(nv - 2);
navDMeshes[i] = new DtPolyDetail(vertBase, triBase, vertCount, triCount);
// Triangulate polygon (local indices).
for (int j = 2; j < nv; ++j)
Expand Down
6 changes: 3 additions & 3 deletions src/DotRecast.Detour/DtPolyDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace DotRecast.Detour
{
public readonly int vertBase; //< The offset of the vertices in the dtMeshTile::detailVerts array.
public readonly int triBase; //< The offset of the triangles in the dtMeshTile::detailTris array.
public readonly int vertCount; //< The number of vertices in the sub-mesh.
public readonly int triCount; //< The number of triangles in the sub-mesh.
public readonly byte vertCount; //< The number of vertices in the sub-mesh.
public readonly byte triCount; //< The number of triangles in the sub-mesh.

public DtPolyDetail(int vertBase, int triBase, int vertCount, int triCount)
public DtPolyDetail(int vertBase, int triBase, byte vertCount, byte triCount)
{
this.vertBase = vertBase;
this.triBase = triBase;
Expand Down
4 changes: 2 additions & 2 deletions src/DotRecast.Detour/Io/DtMeshDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ private DtPolyDetail[] ReadPolyDetails(RcByteBuffer buf, DtMeshHeader header, bo
{
int vertBase = buf.GetInt();
int triBase = buf.GetInt();
int vertCount = buf.Get() & 0xFF;
int triCount = buf.Get() & 0xFF;
byte vertCount = (byte)(buf.Get() & 0xFF);
byte triCount = (byte)(buf.Get() & 0xFF);
polys[i] = new DtPolyDetail(vertBase, triBase, vertCount, triCount);
if (cCompatibility)
{
Expand Down

0 comments on commit a282a80

Please sign in to comment.