Skip to content

Commit

Permalink
Fix SharedBroadphaseSystem.GetBroadphases (#5615)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored Jan 18, 2025
1 parent c463fc5 commit 43b991c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ END TEMPLATE-->

### Bugfixes

*None yet*
* Fixed `SharedBroadphaseSystem.GetBroadphases()` not returning the map itself, which was causing physics to not work properly off-grid.

### Other

Expand Down
45 changes: 29 additions & 16 deletions Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,46 +472,59 @@ public void Refilter(EntityUid uid, Fixture fixture, TransformComponent? xform =
TouchProxies(xform.MapUid.Value, matrix, fixture);
}

internal void GetBroadphases(MapId mapId, Box2 aabb,BroadphaseCallback callback)
internal void GetBroadphases(MapId mapId, Box2 aabb, BroadphaseCallback callback)
{
var internalState = (callback, _broadphaseQuery);

_mapManager.FindGridsIntersecting(mapId,
if (!_map.TryGetMap(mapId, out var map))
return;

if (_broadphaseQuery.TryGetComponent(map.Value, out var mapBroadphase))
callback((map.Value, mapBroadphase));

_mapManager.FindGridsIntersecting(map.Value,
aabb,
ref internalState,
static (
EntityUid uid,
MapGridComponent grid,
MapGridComponent _,
ref (BroadphaseCallback callback, EntityQuery<BroadphaseComponent> _broadphaseQuery) tuple) =>
{
if (!tuple._broadphaseQuery.TryComp(uid, out var broadphase))
return true;
if (tuple._broadphaseQuery.TryComp(uid, out var broadphase))
tuple.callback((uid, broadphase));

tuple.callback((uid, broadphase));
return true;
// Approx because we don't really need accurate checks for these most of the time.
}, approx: true, includeMap: true);
},
// Approx because we don't really need accurate checks for these most of the time.
approx: true,
includeMap: false);
}

internal void GetBroadphases<TState>(MapId mapId, Box2 aabb, ref TState state, BroadphaseCallback<TState> callback)
{
var internalState = (state, callback, _broadphaseQuery);

_mapManager.FindGridsIntersecting(mapId,
if (!_map.TryGetMap(mapId, out var map))
return;

if (_broadphaseQuery.TryGetComponent(map.Value, out var mapBroadphase))
callback((map.Value, mapBroadphase), ref state);

_mapManager.FindGridsIntersecting(map.Value,
aabb,
ref internalState,
static (
EntityUid uid,
MapGridComponent grid,
MapGridComponent _,
ref (TState state, BroadphaseCallback<TState> callback, EntityQuery<BroadphaseComponent> _broadphaseQuery) tuple) =>
{
if (!tuple._broadphaseQuery.TryComp(uid, out var broadphase))
return true;

tuple.callback((uid, broadphase), ref tuple.state);
if (tuple._broadphaseQuery.TryComp(uid, out var broadphase))
tuple.callback((uid, broadphase), ref tuple.state);
return true;
// Approx because we don't really need accurate checks for these most of the time.
}, approx: true, includeMap: true);
},
// Approx because we don't really need accurate checks for these most of the time.
approx: true,
includeMap: false);

state = internalState.state;
}
Expand Down

0 comments on commit 43b991c

Please sign in to comment.