diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 36d1e85..9b5982e 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -318,12 +318,12 @@ namespace DotRecast.Detour.Crowd var delta = next.Subtract(m_pos); RcVec3f goal = RcVec3f.Mad(m_pos, delta, pathOptimizationRange / dist); - Result rc = navquery.Raycast(m_path[0], m_pos, goal, filter, 0, 0); - if (rc.Succeeded()) + var status = navquery.Raycast(m_path[0], m_pos, goal, filter, 0, 0, out var rayHit); + if (status.Succeeded()) { - if (rc.result.path.Count > 1 && rc.result.t > 0.99f) + if (rayHit.path.Count > 1 && rayHit.t > 0.99f) { - m_path = MergeCorridorStartShortcut(m_path, rc.result.path); + m_path = MergeCorridorStartShortcut(m_path, rayHit.path); } } } diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 73e1c30..776fe74 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -927,17 +927,17 @@ namespace DotRecast.Detour List shortcut = null; if (tryLOS) { - Result rayHit = Raycast(parentRef, parentNode.pos, neighbourPos, filter, - DT_RAYCAST_USE_COSTS, grandpaRef); - if (rayHit.Succeeded()) + status = Raycast(parentRef, parentNode.pos, neighbourPos, filter, + DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit); + if (status.Succeeded()) { - foundShortCut = rayHit.result.t >= 1.0f; + foundShortCut = rayHit.t >= 1.0f; if (foundShortCut) { - shortcut = rayHit.result.path; + shortcut = rayHit.path; // shortcut found using raycast. Using shorter cost // instead - cost = parentNode.cost + rayHit.result.pathCost; + cost = parentNode.cost + rayHit.pathCost; } } } @@ -1246,17 +1246,17 @@ namespace DotRecast.Detour List shortcut = null; if (tryLOS) { - Result rayHit = Raycast(parentRef, parentNode.pos, neighbourPos, m_query.filter, - DT_RAYCAST_USE_COSTS, grandpaRef); - if (rayHit.Succeeded()) + status = Raycast(parentRef, parentNode.pos, neighbourPos, m_query.filter, + DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit); + if (status.Succeeded()) { - foundShortCut = rayHit.result.t >= 1.0f; + foundShortCut = rayHit.t >= 1.0f; if (foundShortCut) { - shortcut = rayHit.result.path; + shortcut = rayHit.path; // shortcut found using raycast. Using shorter cost // instead - cost = parentNode.cost + rayHit.result.pathCost; + cost = parentNode.cost + rayHit.pathCost; } } } @@ -2186,17 +2186,20 @@ namespace DotRecast.Detour /// @param[out] pathCount The number of visited polygons. [opt] /// @param[in] maxPath The maximum number of polygons the @p path array can hold. /// @returns The status flags for the query. - public Result Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, - long prevRef) + public DtStatus Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, + long prevRef, out DtRaycastHit hit) { + hit = null; + // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == filter + if (!m_nav.IsValidPolyRef(startRef) || !RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) + || null == filter || (prevRef != 0 && !m_nav.IsValidPolyRef(prevRef))) { - return Results.InvalidParam(); + return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } - DtRaycastHit hit = new DtRaycastHit(); + hit = new DtRaycastHit(); float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3 + 3]; @@ -2235,7 +2238,7 @@ namespace DotRecast.Detour if (!iresult.intersects) { // Could not hit the polygon, keep the old t and report hit. - return Results.Success(hit); + return DtStatus.DT_SUCCSESS; } hit.hitEdgeIndex = iresult.segMax; @@ -2261,7 +2264,7 @@ namespace DotRecast.Detour curRef, tile, poly); } - return Results.Success(hit); + return DtStatus.DT_SUCCSESS; } // Follow neighbours. @@ -2390,7 +2393,7 @@ namespace DotRecast.Detour hit.hitNormal.y = 0; hit.hitNormal.z = -dx; hit.hitNormal.Normalize(); - return Results.Success(hit); + return DtStatus.DT_SUCCSESS; } // No hit, advance to neighbour polygon. @@ -2402,7 +2405,7 @@ namespace DotRecast.Detour poly = nextPoly; } - return Results.Success(hit); + return DtStatus.DT_SUCCSESS; } /// @par diff --git a/src/DotRecast.Detour/LegacyNavMeshQuery.cs b/src/DotRecast.Detour/LegacyNavMeshQuery.cs index 65efa18..6b90341 100644 --- a/src/DotRecast.Detour/LegacyNavMeshQuery.cs +++ b/src/DotRecast.Detour/LegacyNavMeshQuery.cs @@ -361,16 +361,16 @@ namespace DotRecast.Detour bool foundShortCut = false; if (tryLOS) { - Result rayHit = Raycast(parentRef, parentNode.pos, neighbourNode.pos, m_query.filter, - DT_RAYCAST_USE_COSTS, grandpaRef); - if (rayHit.Succeeded()) + status = Raycast(parentRef, parentNode.pos, neighbourNode.pos, m_query.filter, + DT_RAYCAST_USE_COSTS, grandpaRef, out var rayHit); + if (status.Succeeded()) { - foundShortCut = rayHit.result.t >= 1.0f; + foundShortCut = rayHit.t >= 1.0f; if (foundShortCut) { // shortcut found using raycast. Using shorter cost // instead - cost = parentNode.cost + rayHit.result.pathCost; + cost = parentNode.cost + rayHit.pathCost; } } } @@ -505,10 +505,11 @@ namespace DotRecast.Detour DtNode next = m_nodePool.GetNodeAtIdx(node.pidx); if ((node.flags & DtNode.DT_NODE_PARENT_DETACHED) != 0) { - Result iresult = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0); - if (iresult.Succeeded()) + var status2 = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0, + out var rayHit); + if (status2.Succeeded()) { - path.AddRange(iresult.result.path); + path.AddRange(rayHit.path); } // raycast ends on poly boundary and the path might include the next poly boundary. @@ -602,10 +603,11 @@ namespace DotRecast.Detour DtNode next = m_nodePool.GetNodeAtIdx(node.pidx); if ((node.flags & DtNode.DT_NODE_PARENT_DETACHED) != 0) { - Result iresult = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0); - if (iresult.Succeeded()) + var status2 = Raycast(node.id, node.pos, next.pos, m_query.filter, 0, 0, + out var rayHit); + if (status2.Succeeded()) { - path.AddRange(iresult.result.path); + path.AddRange(rayHit.path); } // raycast ends on poly boundary and the path might include the next poly boundary. diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 6061240..65fb506 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -369,11 +369,11 @@ public class TestNavmeshTool : IRcTool if (m_sposSet && m_eposSet && m_startRef != 0) { { - Result hit = m_navQuery.Raycast(m_startRef, m_spos, m_epos, m_filter, 0, 0); - if (hit.Succeeded()) + var status = m_navQuery.Raycast(m_startRef, m_spos, m_epos, m_filter, 0, 0, out var rayHit); + if (status.Succeeded()) { - m_polys = hit.result.path; - if (hit.result.t > 1) + m_polys = rayHit.path; + if (rayHit.t > 1) { // No hit m_hitPos = m_epos; @@ -382,15 +382,15 @@ public class TestNavmeshTool : IRcTool else { // Hit - m_hitPos = RcVec3f.Lerp(m_spos, m_epos, hit.result.t); - m_hitNormal = hit.result.hitNormal; + m_hitPos = RcVec3f.Lerp(m_spos, m_epos, rayHit.t); + m_hitNormal = rayHit.hitNormal; m_hitResult = true; } // Adjust height. - if (hit.result.path.Count > 0) + if (rayHit.path.Count > 0) { - var result = m_navQuery.GetPolyHeight(hit.result.path[hit.result.path.Count - 1], m_hitPos, out var h); + var result = m_navQuery.GetPolyHeight(rayHit.path[rayHit.path.Count - 1], m_hitPos, out var h); if (result.Succeeded()) { m_hitPos.y = h;