From 061c4469ed450153a757e3aeb4f16956fa9cc903 Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 26 Jul 2023 00:14:34 +0900 Subject: [PATCH] class StraightPathItem -> readonly struct StraightPathItem --- src/DotRecast.Detour/DtNavMeshQuery.cs | 4 ++-- src/DotRecast.Detour/PathUtils.cs | 2 +- src/DotRecast.Detour/StraightPathItem.cs | 8 ++++---- src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs | 1 + .../Tools/TestNavmeshToolImpl.cs | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 9eca19b..1c1ccae 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Numerics; using DotRecast.Core; namespace DotRecast.Detour @@ -1437,8 +1438,7 @@ namespace DotRecast.Detour if (straightPath.Count > 0 && DetourCommon.VEqual(straightPath[straightPath.Count - 1].pos, pos)) { // The vertices are equal, update flags and poly. - straightPath[straightPath.Count - 1].flags = flags; - straightPath[straightPath.Count - 1].refs = refs; + straightPath[straightPath.Count - 1] = new StraightPathItem(straightPath[straightPath.Count - 1].pos, flags, refs); } else { diff --git a/src/DotRecast.Detour/PathUtils.cs b/src/DotRecast.Detour/PathUtils.cs index 034534d..c46989f 100644 --- a/src/DotRecast.Detour/PathUtils.cs +++ b/src/DotRecast.Detour/PathUtils.cs @@ -38,7 +38,7 @@ namespace DotRecast.Detour steerPosRef = 0; // Find steer target. - var straightPath = new List(); + var straightPath = new List(MAX_STEER_POINTS); var result = navQuery.FindStraightPath(startPos, endPos, path, ref straightPath, MAX_STEER_POINTS, 0); if (result.Failed()) { diff --git a/src/DotRecast.Detour/StraightPathItem.cs b/src/DotRecast.Detour/StraightPathItem.cs index 3a6099b..d675bf4 100644 --- a/src/DotRecast.Detour/StraightPathItem.cs +++ b/src/DotRecast.Detour/StraightPathItem.cs @@ -23,11 +23,11 @@ using DotRecast.Core; namespace DotRecast.Detour { //TODO: (PP) Add comments - public class StraightPathItem + public readonly struct StraightPathItem { - public RcVec3f pos; - public int flags; - public long refs; + public readonly RcVec3f pos; + public readonly int flags; + public readonly long refs; public StraightPathItem(RcVec3f pos, int flags, long refs) { diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 7bb1ab9..85330e0 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -809,6 +809,7 @@ public class TestNavmeshTool : IRcTool } } + m_straightPath = new(MAX_POLYS); m_navQuery.FindStraightPath(m_spos, epos, m_polys, ref m_straightPath, MAX_POLYS, DtNavMeshQuery.DT_STRAIGHTPATH_ALL_CROSSINGS); } diff --git a/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs index 2b78f80..19da000 100644 --- a/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs +++ b/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs @@ -7,8 +7,8 @@ namespace DotRecast.Recast.DemoTool.Tools { public class TestNavmeshToolImpl : ISampleTool { - private const int MAX_POLYS = 256; - private const int MAX_SMOOTH = 2048; + public const int MAX_POLYS = 256; + public const int MAX_SMOOTH = 2048; private Sample _sample; private readonly TestNavmeshToolOption _option;