Skip to content
Permalink
Browse files

[Physics] Provide public access to callbacks' recycle and buffer

  • Loading branch information
Eideren committed Jun 26, 2019
1 parent c527b17 commit ae1f4b4fb5e31cca18741af4d409cbe19f40b998
Showing with 24 additions and 12 deletions.
  1. +24 −12 sources/engine/Xenko.Physics/Simulation.cs
@@ -995,16 +995,16 @@ private class XenkoAllHitsConvexResultCallback : XenkoReusableConvexResultCallba
[ThreadStatic]
static XenkoAllHitsConvexResultCallback shared;

private IList<HitResult> resultsList;
public IList<HitResult> ResultsList { get; set; }

public XenkoAllHitsConvexResultCallback(IList<HitResult> results)
{
resultsList = results;
ResultsList = results;
}

public override float AddSingleResult(ref BulletSharp.LocalConvexResult convexResult, bool normalInWorldSpace)
{
resultsList.Add(ComputeHitResult(ref convexResult, normalInWorldSpace));
ResultsList.Add(ComputeHitResult(ref convexResult, normalInWorldSpace));
return convexResult.m_hitFraction;
}

@@ -1014,7 +1014,7 @@ public static XenkoAllHitsConvexResultCallback Shared(IList<HitResult> buffer, C
{
shared = new XenkoAllHitsConvexResultCallback(buffer);
}
shared.resultsList = buffer;
shared.ResultsList = buffer;
shared.Recycle(filterGroup, filterMask);
return shared;
}
@@ -1043,13 +1043,19 @@ public override float AddSingleResult(ref BulletSharp.LocalConvexResult convexRe
return fraction;
}

public override void Recycle(CollisionFilterGroups filterGroup = CollisionFilterGroups.DefaultFilter, CollisionFilterGroupFlags filterMask = (CollisionFilterGroupFlags)(-1))
{
base.Recycle(filterGroup, filterMask);
closestFraction = null;
closestHit = default;
}

public static XenkoClosestConvexResultCallback Shared(CollisionFilterGroups filterGroup = DefaultGroup, CollisionFilterGroupFlags filterMask = DefaultFlags)
{
if (shared == null)
{
shared = new XenkoClosestConvexResultCallback();
}
shared.closestFraction = null;
shared.Recycle(filterGroup, filterMask);
return shared;
}
@@ -1060,16 +1066,16 @@ private class XenkoAllHitsRayResultCallback : XenkoReusableRayResultCallback
[ThreadStatic]
static XenkoAllHitsRayResultCallback shared;

private IList<HitResult> resultsList;
public IList<HitResult> ResultsList { get; set; }

public XenkoAllHitsRayResultCallback(ref Vector3 from, ref Vector3 to, IList<HitResult> results) : base(ref from, ref to)
{
resultsList = results;
ResultsList = results;
}

public override float AddSingleResult(ref BulletSharp.LocalRayResult rayResult, bool normalInWorldSpace)
{
resultsList.Add(ComputeHitResult(ref rayResult, normalInWorldSpace));
ResultsList.Add(ComputeHitResult(ref rayResult, normalInWorldSpace));
return rayResult.m_hitFraction;
}

@@ -1079,7 +1085,7 @@ public static XenkoAllHitsRayResultCallback Shared(ref Vector3 from, ref Vector3
{
shared = new XenkoAllHitsRayResultCallback(ref from, ref to, buffer);
}
shared.resultsList = buffer;
shared.ResultsList = buffer;
shared.Recycle(ref from, ref to, filterGroup, filterMask);
return shared;
}
@@ -1114,13 +1120,19 @@ public override float AddSingleResult(ref BulletSharp.LocalRayResult rayResult,
return fraction;
}

public override void Recycle(ref Vector3 from, ref Vector3 to, CollisionFilterGroups filterGroup = DefaultGroup, CollisionFilterGroupFlags filterMask = DefaultFlags)
{
base.Recycle(ref from, ref to, filterGroup, filterMask);
closestFraction = null;
closestHit = default;
}

public static XenkoClosestRayResultCallback Shared(ref Vector3 from, ref Vector3 to, CollisionFilterGroups filterGroup = DefaultGroup, CollisionFilterGroupFlags filterMask = DefaultFlags)
{
if (shared == null)
{
shared = new XenkoClosestRayResultCallback(ref from, ref to);
}
shared.closestFraction = null;
shared.Recycle(ref from, ref to, filterGroup, filterMask);
return shared;
}
@@ -1161,7 +1173,7 @@ public HitResult ComputeHitResult(ref BulletSharp.LocalRayResult rayResult, bool
};
}

protected void Recycle(ref Vector3 from, ref Vector3 to, CollisionFilterGroups filterGroup = DefaultGroup, CollisionFilterGroupFlags filterMask = DefaultFlags)
public virtual void Recycle(ref Vector3 from, ref Vector3 to, CollisionFilterGroups filterGroup = DefaultGroup, CollisionFilterGroupFlags filterMask = DefaultFlags)
{
RayFromWorld = from;
RayToWorld = to;
@@ -1199,7 +1211,7 @@ public HitResult ComputeHitResult(ref BulletSharp.LocalConvexResult convexResult
};
}

protected void Recycle(CollisionFilterGroups filterGroup = DefaultGroup, CollisionFilterGroupFlags filterMask = DefaultFlags)
public virtual void Recycle(CollisionFilterGroups filterGroup = DefaultGroup, CollisionFilterGroupFlags filterMask = DefaultFlags)
{
ClosestHitFraction = float.PositiveInfinity;
CollisionFilterGroup = (int)filterGroup;

0 comments on commit ae1f4b4

Please sign in to comment.
You can’t perform that action at this time.