Skip to content

Commit

Permalink
fix: Avoid physics query slowdown over time by rebuilding broadphase …
Browse files Browse the repository at this point in the history
…every frame (#962)

See #961 for context. There's a bug in parry2d involving incremental
update failing to balance broadphase BVH. Fully rebuilding BVH avoids
this issue, and we can get away with it due to few bodies in our game.
This was our previous behavior before supporting dynamic bodies and
relying on incremental update in physics pipeline, which turns out to be
broken.
  • Loading branch information
MaxCWhitehead authored Apr 6, 2024
1 parent d89e045 commit 0ade25b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/physics/collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,13 @@ impl<'a> CollisionWorld<'a> {
&collision_cache,
);

// Force a full rebuild of broadphase
// PhysicsPipeline step should incrementally update it, but due to an issue with
// incrementally rebalancing BVH in parry2d, the tree becomes unbalanced and query perf tanks.
// Rebuilding it every frame is quite fast for our game, and avoids this issue.
// https://github.com/fishfolk/jumpy/issues/961
query_pipeline.update(rigid_body_set, collider_set);

// Iter on each dynamic rigid-bodies that moved.
for rigid_body_handle in islands.active_dynamic_bodies() {
let rigid_body = rigid_body_set.get_mut(*rigid_body_handle).unwrap();
Expand Down

0 comments on commit 0ade25b

Please sign in to comment.