From 80970e00514e5579fa92158ac0b07517308263a1 Mon Sep 17 00:00:00 2001 From: ikpil Date: Thu, 20 Apr 2023 00:04:09 +0900 Subject: [PATCH] new float[] -> struct Vector3f --- src/DotRecast.Detour.Crowd/Crowd.cs | 102 +++++++++--------- src/DotRecast.Detour.Crowd/CrowdAgent.cs | 48 ++++----- .../Draw/NavMeshRenderer.cs | 8 +- .../Draw/RecastDebugDraw.cs | 45 ++++---- .../Tools/CrowdProfilingTool.cs | 16 +-- src/DotRecast.Recast.Demo/Tools/CrowdTool.cs | 20 ++-- 6 files changed, 116 insertions(+), 123 deletions(-) diff --git a/src/DotRecast.Detour.Crowd/Crowd.cs b/src/DotRecast.Detour.Crowd/Crowd.cs index e4cdeb7..eee89ef 100644 --- a/src/DotRecast.Detour.Crowd/Crowd.cs +++ b/src/DotRecast.Detour.Crowd/Crowd.cs @@ -263,14 +263,14 @@ namespace DotRecast.Detour.Crowd if (refs != 0) { - ag.state = CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING; + ag.state = CrowdAgentState.DT_CROWDAGENT_STATE_WALKING; } else { - ag.state = CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_INVALID; + ag.state = CrowdAgentState.DT_CROWDAGENT_STATE_INVALID; } - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_NONE; return ag; } @@ -328,7 +328,7 @@ namespace DotRecast.Detour.Crowd agent.targetPos = vel; agent.targetPathQueryResult = null; agent.targetReplan = false; - agent.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY; + agent.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY; return true; } @@ -344,7 +344,7 @@ namespace DotRecast.Detour.Crowd agent.dvel = Vector3f.Zero; agent.targetPathQueryResult = null; agent.targetReplan = false; - agent.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE; + agent.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_NONE; return true; } @@ -443,7 +443,7 @@ namespace DotRecast.Detour.Crowd foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } @@ -474,7 +474,7 @@ namespace DotRecast.Detour.Crowd ag.corridor.reset(0, agentPos); ag.partial = false; ag.boundary.reset(); - ag.state = CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_INVALID; + ag.state = CrowdAgentState.DT_CROWDAGENT_STATE_INVALID; continue; } @@ -492,15 +492,15 @@ namespace DotRecast.Detour.Crowd // If the agent does not have move target or is controlled by // velocity, no need to recover the target nor replan. - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { continue; } // Try to recover move request position. - if (ag.targetState != CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - && ag.targetState != CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) + if (ag.targetState != MoveRequestState.DT_CROWDAGENT_TARGET_NONE + && ag.targetState != MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) { if (!navQuery.isValidPolyRef(ag.targetRef, m_filters[ag.option.queryFilterType])) { @@ -521,7 +521,7 @@ namespace DotRecast.Detour.Crowd // Failed to reposition target, fail moverequest. ag.corridor.reset(agentRef, agentPos); ag.partial = false; - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_NONE; } } @@ -537,7 +537,7 @@ namespace DotRecast.Detour.Crowd // If the end of the path is near and it is not the requested // location, replan. - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VALID) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VALID) { if (ag.targetReplanTime > _config.targetReplanDelay && ag.corridor.getPathCount() < _config.checkLookAhead && ag.corridor.getLastPoly() != ag.targetRef) @@ -549,7 +549,7 @@ namespace DotRecast.Detour.Crowd // Try to replan path to goal. if (replan) { - if (ag.targetState != CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE) + if (ag.targetState != MoveRequestState.DT_CROWDAGENT_TARGET_NONE) { requestMoveTargetReplan(ag, ag.targetRef, ag.targetPos); } @@ -568,18 +568,18 @@ namespace DotRecast.Detour.Crowd // Fire off new requests. foreach (CrowdAgent ag in agents) { - if (ag.state == CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_INVALID) + if (ag.state == CrowdAgentState.DT_CROWDAGENT_STATE_INVALID) { continue; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { continue; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING) { List path = ag.corridor.getPath(); if (0 == path.Count) @@ -644,19 +644,19 @@ namespace DotRecast.Detour.Crowd if (reqPath[reqPath.Count - 1] == ag.targetRef) { - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VALID; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_VALID; ag.targetReplanTime = 0; } else { // The path is longer or potentially unreachable, full plan. - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE; } ag.targetReplanWaitTime = 0; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE) { queue.Enqueue(ag); } @@ -669,7 +669,7 @@ namespace DotRecast.Detour.Crowd ag.targetPos, m_filters[ag.option.queryFilterType]); if (ag.targetPathQueryResult != null) { - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH; } else { @@ -686,13 +686,13 @@ namespace DotRecast.Detour.Crowd // Process path results. foreach (CrowdAgent ag in agents) { - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { continue; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH) { // _telemetry.recordPathWaitTime(ag.targetReplanTime); // Poll path queue. @@ -704,11 +704,11 @@ namespace DotRecast.Detour.Crowd ag.targetPathQueryResult = null; if (ag.targetRef != 0) { - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING; } else { - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_FAILED; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_FAILED; } ag.targetReplanTime = 0; @@ -800,12 +800,12 @@ namespace DotRecast.Detour.Crowd ag.corridor.setCorridor(targetPos, res); // Force to update boundary. ag.boundary.reset(); - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VALID; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_VALID; } else { // Something went wrong. - ag.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_FAILED; + ag.targetState = MoveRequestState.DT_CROWDAGENT_TARGET_FAILED; } ag.targetReplanTime = 0; @@ -827,13 +827,13 @@ namespace DotRecast.Detour.Crowd foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { continue; } @@ -879,7 +879,7 @@ namespace DotRecast.Detour.Crowd _telemetry.start("buildNeighbours"); foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } @@ -940,13 +940,13 @@ namespace DotRecast.Detour.Crowd CrowdAgent debugAgent = debug != null ? debug.agent : null; foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { continue; } @@ -988,13 +988,13 @@ namespace DotRecast.Detour.Crowd _telemetry.start("triggerOffMeshConnections"); foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { continue; } @@ -1017,7 +1017,7 @@ namespace DotRecast.Detour.Crowd anim.t = 0.0f; anim.tmax = (vDist2D(anim.startPos, anim.endPos) / ag.option.maxSpeed) * 0.5f; - ag.state = CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_OFFMESH; + ag.state = CrowdAgentState.DT_CROWDAGENT_STATE_OFFMESH; ag.corners.Clear(); ag.neis.Clear(); continue; @@ -1037,19 +1037,19 @@ namespace DotRecast.Detour.Crowd _telemetry.start("calculateSteering"); foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE) { continue; } Vector3f dvel = new Vector3f(); - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { dvel = ag.targetPos; ag.desiredSpeed = vLen(ag.targetPos); @@ -1136,7 +1136,7 @@ namespace DotRecast.Detour.Crowd CrowdAgent debugAgent = debug != null ? debug.agent : null; foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } @@ -1210,7 +1210,7 @@ namespace DotRecast.Detour.Crowd _telemetry.start("integrate"); foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } @@ -1229,7 +1229,7 @@ namespace DotRecast.Detour.Crowd foreach (CrowdAgent ag in agents) { long idx0 = ag.idx; - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } @@ -1286,7 +1286,7 @@ namespace DotRecast.Detour.Crowd foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } @@ -1303,7 +1303,7 @@ namespace DotRecast.Detour.Crowd _telemetry.start("moveAgents"); foreach (CrowdAgent ag in agents) { - if (ag.state != CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) + if (ag.state != CrowdAgentState.DT_CROWDAGENT_STATE_WALKING) { continue; } @@ -1314,8 +1314,8 @@ namespace DotRecast.Detour.Crowd ag.npos = ag.corridor.getPos(); // If not using path, truncate the corridor to just one poly. - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { ag.corridor.reset(ag.corridor.getFirstPoly(), ag.npos); ag.partial = false; @@ -1342,7 +1342,7 @@ namespace DotRecast.Detour.Crowd // Reset animation anim.active = false; // Prepare agent for walking. - ag.state = CrowdAgent.CrowdAgentState.DT_CROWDAGENT_STATE_WALKING; + ag.state = CrowdAgentState.DT_CROWDAGENT_STATE_WALKING; continue; } diff --git a/src/DotRecast.Detour.Crowd/CrowdAgent.cs b/src/DotRecast.Detour.Crowd/CrowdAgent.cs index ca06bbb..e2cd9d6 100644 --- a/src/DotRecast.Detour.Crowd/CrowdAgent.cs +++ b/src/DotRecast.Detour.Crowd/CrowdAgent.cs @@ -26,34 +26,34 @@ namespace DotRecast.Detour.Crowd { using static DotRecast.Core.RecastMath; + /// The type of navigation mesh polygon the agent is currently traversing. + /// @ingroup crowd + public enum CrowdAgentState + { + DT_CROWDAGENT_STATE_INVALID, + + /// < The agent is not in a valid state. + DT_CROWDAGENT_STATE_WALKING, + + /// < The agent is traversing a normal navigation mesh polygon. + DT_CROWDAGENT_STATE_OFFMESH, /// < The agent is traversing an off-mesh connection. + }; + + public enum MoveRequestState + { + DT_CROWDAGENT_TARGET_NONE, + DT_CROWDAGENT_TARGET_FAILED, + DT_CROWDAGENT_TARGET_VALID, + DT_CROWDAGENT_TARGET_REQUESTING, + DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE, + DT_CROWDAGENT_TARGET_WAITING_FOR_PATH, + DT_CROWDAGENT_TARGET_VELOCITY, + }; + /// Represents an agent managed by a #dtCrowd object. /// @ingroup crowd public class CrowdAgent { - /// The type of navigation mesh polygon the agent is currently traversing. - /// @ingroup crowd - public enum CrowdAgentState - { - DT_CROWDAGENT_STATE_INVALID, - - /// < The agent is not in a valid state. - DT_CROWDAGENT_STATE_WALKING, - - /// < The agent is traversing a normal navigation mesh polygon. - DT_CROWDAGENT_STATE_OFFMESH, /// < The agent is traversing an off-mesh connection. - }; - - public enum MoveRequestState - { - DT_CROWDAGENT_TARGET_NONE, - DT_CROWDAGENT_TARGET_FAILED, - DT_CROWDAGENT_TARGET_VALID, - DT_CROWDAGENT_TARGET_REQUESTING, - DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE, - DT_CROWDAGENT_TARGET_WAITING_FOR_PATH, - DT_CROWDAGENT_TARGET_VELOCITY, - }; - public readonly long idx; /// The type of mesh polygon the agent is traversing. (See: #CrowdAgentState) diff --git a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs index 93943af..8643e9d 100644 --- a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs +++ b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs @@ -250,8 +250,8 @@ public class NavMeshRenderer int col = DebugDraw.duTransCol(DebugDraw.areaToCol(vol.areaMod.getMaskedValue()), 32); for (int j = 0, k = vol.verts.Length - 3; j < vol.verts.Length; k = j, j += 3) { - float[] va = new float[] { vol.verts[k], vol.verts[k + 1], vol.verts[k + 2] }; - float[] vb = new float[] { vol.verts[j], vol.verts[j + 1], vol.verts[j + 2] }; + var va = Vector3f.Of(vol.verts[k], vol.verts[k + 1], vol.verts[k + 2]); + var vb = Vector3f.Of(vol.verts[j], vol.verts[j + 1], vol.verts[j + 2]); debugDraw.vertex(vol.verts[0], vol.hmax, vol.verts[2], col); debugDraw.vertex(vb[0], vol.hmax, vb[2], col); @@ -275,8 +275,8 @@ public class NavMeshRenderer int col = DebugDraw.duTransCol(DebugDraw.areaToCol(vol.areaMod.getMaskedValue()), 220); for (int j = 0, k = vol.verts.Length - 3; j < vol.verts.Length; k = j, j += 3) { - float[] va = new float[] { vol.verts[k], vol.verts[k + 1], vol.verts[k + 2] }; - float[] vb = new float[] { vol.verts[j], vol.verts[j + 1], vol.verts[j + 2] }; + var va = Vector3f.Of(vol.verts[k], vol.verts[k + 1], vol.verts[k + 2]); + var vb = Vector3f.Of(vol.verts[j], vol.verts[j + 1], vol.verts[j + 2]); debugDraw.vertex(va[0], vol.hmin, va[2], DebugDraw.duDarkenCol(col)); debugDraw.vertex(vb[0], vol.hmin, vb[2], DebugDraw.duDarkenCol(col)); debugDraw.vertex(va[0], vol.hmax, va[2], col); diff --git a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs index da769d6..120cd1c 100644 --- a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; +using System.Numerics; using DotRecast.Core; using DotRecast.Detour; using DotRecast.Recast.Demo.Builder; @@ -187,16 +188,14 @@ public class RecastDebugDraw : DebugDraw } OffMeshConnection con = tile.data.offMeshCons[i - tile.data.header.offMeshBase]; - float[] va = new float[] - { + Vector3f va = Vector3f.Of( tile.data.verts[p.verts[0] * 3], tile.data.verts[p.verts[0] * 3 + 1], tile.data.verts[p.verts[0] * 3 + 2] - }; - float[] vb = new float[] - { + ); + Vector3f vb = Vector3f.Of( tile.data.verts[p.verts[1] * 3], tile.data.verts[p.verts[1] * 3 + 1], tile.data.verts[p.verts[1] * 3 + 2] - }; + ); // Check to see if start and end end-points have links. bool startSet = false; @@ -356,17 +355,15 @@ public class RecastDebugDraw : DebugDraw } } - float[] v0 = new float[] - { + var v0 = Vector3f.Of( tile.data.verts[p.verts[j] * 3], tile.data.verts[p.verts[j] * 3 + 1], tile.data.verts[p.verts[j] * 3 + 2] - }; - float[] v1 = new float[] - { + ); + var v1 = Vector3f.Of( tile.data.verts[p.verts[(j + 1) % nj] * 3], tile.data.verts[p.verts[(j + 1) % nj] * 3 + 1], tile.data.verts[p.verts[(j + 1) % nj] * 3 + 2] - }; + ); // Draw detail mesh edges which align with the actual poly edge. // This is really slow. @@ -376,26 +373,24 @@ public class RecastDebugDraw : DebugDraw for (int k = 0; k < pd.triCount; ++k) { int t = (pd.triBase + k) * 4; - float[][] tv = new float[3][]; + Vector3f[] tv = new Vector3f[3]; for (int m = 0; m < 3; ++m) { int v = tile.data.detailTris[t + m]; if (v < p.vertCount) { - tv[m] = new float[] - { + tv[m] = Vector3f.Of( tile.data.verts[p.verts[v] * 3], tile.data.verts[p.verts[v] * 3 + 1], tile.data.verts[p.verts[v] * 3 + 2] - }; + ); } else { - tv[m] = new float[] - { + tv[m] = Vector3f.Of( tile.data.detailVerts[(pd.vertBase + (v - p.vertCount)) * 3], tile.data.detailVerts[(pd.vertBase + (v - p.vertCount)) * 3 + 1], tile.data.detailVerts[(pd.vertBase + (v - p.vertCount)) * 3 + 2] - }; + ); } } @@ -428,7 +423,7 @@ public class RecastDebugDraw : DebugDraw end(); } - static float distancePtLine2d(float[] pt, float[] p, float[] q) + static float distancePtLine2d(Vector3f pt, Vector3f p, Vector3f q) { float pqx = q[0] - p[0]; float pqz = q[2] - p[2]; @@ -1358,17 +1353,15 @@ public class RecastDebugDraw : DebugDraw continue; // Create new links - float[] va = new float[] - { + var va = Vector3f.Of( tile.data.verts[poly.verts[j] * 3], tile.data.verts[poly.verts[j] * 3 + 1], tile.data.verts[poly.verts[j] * 3 + 2] - }; - float[] vb = new float[] - { + ); + var vb = Vector3f.Of( tile.data.verts[poly.verts[(j + 1) % nv] * 3], tile.data.verts[poly.verts[(j + 1) % nv] * 3 + 1], tile.data.verts[poly.verts[(j + 1) % nv] * 3 + 2] - }; + ); if (side == 0 || side == 4) { diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs index 5c2e307..baca225 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdProfilingTool.cs @@ -327,13 +327,13 @@ public class CrowdProfilingTool private bool needsNewTarget(CrowdAgent ag) { - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_NONE + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) { return true; } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VALID) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VALID) { float dx = ag.targetPos[0] - ag.npos[0]; float dy = ag.targetPos[1] - ag.npos[1]; @@ -385,14 +385,14 @@ public class CrowdProfilingTool col = duRGBA(120, 80, 160, 128); } - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE) col = duLerpCol(col, duRGBA(255, 255, 32, 128), 128); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH) col = duLerpCol(col, duRGBA(255, 64, 32, 128), 128); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) col = duRGBA(255, 32, 16, 128); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) col = duLerpCol(col, duRGBA(64, 255, 0, 128), 128); dd.debugDrawCylinder(pos[0] - radius, pos[1] + radius * 0.1f, pos[2] - radius, pos[0] + radius, pos[1] + height, diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index aa76769..9180a48 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -578,14 +578,14 @@ public class CrowdTool : Tool Vector3f pos = ag.npos; int col = duRGBA(220, 220, 220, 128); - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE) col = duLerpCol(col, duRGBA(128, 0, 255, 128), 32); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH) col = duLerpCol(col, duRGBA(128, 0, 255, 128), 128); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) col = duRGBA(255, 32, 16, 128); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) col = duLerpCol(col, duRGBA(64, 255, 0, 128), 128); dd.debugDrawCylinder(pos[0] - radius, pos[1] + radius * 0.1f, pos[2] - radius, pos[0] + radius, pos[1] + height, @@ -637,14 +637,14 @@ public class CrowdTool : Tool Vector3f dvel = ag.dvel; int col = duRGBA(220, 220, 220, 192); - if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING - || ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE) + if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING + || ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_QUEUE) col = duLerpCol(col, duRGBA(128, 0, 255, 192), 48); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_WAITING_FOR_PATH) col = duLerpCol(col, duRGBA(128, 0, 255, 192), 128); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_FAILED) col = duRGBA(255, 32, 16, 192); - else if (ag.targetState == CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) + else if (ag.targetState == MoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) col = duLerpCol(col, duRGBA(64, 255, 0, 192), 128); dd.debugDrawCircle(pos[0], pos[1] + height, pos[2], radius, col, 2.0f);