Handle sleeping logic before physics #425
Merged
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.
Objective
Currently, sleeping and waking is handled after physics. This leads to a one frame delay before bodies are woken up by things like velocity changes or applied external forces. It can even cause
ExternalImpulse
to do nothing, because the body is only woken up by the time the impulse should've already been applied and cleared.Solution
Run sleeping logic before physics. User changes are detected by comparing component change ticks to a
LastPhysicsTick
resource. This refactor also lets us get rid of thePhysicsChangeTicks
component, which was previously stored and updated for all physics entities.PhysicsStepSet::Sleeping
now technically doesn't have much sleeping logic anymore, but that can be reworked in a follow-up.