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

aligning public apis of Time,Timer and Stopwatch #15962

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ pub fn advance_animations(
animation_graphs: Res<Assets<AnimationGraph>>,
mut players: Query<(&mut AnimationPlayer, &AnimationGraphHandle)>,
) {
let delta_seconds = time.delta_seconds();
let delta_seconds = time.delta_secs();
players
.par_iter_mut()
.for_each(|(mut player, graph_handle)| {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_animation/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn advance_transitions(
for transition in &mut animation_transitions.transitions.iter_mut().rev() {
// Decrease weight.
transition.current_weight = (transition.current_weight
- transition.weight_decline_per_sec * time.delta_seconds())
- transition.weight_decline_per_sec * time.delta_secs())
.max(0.0);

// Update weight.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl FrameTimeDiagnosticsPlugin {
) {
diagnostics.add_measurement(&Self::FRAME_COUNT, || frame_count.0 as f64);

let delta_seconds = time.delta_seconds_f64();
let delta_seconds = time.delta_secs_f64();
if delta_seconds == 0.0 {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_render/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ fn prepare_globals_buffer(
frame_count: Res<FrameCount>,
) {
let buffer = globals_buffer.buffer.get_mut();
buffer.time = time.elapsed_seconds_wrapped();
buffer.delta_time = time.delta_seconds();
buffer.time = time.elapsed_secs_wrapped();
buffer.delta_time = time.delta_secs();
buffer.frame_count = frame_count.0;

globals_buffer
Expand Down
26 changes: 13 additions & 13 deletions crates/bevy_time/src/stopwatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ use bevy_utils::Duration;
/// assert_eq!(stopwatch.elapsed_secs(), 1.0);
///
/// stopwatch.reset(); // reset the stopwatch
/// assert!(stopwatch.paused());
/// assert!(stopwatch.is_paused());
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
/// ```
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Default))]
pub struct Stopwatch {
elapsed: Duration,
paused: bool,
is_paused: bool,
}

impl Stopwatch {
Expand All @@ -40,7 +40,7 @@ impl Stopwatch {
/// # use bevy_time::*;
/// let stopwatch = Stopwatch::new();
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
/// assert_eq!(stopwatch.paused(), false);
/// assert_eq!(stopwatch.is_paused(), false);
/// ```
pub fn new() -> Self {
Default::default()
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Stopwatch {
/// assert_eq!(stopwatch.elapsed_secs(), 1.5);
/// ```
pub fn tick(&mut self, delta: Duration) -> &Self {
if !self.paused() {
if !self.is_paused() {
self.elapsed = self.elapsed.saturating_add(delta);
}
self
Expand All @@ -144,12 +144,12 @@ impl Stopwatch {
/// let mut stopwatch = Stopwatch::new();
/// stopwatch.pause();
/// stopwatch.tick(Duration::from_secs_f32(1.5));
/// assert!(stopwatch.paused());
/// assert!(stopwatch.is_paused());
/// assert_eq!(stopwatch.elapsed_secs(), 0.0);
/// ```
#[inline]
pub fn pause(&mut self) {
self.paused = true;
self.is_paused = true;
}

/// Unpauses the stopwatch. Resume the effect of ticking on elapsed time.
Expand All @@ -163,12 +163,12 @@ impl Stopwatch {
/// stopwatch.tick(Duration::from_secs_f32(1.0));
/// stopwatch.unpause();
/// stopwatch.tick(Duration::from_secs_f32(1.0));
/// assert!(!stopwatch.paused());
/// assert!(!stopwatch.is_paused());
/// assert_eq!(stopwatch.elapsed_secs(), 1.0);
/// ```
#[inline]
pub fn unpause(&mut self) {
self.paused = false;
self.is_paused = false;
}

/// Returns `true` if the stopwatch is paused.
Expand All @@ -177,15 +177,15 @@ impl Stopwatch {
/// ```
/// # use bevy_time::*;
/// let mut stopwatch = Stopwatch::new();
/// assert!(!stopwatch.paused());
/// assert!(!stopwatch.is_paused());
/// stopwatch.pause();
/// assert!(stopwatch.paused());
/// assert!(stopwatch.is_paused());
/// stopwatch.unpause();
/// assert!(!stopwatch.paused());
/// assert!(!stopwatch.is_paused());
/// ```
#[inline]
pub fn paused(&self) -> bool {
self.paused
pub fn is_paused(&self) -> bool {
self.is_paused
}

/// Resets the stopwatch. The reset doesn't affect the paused state of the stopwatch.
Expand Down
Loading