Refactor post-step operations in Jolt module to be done as needed #101815
+88
−59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #101695.
Fixes #101721.
The general theme of this PR is to remove
JoltObject3D::post_step
, and instead replace whatever previously happened inJoltBody3D::post_step
andJoltArea3D::post_step
with more specific operations that are invoked as needed rather than for every active/awake body in the simulation on every physics step.What mainly prompted this change was that
JoltShapedObject3D::previous_jolt_shape
was until now being cleared as part ofJoltShapedObject3D::post_step
, which worked fine prior to #100983 due topost_step
always being invoked for every single body, sleeping or otherwise, but as of #100983post_step
will only be called for active/awake bodies. This meant thatprevious_jolt_shape
would never be cleared for something likeStaticBody3D
, which is always sleeping, leading to the forcedArea3D
enter/exit events emitted byJoltContactListener3D::_flush_area_shifts
to be queued up every single physics step as opposed to just once.The solution to this is to add a new list in
JoltSpace3D
, calledshapes_changed_list
, that keeps track of anyJoltShapedObject3D
that have changed their shape since the last physics step, and use that list to clear all of their respectiveprevious_jolt_shape
after we've checked against it inJoltContactListener3D::post_step
.However, seeing as how this clearing of
previous_jolt_shape
was the only thing happening inJoltBody3D::post_step
, we have no need to call it at all for bodies anymore. This meant that the only object being post-stepped wasJoltArea3D
, which currently uses it to check if there are any pending events and queue up the invocation of itsJoltArea3D::call_queries
for the next physics frame if there are, which upon closer inspection wasn't strictly necessary. We may just as well queue upJoltArea3D::call_queries
as the individual events are being added instead, obviating the need forJoltArea3D::post_step
(and thus alsoJoltObject3D::post_step
) altogether.Removing
JoltArea3D::post_step
also happens to resolve #101695, asJoltArea3D::post_step
wasn't invoking the base implementation ofJoltShapedObject3D::post_step
, leading to itsprevious_jolt_shape
never being cleared either.