-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[Merged by Bors] - Made Time::time_since_startup return from last tick. #3264
Conversation
Looks great, thanks for the first contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value for seconds_since_startup
is computed at update time:
bevy/crates/bevy_core/src/time/time.rs
Lines 34 to 44 in 4423a2f
pub(crate) fn update_with_instant(&mut self, instant: Instant) { | |
if let Some(last_update) = self.last_update { | |
self.delta = instant - last_update; | |
self.delta_seconds_f64 = self.delta.as_secs_f64(); | |
self.delta_seconds = self.delta.as_secs_f32(); | |
} | |
let duration_since_startup = instant - self.startup; | |
self.seconds_since_startup = duration_since_startup.as_secs_f64(); | |
self.last_update = Some(instant); | |
} |
In that function,
duration_since_startup
is also computed. Could we save it in that struct instead of recalculating it when calling time_since_startup
?
@mockersf good idea! I'll work on that now. |
As requested in bevyengine#3264.
I made that change @mockersf |
I don't think that CI error in bevy_render is anything to do with my code. |
CI error should be fixed (#3269) if you rebase on main |
As discussed in bevyengine#3259 Also added unit tests for it.
As requested in bevyengine#3264.
I rebased and pushed. |
Good call! Way more useful this way. I agree that pre-computing seconds-since-startup is a good call. There are enough ops in the Duration -> "float seconds" conversion that the extra internal complexity seems worth it when this function might get called hundreds or thousands of times per frame. |
bors r+ |
Also added unit tests for it.
Objective
Solution