Skip to content

Commit

Permalink
Stopwatch elapsed secs f64 (bevyengine#5978)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
EMachad0 authored and james7132 committed Oct 28, 2022
1 parent 60dc0a4 commit ce9cf20
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/bevy_time/src/stopwatch.rs
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ce9cf20

Please sign in to comment.