-
-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify physics time APIs with Time<Physics>
and Time<Substeps>
#214
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c3710a0
to
b27370f
Compare
…into physics-clocks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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, bevy_xpbd has the
DeltaTime
,SubDeltaTime
,PhysicsTimestep
,PhysicsTimescale
andPhysicsLoop
resources for managing logic related to time and scheduling. Having so many separate resources can be confusing and inconvenient for users.The
DeltaTime
andSubDeltaTime
resources also create a contextual divide into two system groups: those that run in thePhysicsSchedule
and those that run in theSubstepSchedule
. However, a lot of systems aren't necessarily tied to a specific schedule in functionality; what if you wanted to run position integration outside of the substepping loop? It would be better if all of these systems had a shared time resource that could just be interpreted differently based on the schedule.Solution
Replace
DeltaTime
,SubDeltaTime
,PhysicsTimestep
,PhysicsTimescale
andPhysicsLoop
withTime<Physics>
andTime<Substeps>
using the new time API in Bevy 0.12.The generic
Time
resource is replaced byTime<Physics>
in thePhysicsSchedule
andTime<Substeps>
in theSubstepSchedule
. This means that systems are now agnostic over the time resource used, which also reduces cognitive overhead for users, as they can just useTime
instead of e.g.DeltaTime
in thePhysicsSchedule
.The timestep is still configurable, as
Physics
contains anTimestepMode
enum like the oldPhysicsTimestep
. To match Bevy's APIs, the timestep also uses aDuration
instead of a single scalar value.Physics
has helper methods likefixed_hz
,fixed_once_hz
andvariable
to reduce the boilerplate a bit.The physics loop is now also controlled using
Time<Physics>
and its propertiespaused
andrelative_speed
.Migration guide
DeltaTime
inPhysicsSchedule
and everySubDeltaTime
inSubstepSchedule
withTime
, elsewhere explicitly useTime<Physics>
andTime<Substep>
DeltaTime
, advance theTime<Physics>
clock usingtime.advance_by(...)
PhysicsTimestep
withTime::new_with(Physics::FooBar(...))
PhysicsLoop::pause/resume
withTime::<Physics>::pause/unpause
PhysicsLoop::step
with advancing the physics clock usingTime::<Physics>::advance_by
PhysicsTimescale
usage withTime::<Physics>::with/set_relative_speed
Todo
Future work
It'd be nice to use
Time<Virtual>
andTime<Fixed>
directly, but this has limitations that currently make it not viable.