heap memory optimization

This commit is contained in:
ikpil 2023-05-03 00:11:45 +09:00
parent ebb77c5465
commit cd39cbbd36
3 changed files with 30 additions and 12 deletions

View File

@ -0,0 +1,14 @@
namespace DotRecast.Detour.Crowd
{
public struct IsectRaySegResult
{
public readonly bool result;
public readonly float htmin;
public IsectRaySegResult(bool result, float htmin)
{
this.result = result;
this.htmin = htmin;
}
}
}

View File

@ -65,7 +65,7 @@ namespace DotRecast.Detour.Crowd
public bool touch;
}
private ObstacleAvoidanceParams m_params;
private float m_invHorizTime;
private float m_vmax;
@ -120,7 +120,7 @@ namespace DotRecast.Detour.Crowd
{
if (m_nsegments >= m_maxSegments)
return;
ObstacleSegment seg = m_segments[m_nsegments++];
seg.p = p;
seg.q = q;
@ -207,21 +207,24 @@ namespace DotRecast.Detour.Crowd
return new SweepCircleCircleResult(true, (b - rd) * a, (b + rd) * a);
}
Tuple<bool, float> isectRaySeg(Vector3f ap, Vector3f u, Vector3f bp, Vector3f bq)
IsectRaySegResult isectRaySeg(Vector3f ap, Vector3f u, Vector3f bp, Vector3f bq)
{
Vector3f v = vSub(bq, bp);
Vector3f w = vSub(ap, bp);
float d = vPerp2D(u, v);
if (Math.Abs(d) < 1e-6f)
return Tuple.Create(false, 0f);
return new IsectRaySegResult(false, 0f);
d = 1.0f / d;
float t = vPerp2D(v, w) * d;
if (t < 0 || t > 1)
return Tuple.Create(false, 0f);
return new IsectRaySegResult(false, 0f);
float s = vPerp2D(u, w) * d;
if (s < 0 || s > 1)
return Tuple.Create(false, 0f);
return Tuple.Create(true, t);
return new IsectRaySegResult(false, 0f);
return new IsectRaySegResult(true, t);
}
/**
@ -310,10 +313,11 @@ namespace DotRecast.Detour.Crowd
}
else
{
Tuple<bool, float> ires = isectRaySeg(pos, vcand, seg.p, seg.q);
if (!ires.Item1)
var ires = isectRaySeg(pos, vcand, seg.p, seg.q);
if (!ires.result)
continue;
htmin = ires.Item2;
htmin = ires.htmin;
}
// Avoid less when facing walls.
@ -523,4 +527,4 @@ namespace DotRecast.Detour.Crowd
return Tuple.Create(ns, nvel);
}
}
}
}

View File

@ -20,7 +20,7 @@ freely, subject to the following restrictions:
namespace DotRecast.Detour.Crowd
{
public class SweepCircleCircleResult
public struct SweepCircleCircleResult
{
public readonly bool intersection;
public readonly float htmin;