Skip to content

Commit

Permalink
Formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedible committed Jun 29, 2023
1 parent d57e50b commit 6e9e6cd
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 103 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_gilrs/src/rumble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy_ecs::{
};
use bevy_input::gamepad::{GamepadRumbleIntensity, GamepadRumbleRequest};
use bevy_log::{debug, warn};
use bevy_time::{Time, Real};
use bevy_time::{Real, Time};
use bevy_utils::{Duration, HashMap};
use gilrs::{
ff::{self, BaseEffect, BaseEffectType, Repeat, Replay},
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_time/src/common_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ mod tests {
#[test]
fn distributive_run_if_compiles() {
Schedule::default().add_systems(
(test_system, test_system)
.distributive_run_if(on_timer(Duration::new(1, 0)))
(test_system, test_system).distributive_run_if(on_timer(Duration::new(1, 0))),
);
}
}
43 changes: 23 additions & 20 deletions crates/bevy_time/src/fixed.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
use bevy_utils::Duration;
use bevy_ecs::world::World;
use bevy_reflect::{FromReflect, Reflect};
use bevy_utils::Duration;

use crate::FixedUpdate;
use crate::time::Time;
use crate::virt::Virtual;
use crate::{time::Time, virt::Virtual, FixedUpdate};

/// The fixed timestep game clock following virtual time.
///
/// Normally used as `Time<Fixed>`. It is automatically inserted as a resource
/// by `TimePlugin` and updated based on `Time<Virtual>`. The fixed clock is
/// automatically set as the generic `Time` resource during `FixedUpdate`
/// schedule processing.
///
///
/// The fixed timestep game clock runs at a regular interval and is extremely
/// useful for steady, frame-rate independent gameplay logic and physics.
///
/// useful for steady, frame-rate independent gameplay logic and physics.
///
/// To run a system on a fixed timestep, add it to the `FixedUpdate` schedule.
/// This schedule is run a number of times between `PreUpdate` and `Update`
/// according to the accumulated `overstep()` time divided by the `timestep()`.
/// This means the schedule may run 0, 1 or more times during a single update.
///
///
/// `Time<Fixed>` and the generic `Time` resource will report a `delta()` equal
/// to `timestep()` and always grow `elapsed()` by one `timestep()` per
/// iteration.
///
///
/// The fixed timestep clock follows the `Time<Virtual>` clock, which means it
/// is affected by `paused()`, `relative_speed()` and `max_delta()` from virtual
/// time. If the virtual clock is paused, the `FixedUpdate` schedule will not
/// run. It is guaranteed that the `elapsed()` time in `Time<Fixed>` is always
/// between the previous `elapsed()` and the next `elapsed()` value in
/// `Time<Virtual>`, so the values are compatible.
///
///
/// Changing the timestep size while the game is running should not normally be
/// done, as having a regular interval is the point of this schedule, but it may
/// be necessary for effects like "bullet-time" if the normal granularity of the
Expand Down Expand Up @@ -78,34 +76,41 @@ impl Time<Fixed> {

/// Sets the amount of virtual time that must pass before the fixed timestep
/// schedule is run again, as [`Duration`].
///
///
/// Takes effect immediately on the next run of the schedule, respecting
/// what is currently in `overstep()`.
pub fn set_timestep(&mut self, timestep: Duration) {
assert_ne!(timestep, Duration::ZERO, "attempted to set fixed timestep to zero");
assert_ne!(
timestep,
Duration::ZERO,
"attempted to set fixed timestep to zero"
);
self.context_mut().timestep = timestep;
}

/// Sets the amount of virtual time that must pass before the fixed timestep
/// schedule is run again, as seconds.
///
///
/// Timestep is stored as a `Duration`, which has fixed nanosecond
/// resolution and will be converted from the floating point number.
///
///
/// Takes effect immediately on the next run of the schedule, respecting
/// what is currently in `overstep()`.
pub fn set_timestep_seconds(&mut self, seconds: f64) {
assert!(seconds.is_sign_positive(), "seconds less than or equal to zero");
assert!(
seconds.is_sign_positive(),
"seconds less than or equal to zero"
);
assert!(seconds.is_finite(), "seconds is infinite");
self.set_timestep(Duration::from_secs_f64(seconds));
}

/// Sets the amount of virtual time that must pass before the fixed timestep
/// schedule is run again, as frequency.
///
///
/// The timestep value is set to `1 / hz`, converted to a `Duration` which
/// has fixed nanosecond resolution.
///
///
/// Takes effect immediately on the next run of the schedule, respecting
/// what is currently in `overstep()`.
pub fn set_timestep_hz(&mut self, hz: f64) {
Expand Down Expand Up @@ -159,9 +164,7 @@ impl Default for Fixed {
}
}

pub fn run_fixed_update_schedule(
world: &mut World
) {
pub fn run_fixed_update_schedule(world: &mut World) {
let delta = world.resource::<Time<Virtual>>().delta();
world.resource_mut::<Time<Fixed>>().accumulate(delta);

Expand Down
23 changes: 13 additions & 10 deletions crates/bevy_time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

/// Common run conditions
pub mod common_conditions;
mod fixed;
mod real;
mod stopwatch;
#[allow(clippy::module_inception)]
mod time;
mod timer;
mod real;
mod fixed;
mod virt;

pub use fixed::*;
pub use real::*;
pub use stopwatch::*;
pub use time::*;
pub use timer::*;
pub use real::*;
pub use virt::*;
pub use fixed::*;

use bevy_ecs::system::{Res, ResMut};
use bevy_utils::{tracing::warn, Duration, Instant};
Expand All @@ -24,7 +24,7 @@ use crossbeam_channel::{Receiver, Sender};
pub mod prelude {
//! The Bevy Time Prelude.
#[doc(hidden)]
pub use crate::{Time, Timer, TimerMode, Real, Virtual, Fixed};
pub use crate::{Fixed, Real, Time, Timer, TimerMode, Virtual};
}

use bevy_app::{prelude::*, RunFixedUpdateLoop};
Expand Down Expand Up @@ -52,7 +52,10 @@ impl Plugin for TimePlugin {
.register_type::<Time<Fixed>>()
.register_type::<Timer>()
.register_type::<Stopwatch>()
.add_systems(First, (time_system, virtual_time_system.after(time_system)).in_set(TimeSystem))
.add_systems(
First,
(time_system, virtual_time_system.after(time_system)).in_set(TimeSystem),
)
.add_systems(RunFixedUpdateLoop, run_fixed_update_schedule);

#[cfg(feature = "bevy_ci_testing")]
Expand All @@ -72,8 +75,8 @@ impl Plugin for TimePlugin {

/// Configuration resource used to determine how the time system should run.
///
/// For most cases, [`TimeUpdateStrategy::Automatic`] is fine. When writing tests, dealing with networking, or similar
/// you may prefer to set the next [`Time`] value manually.
/// For most cases, [`TimeUpdateStrategy::Automatic`] is fine. When writing tests, dealing with
/// networking, or similar you may prefer to set the next [`Time`] value manually.
#[derive(Resource, Default)]
pub enum TimeUpdateStrategy {
#[default]
Expand All @@ -100,8 +103,8 @@ pub fn create_time_channels() -> (TimeSender, TimeReceiver) {
(TimeSender(s), TimeReceiver(r))
}

/// The system used to update the [`Time`] used by app logic. If there is a render world the time is sent from
/// there to this system through channels. Otherwise the time is updated in this system.
/// The system used to update the [`Time`] used by app logic. If there is a render world the time is
/// sent from there to this system through channels. Otherwise the time is updated in this system.
fn time_system(
mut time: ResMut<Time<Real>>,
update_strategy: Res<TimeUpdateStrategy>,
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_time/src/real.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use bevy_utils::{Duration, Instant};
use bevy_reflect::{FromReflect, Reflect};
use bevy_utils::{Duration, Instant};

use crate::time::Time;

/// Real time clock representing elapsed wall clock time.
///
///
/// Normally used as `Time<Real>`. It is automatically inserted as a resource by
/// `TimePlugin` and updated with time instants based on `TimeUpdateStrategy`.
///
///
/// The `delta()` and `elapsed()` values of this clock should be used for
/// anything which deals specifically with real time (wall clock time). It will
/// not be affected by relative game speed adjustments, pausing or other
/// adjustments.
///
///
/// The clock does not count time from `startup()` to `first_update()` into
/// elapsed, but instead will start counting time from the first update call.
/// `delta()` and `elapsed()` will report zero on the first update as there is
/// no previous update instant. This means that a `delta()` of zero must be
/// handled without errors in application logic, as it may theoretically also
/// happen at other times.
///
///
/// `Instant`s for `startup()`, `first_update()` and `last_update()` are
/// recorded and accessible.
#[derive(Debug, Copy, Clone, Reflect, FromReflect)]
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Time<Real> {
/// Updates time with a specified [`Duration`].
///
/// This method is provided for use in tests.
///
///
/// Calling this method as part of your app will most likely result in inaccurate timekeeping,
/// as the `Time` resource is ordinarily managed by the [`TimePlugin`](crate::TimePlugin).
pub fn update_with_duration(&mut self, duration: Duration) {
Expand All @@ -71,7 +71,7 @@ impl Time<Real> {
/// Updates time with a specified [`Instant`].
///
/// This method is provided for use in tests.
///
///
/// Calling this method as part of your app will most likely result in inaccurate timekeeping,
/// as the `Time` resource is ordinarily managed by the [`TimePlugin`](crate::TimePlugin).
pub fn update_with_instant(&mut self, instant: Instant) {
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_time/src/stopwatch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bevy_reflect::prelude::*;
use bevy_reflect::Reflect;
use bevy_reflect::{prelude::*, Reflect};
use bevy_utils::Duration;

/// A Stopwatch is a struct that track elapsed time when started.
Expand Down
Loading

0 comments on commit 6e9e6cd

Please sign in to comment.