From 43b991c69066b89df9d6917180fe8b905b8ac41b Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Sat, 18 Jan 2025 14:37:54 +1100 Subject: [PATCH] Fix SharedBroadphaseSystem.GetBroadphases (#5615) --- RELEASE-NOTES.md | 2 +- .../Physics/Systems/SharedBroadphaseSystem.cs | 45 ++++++++++++------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 48a3e8aca7c..5656daa9729 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -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 diff --git a/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs b/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs index bec02a11eec..726509fdaff 100644 --- a/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs +++ b/Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs @@ -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 _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(MapId mapId, Box2 aabb, ref TState state, BroadphaseCallback 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 callback, EntityQuery _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; }