From a6b540f85a137cfc3abc7a5475bdcb69a304a656 Mon Sep 17 00:00:00 2001 From: Eliton Machado da Silva Date: Tue, 13 Sep 2022 22:41:29 +0000 Subject: [PATCH] Stopwatch elapsed secs f64 (#5978) # Objective While coding in bevy I needed to get the elapsed time of a stopwatch as f64. I found it quite odd there are functions on Timer to get time as f64 but not on the Stopwatch. ## Solution - added a function that returns the `Stopwatch` elapsed time as `f64` --- ## Changelog ### Added - Added a function to get `Stopwatch` elapsed time as `f64` ### Fixed - The Stopwatch elapsed function had a wrong docs link --- crates/bevy_time/src/stopwatch.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/bevy_time/src/stopwatch.rs b/crates/bevy_time/src/stopwatch.rs index cb9bd953f0e9f..bb92bd25868c8 100644 --- a/crates/bevy_time/src/stopwatch.rs +++ b/crates/bevy_time/src/stopwatch.rs @@ -58,7 +58,8 @@ impl Stopwatch { /// /// # See Also /// - /// [`elapsed_secs`](Stopwatch::elapsed) - if a `f32` value is desirable instead. + /// [`elapsed_secs`](Stopwatch::elapsed_secs) - if a `f32` value is desirable instead. + /// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if a `f64` is desirable instead. #[inline] pub fn elapsed(&self) -> Duration { self.elapsed @@ -79,11 +80,24 @@ impl Stopwatch { /// # See Also /// /// [`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. + /// [`elapsed_secs_f64`](Stopwatch::elapsed_secs_f64) - if a `f64` is desirable instead. #[inline] pub fn elapsed_secs(&self) -> f32 { self.elapsed().as_secs_f32() } + /// Returns the elapsed time since the last [`reset`](Stopwatch::reset) + /// of the stopwatch, in seconds, as f64. + /// + /// # See Also + /// + /// [`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. + /// [`elapsed_secs`](Stopwatch::elapsed_secs) - if a `f32` is desirable instead. + #[inline] + pub fn elapsed_secs_f64(&self) -> f64 { + self.elapsed().as_secs_f64() + } + /// Sets the elapsed time of the stopwatch. /// /// # Examples