Skip to content

Commit

Permalink
Calculate Time.time_since_startup on update()
Browse files Browse the repository at this point in the history
As requested in #3264.
  • Loading branch information
Alex Helfet committed Dec 6, 2021
1 parent 9b7a703 commit 9de47f5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/bevy_core/src/time/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Time {
delta_seconds_f64: f64,
delta_seconds: f32,
seconds_since_startup: f64,
time_since_startup: Duration,
startup: Instant,
}

Expand All @@ -20,6 +21,7 @@ impl Default for Time {
startup: Instant::now(),
delta_seconds_f64: 0.0,
seconds_since_startup: 0.0,
time_since_startup: Duration::from_secs(0),
delta_seconds: 0.0,
}
}
Expand All @@ -38,8 +40,8 @@ impl Time {
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.time_since_startup = instant - self.startup;
self.seconds_since_startup = self.time_since_startup.as_secs_f64();
self.last_update = Some(instant);
}

Expand Down Expand Up @@ -81,7 +83,7 @@ impl Time {

/// The ['Duration'] from startup to the last update
pub fn time_since_startup(&self) -> Duration {
self.last_update.unwrap_or(self.startup) - self.startup
self.time_since_startup
}
}

Expand Down

0 comments on commit 9de47f5

Please sign in to comment.