Skip to content

Commit

Permalink
SOH-2 - Span<float> pat = stackalloc float[(DT_MAX_PATTERN_DIVS * DT_…
Browse files Browse the repository at this point in the history
…MAX_PATTERN_RINGS + 1) * 2];

- #41
  • Loading branch information
ikpil committed May 1, 2024
1 parent a84d661 commit 1e0ef4f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 3. This notice may not be removed or altered from any source distribution.
*/

using System;
using System.Runtime.CompilerServices;
using DotRecast.Core;
using DotRecast.Core.Numerics;

Expand All @@ -27,11 +28,9 @@ namespace DotRecast.Detour.Crowd
{
public class DtObstacleAvoidanceQuery
{
public const int DT_MAX_PATTERN_DIVS = 32;

/// < Max numver of adaptive divs.
public const int DT_MAX_PATTERN_DIVS = 32; // < Max numver of adaptive divs.
public const int DT_MAX_PATTERN_RINGS = 4;

public const float DT_PI = 3.14159265f;

private DtObstacleAvoidanceParams m_params;
private float m_invHorizTime;
Expand Down Expand Up @@ -362,7 +361,8 @@ public int SampleVelocityGrid(RcVec3f pos, float rad, float vmax, RcVec3f vel, R
}

// vector normalization that ignores the y-component.
void DtNormalize2D(float[] v)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void DtNormalize2D(Span<float> v)
{
float d = MathF.Sqrt(v[0] * v[0] + v[2] * v[2]);
if (d == 0)
Expand All @@ -373,7 +373,8 @@ void DtNormalize2D(float[] v)
}

// vector normalization that ignores the y-component.
RcVec3f DtRotate2D(float[] v, float ang)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
RcVec3f DtRotate2D(Span<float> v, float ang)
{
RcVec3f dest = new RcVec3f();
float c = MathF.Cos(ang);
Expand All @@ -384,7 +385,6 @@ RcVec3f DtRotate2D(float[] v, float ang)
return dest;
}

static readonly float DT_PI = 3.14159265f;

public int SampleVelocityAdaptive(RcVec3f pos, float rad, float vmax, RcVec3f vel, RcVec3f dvel, out RcVec3f nvel,
DtObstacleAvoidanceParams option,
Expand All @@ -402,7 +402,7 @@ public int SampleVelocityAdaptive(RcVec3f pos, float rad, float vmax, RcVec3f ve
debug.Reset();

// Build sampling pattern aligned to desired velocity.
float[] pat = new float[(DT_MAX_PATTERN_DIVS * DT_MAX_PATTERN_RINGS + 1) * 2];
Span<float> pat = stackalloc float[(DT_MAX_PATTERN_DIVS * DT_MAX_PATTERN_RINGS + 1) * 2];
int npat = 0;

int ndivs = m_params.adaptiveDivs;
Expand All @@ -416,7 +416,7 @@ public int SampleVelocityAdaptive(RcVec3f pos, float rad, float vmax, RcVec3f ve
float sa = MathF.Sin(da);

// desired direction
float[] ddir = new float[6];
Span<float> ddir = stackalloc float[6];
ddir[0] = dvel.X;
ddir[1] = dvel.Y;
ddir[2] = dvel.Z;
Expand Down

0 comments on commit 1e0ef4f

Please sign in to comment.