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 the PhysicsChangeTicks 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.
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.