bevy
bevy copied to clipboard
Time trackers
Objective
Users currently need to update timers and stopwatches themselves. This introduces 2 main issues:
- Users may forget to update their timers.
- Timers read from both
UpdateandFixedUpdateneed special considerations when updating them
Solution
- Introduce 2 new component versions of timers and stopwatches.
-
Updating*time trackers track time based on their generic argument (e.g.UpdatingTimer<Virtual>will trackTime<Virtual>). -
Mixed*time trackers track both virtual and fixed time and correctly report time based on which schedule they're read from.
-
- Introduce a
TimeTrackertrait defining how to update a time tracker. The intent is to eventually provide a derive macro. - Introduce a
Contexttrait to distinguishTime<()>from all the time types. This is used to constrain what time type the updating time trackers track. - Introduce a
TimesWithContextto define what times aTimeTrackertracks. - Introduce a
TimeTrackingAppExtensiontrait that helps with registering user defined time trackers into the app.
The `TimeTracker` trait
pub trait TimeTracker {
type Time: TimesWithContext;
fn update(
&mut self,
time: &<<Self::Time as TimesWithContext>::AsSystemParam<'_> as SystemParam>::Item<'_, '_>,
);
fn enter_fixed_update(&mut self) {}
fn exit_fixed_update(&mut self) {}
}
Closes #13420.
Future work
- A
TimeTrackerderive macro. - Automatic cleanup of finished time trackers.
Testing
- Did you test these changes? If so, how?
- Are there any parts that need more testing?
- How can other people (reviewers) test your changes? Is there anything specific they need to know?
- If relevant, what platforms did you test these changes on, and are there any important ones you can't test?
Showcase
This section is optional. If this PR does not include a visual change or does not add a new feature, you can delete this section.
- Help others understand the result of this PR by showcasing your awesome work!
- If this PR adds a new feature or public API, consider adding a brief pseudo-code snippet of it in action
- If this PR includes a visual change, consider adding a screenshot, GIF, or video
- If you want, you could even include a before/after comparison!
- If the Migration Guide adequately covers the changes, you can delete this section
While a showcase should aim to be brief and digestible, you can use a toggleable section to save space on longer showcases:
Click to view showcase
println!("My super cool code.");