From daf552b4b75836d34bb4ee2e8002720f3ef966f4 Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 2 May 2024 23:12:33 +0900 Subject: [PATCH] SOH - Span verts = stackalloc float[m_maxVertPerPoly * 3]; https://github.com/ikpil/DotRecast/issues/41 --- src/DotRecast.Detour/DtNavMesh.cs | 29 +++++++++-------------------- src/DotRecast.Detour/DtUtils.cs | 2 +- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index 4b5f49d..70bddcd 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -66,30 +66,19 @@ namespace DotRecast.Detour /// The limit is given as a multiple of the character radius public const float DT_RAY_CAST_LIMIT_PROPORTIONS = 50.0f; - private readonly DtNavMeshParams m_params; - - /// < Current initialization params. TODO: do not store this info twice. - private readonly RcVec3f m_orig; - - /// < Origin of the tile (0,0) + private readonly DtNavMeshParams m_params; // < Current initialization params. TODO: do not store this info twice. + private readonly RcVec3f m_orig; // < Origin of the tile (0,0) // float m_orig[3]; ///< Origin of the tile (0,0) + private float m_tileWidth; - - private float m_tileHeight; - - /// < Dimensions of each tile. - int m_maxTiles; - - /// < Max number of tiles. - private readonly int m_tileLutMask; - - /// < Tile hash lookup mask. + private float m_tileHeight; // < Dimensions of each tile. + int m_maxTiles; // < Max number of tiles. + private readonly int m_tileLutMask; // < Tile hash lookup mask. private readonly Dictionary> posLookup = new Dictionary>(); private readonly LinkedList availableTiles = new LinkedList(); - private readonly DtMeshTile[] m_tiles; + private readonly DtMeshTile[] m_tiles; // List of tiles. - /// < List of tiles. /** The maximum number of vertices per navigation polygon. */ private readonly int m_maxVertPerPoly; @@ -1246,11 +1235,11 @@ namespace DotRecast.Detour int ip = poly.index; - float[] verts = new float[m_maxVertPerPoly * 3]; + Span verts = stackalloc float[m_maxVertPerPoly * 3]; int nv = poly.vertCount; for (int i = 0; i < nv; ++i) { - RcArrays.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3); + RcSpans.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3); } if (!DtUtils.PointInPolygon(pos, verts, nv)) diff --git a/src/DotRecast.Detour/DtUtils.cs b/src/DotRecast.Detour/DtUtils.cs index adb6e9f..b2cdc08 100644 --- a/src/DotRecast.Detour/DtUtils.cs +++ b/src/DotRecast.Detour/DtUtils.cs @@ -267,7 +267,7 @@ namespace DotRecast.Detour /// @par /// /// All points are projected onto the xz-plane, so the y-values are ignored. - public static bool PointInPolygon(RcVec3f pt, float[] verts, int nverts) + public static bool PointInPolygon(RcVec3f pt, Span verts, int nverts) { // TODO: Replace pnpoly with triArea2D tests? int i, j;