Fix shape lookups for non-hard fixtures (#4583)

This commit is contained in:
Leon Friedrich
2023-11-20 18:15:27 +13:00
committed by GitHub
parent c21b6c993c
commit 54d6552164

View File

@@ -154,34 +154,35 @@ public sealed partial class EntityLookupSystem
if (!state.Query.TryGetComponent(value, out var comp))
return true;
if (!state.FixturesQuery.TryGetComponent(value, out var fixtures))
{
var position = state.TransformSystem.GetWorldPosition(value);
if (state.Fixtures.TestPoint(state.Shape, state.Transform, position))
goto found;
return true;
}
var intersectingTransform = state.Physics.GetPhysicsTransform(value);
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!state.Sensors && !fixture.Hard)
continue;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
if (state.FixturesQuery.TryGetComponent(value, out var fixtures))
{
bool anyFixture = false;
foreach (var fixture in fixtures.Fixtures.Values)
{
if (state.Manifolds.TestOverlap(state.Shape, 0, fixture.Shape, i, state.Transform, intersectingTransform))
if (!state.Sensors && !fixture.Hard)
continue;
anyFixture = true;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
goto found;
if (state.Manifolds.TestOverlap(state.Shape, 0, fixture.Shape, i, state.Transform,
intersectingTransform))
{
state.Intersecting.Add((value, comp));
return true;
}
}
}
if (anyFixture)
return true;
}
return true;
if (state.Fixtures.TestPoint(state.Shape, state.Transform, intersectingTransform.Position))
state.Intersecting.Add((value, comp));
found:
state.Intersecting.Add((value, comp));
return true;
}, localAABB, (flags & LookupFlags.Approximate) != 0x0);
}
@@ -194,34 +195,35 @@ public sealed partial class EntityLookupSystem
if (!state.Query.TryGetComponent(value, out var comp))
return true;
if (!state.FixturesQuery.TryGetComponent(value, out var fixtures))
{
var position = state.TransformSystem.GetWorldPosition(value);
if (state.Fixtures.TestPoint(state.Shape, state.Transform, position))
goto found;
return true;
}
var intersectingTransform = state.Physics.GetPhysicsTransform(value);
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!state.Sensors && !fixture.Hard)
continue;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
if (state.FixturesQuery.TryGetComponent(value, out var fixtures))
{
bool anyFixture = false;
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!state.Manifolds.TestOverlap(state.Shape, 0, fixture.Shape, i, state.Transform, intersectingTransform))
if (!state.Sensors && !fixture.Hard)
continue;
anyFixture = true;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
goto found;
if (state.Manifolds.TestOverlap(state.Shape, 0, fixture.Shape, i, state.Transform,
intersectingTransform))
{
state.Intersecting.Add((value, comp));
return true;
}
}
}
if (anyFixture)
return true;
}
return true;
if (state.Fixtures.TestPoint(state.Shape, state.Transform, intersectingTransform.Position))
state.Intersecting.Add((value, comp));
found:
state.Intersecting.Add((value, comp));
return true;
}, localAABB, (flags & LookupFlags.Approximate) != 0x0);
}
@@ -554,10 +556,10 @@ public sealed partial class EntityLookupSystem
foreach (var (uid, comp) in EntityManager.GetAllComponents(type, true))
{
var xform = _xformQuery.GetComponent(uid);
var xFormPosition = _transform.GetWorldPosition(xform);
var (pos, rot) = _transform.GetWorldPositionRotation(xform);
if (xform.MapID != mapId ||
!worldAABB.Contains(xFormPosition) ||
!worldAABB.Contains(pos) ||
((flags & LookupFlags.Contained) == 0x0 &&
_container.IsEntityOrParentInContainer(uid, _metaQuery.GetComponent(uid), xform)))
{
@@ -566,14 +568,15 @@ public sealed partial class EntityLookupSystem
if (_fixturesQuery.TryGetComponent(uid, out var fixtures))
{
var xFormRotation = _transform.GetWorldRotation(xform, _xformQuery);
var transform = new Transform(xFormPosition, xFormRotation);
var transform = new Transform(pos, rot);
bool anyFixture = false;
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!sensors && !fixture.Hard)
continue;
anyFixture = true;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
if (_manifoldManager.TestOverlap(shape, 0, fixture.Shape, i, shapeTransform, transform))
@@ -583,16 +586,14 @@ public sealed partial class EntityLookupSystem
}
}
continue;
}
else
{
if (!_fixtures.TestPoint(shape, shapeTransform, xFormPosition))
if (anyFixture)
continue;
}
found:
if (!_fixtures.TestPoint(shape, shapeTransform, pos))
continue;
found:
intersecting.Add((uid, comp));
}
}
@@ -630,24 +631,21 @@ public sealed partial class EntityLookupSystem
while (query.MoveNext(out var uid, out var comp, out var xform))
{
var xFormPosition = _transform.GetWorldPosition(xform);
var (pos, rot) = _transform.GetWorldPositionRotation(xform);
if (xform.MapID != mapId ||
!worldAABB.Contains(xFormPosition))
{
if (xform.MapID != mapId || !worldAABB.Contains(pos))
continue;
}
if (_fixturesQuery.TryGetComponent(uid, out var fixtures))
{
var xFormRotation = _transform.GetWorldRotation(xform, _xformQuery);
var transform = new Transform(xFormPosition, xFormRotation);
var transform = new Transform(pos, rot);
bool anyFixture = false;
foreach (var fixture in fixtures.Fixtures.Values)
{
if (!sensors && !fixture.Hard)
continue;
anyFixture = true;
for (var i = 0; i < fixture.Shape.ChildCount; i++)
{
if (_manifoldManager.TestOverlap(shape, 0, fixture.Shape, i, shapeTransform, transform))
@@ -657,14 +655,13 @@ public sealed partial class EntityLookupSystem
}
}
continue;
}
else
{
if (!_fixtures.TestPoint(shape, shapeTransform, xFormPosition))
if (anyFixture)
continue;
}
if (!_fixtures.TestPoint(shape, shapeTransform, pos))
continue;
found:
entities.Add((uid, comp));
}