Skip to content

Commit

Permalink
Relative lookup fix
Browse files Browse the repository at this point in the history
Some of the transforms weren't being transformed, added another test.
  • Loading branch information
metalgearsloth committed Aug 31, 2024
1 parent ab6bd19 commit 98fa764
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Robust.Shared/GameObjects/Systems/EntityLookup.Queries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private bool AnyEntitiesIntersecting(MapId mapId,
var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, uid);
var localAabb = state.Shape.ComputeAABB(localTransform, 0);
if (state.Lookup.AnyEntitiesIntersecting(uid, state.Shape, localAabb, state.Transform, state.Flags, ignored: state.Ignored))
if (state.Lookup.AnyEntitiesIntersecting(uid, state.Shape, localAabb, localTransform, state.Flags, ignored: state.Ignored))
{
state.Found = true;
return false;
Expand All @@ -266,7 +266,7 @@ private bool AnyEntitiesIntersecting(MapId mapId,
var mapUid = _map.GetMapOrInvalid(mapId);
var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, mapUid);
var localAabb = state.Shape.ComputeAABB(localTransform, 0);
state.Found = AnyEntitiesIntersecting(mapUid, shape, localAabb, shapeTransform, flags, ignored);
state.Found = AnyEntitiesIntersecting(mapUid, shape, localAabb, localTransform, flags, ignored);
}

return state.Found;
Expand Down Expand Up @@ -568,7 +568,7 @@ public HashSet<EntityUid> GetEntitiesIntersecting(MapId mapId, Box2Rotated world
state.intersecting,
state.shape,
localAabb,
state.transform,
localTransform,
state.flags);
return true;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,15 @@ public void GetEntitiesIntersecting(Type type, MapId mapId, IPhysShape shape, Tr
{
var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, uid);
var localAabb = state.Shape.ComputeAABB(localTransform, 0);
state.Lookup.AddEntitiesIntersecting(uid, state.Intersecting, state.Shape, localAabb, state.Transform, state.Flags, state.Query);
state.Lookup.AddEntitiesIntersecting(uid, state.Intersecting, state.Shape, localAabb, localTransform, state.Flags, state.Query);
return true;
}, approx: true, includeMap: false);

var mapUid = _map.GetMapOrInvalid(mapId);
var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, mapUid);
var localAabb = state.Shape.ComputeAABB(localTransform, 0);

AddEntitiesIntersecting(mapUid, intersecting, shape, localAabb, shapeTransform, flags, query);
AddEntitiesIntersecting(mapUid, intersecting, shape, localAabb, localTransform, flags, query);

AddContained(intersecting, flags, query);
}
Expand Down Expand Up @@ -586,7 +586,7 @@ public void GetEntitiesIntersecting<T>(MapId mapId, IPhysShape shape, Transform
{
var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, uid);
var localAabb = state.Shape.ComputeAABB(localTransform, 0);
state.Lookup.AddEntitiesIntersecting(uid, state.Intersecting, state.Shape, localAabb, state.Transform, state.Flags, state.Query);
state.Lookup.AddEntitiesIntersecting(uid, state.Intersecting, state.Shape, localAabb, localTransform, state.Flags, state.Query);
return true;
}, approx: true, includeMap: false);

Expand All @@ -595,7 +595,7 @@ public void GetEntitiesIntersecting<T>(MapId mapId, IPhysShape shape, Transform
var localTransform = state.Physics.GetRelativePhysicsTransform(state.Transform, mapUid);
var localAabb = state.Shape.ComputeAABB(localTransform, 0);

AddEntitiesIntersecting(mapUid, entities, shape, localAabb, shapeTransform, flags, query);
AddEntitiesIntersecting(mapUid, entities, shape, localAabb, localTransform, flags, query);
AddContained(entities, flags, query);
}
}
Expand Down Expand Up @@ -678,8 +678,8 @@ public HashSet<T> GetComponentsInRange<T>(MapId mapId, Vector2 worldPos, float r

public void GetEntitiesInRange<T>(MapId mapId, Vector2 worldPos, float range, HashSet<Entity<T>> entities, LookupFlags flags = DefaultFlags) where T : IComponent
{
var shape = new PhysShapeCircle(range);
var transform = new Transform(worldPos, 0f);
var shape = new PhysShapeCircle(range, worldPos);
var transform = Physics.Transform.Empty;

GetEntitiesInRange(mapId, shape, transform, entities, flags);
}
Expand Down
3 changes: 3 additions & 0 deletions Robust.UnitTesting/Shared/EntityLookup_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public sealed class EntityLookupTest
new TestCaseData(false, new MapCoordinates(new Vector2(10f, 10f), MapId), new MapCoordinates(new Vector2(9.5f, 9.5f), MapId), 0.5f, false),
// Close but no cigar
new TestCaseData(false, new MapCoordinates(new Vector2(10f, 10f), MapId), new MapCoordinates(new Vector2(9f, 9f), MapId), 0.5f, false),

// Big offset
new TestCaseData(true, new MapCoordinates(new Vector2(100f, 0f), MapId), new MapCoordinates(new Vector2(100f, 0f), MapId), 0.25f, true),
};

// Remember this test data is relative.
Expand Down

0 comments on commit 98fa764

Please sign in to comment.