Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SharedBroadphaseSystem.GetBroadphases #5615

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading