Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

fluffysquirrels
Copy link
Contributor

Also added unit tests for it.

Objective

Solution

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Dec 6, 2021
@alice-i-cecile alice-i-cecile added A-Core Common functionality for all bevy apps C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Dec 6, 2021
@alice-i-cecile alice-i-cecile added S-Needs-Migration-Guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Dec 6, 2021
@alice-i-cecile
Copy link
Member

Looks great, thanks for the first contribution!

Copy link
Member

@mockersf mockersf left a 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:

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?

@fluffysquirrels
Copy link
Contributor Author

@mockersf good idea! I'll work on that now.

fluffysquirrels pushed a commit to fluffysquirrels/bevy that referenced this pull request Dec 6, 2021
@fluffysquirrels
Copy link
Contributor Author

I made that change @mockersf

@fluffysquirrels
Copy link
Contributor Author

I don't think that CI error in bevy_render is anything to do with my code.

@mockersf
Copy link
Member

mockersf commented Dec 6, 2021

CI error should be fixed (#3269) if you rebase on main

@fluffysquirrels
Copy link
Contributor Author

I rebased and pushed.

@cart
Copy link
Member

cart commented Dec 7, 2021

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.

@cart
Copy link
Member

cart commented Dec 7, 2021

bors r+

bors bot pushed a commit that referenced this pull request Dec 7, 2021
Also added unit tests for it.

# Objective

- Fixes #3259 

## Solution

- As discussed in #3259

Co-authored-by: Alex Helfet <alex.helfet@gmail.com>
@bors bors bot changed the title Made Time::time_since_startup return from last tick. [Merged by Bors] - Made Time::time_since_startup return from last tick. Dec 7, 2021
@bors bors bot closed this Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Core Common functionality for all bevy apps C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time::time_since_startup is inconsistent
4 participants