Skip to content

Commit f99dcad

Browse files
Add missing documentation to bevy_time (#9428)
# Objective * Add documentation to undocumented items in `bevy_time`. * Add a warning for undocumented items. --------- Co-authored-by: Sélène Amanita <[email protected]>
1 parent 6ccb268 commit f99dcad

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

crates/bevy_time/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Bevy Time
2+
3+
The built-in timekeeping plugin for the Bevy game engine.

crates/bevy_time/src/fixed_timestep.rs

+28-8
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,60 @@ use bevy_utils::Duration;
2828
use thiserror::Error;
2929

3030
/// The amount of time that must pass before the fixed timestep schedule is run again.
31+
///
32+
/// For more information, see the [module-level documentation](self).
33+
///
34+
/// When using bevy's default configuration, this will be updated using the [`Time`]
35+
/// resource. To customize how `Time` is updated each frame, see [`TimeUpdateStrategy`].
36+
///
37+
/// [`TimeUpdateStrategy`]: crate::TimeUpdateStrategy
3138
#[derive(Resource, Debug)]
3239
pub struct FixedTime {
3340
accumulated: Duration,
41+
/// The amount of time spanned by each fixed update.
3442
/// Defaults to 1/60th of a second.
35-
/// To configure this value, simply mutate or overwrite this resource.
43+
///
44+
/// To configure this value, simply mutate or overwrite this field.
3645
pub period: Duration,
3746
}
3847

3948
impl FixedTime {
40-
/// Creates a new [`FixedTime`] struct
49+
/// Creates a new [`FixedTime`] struct with a specified period.
4150
pub fn new(period: Duration) -> Self {
4251
FixedTime {
4352
accumulated: Duration::ZERO,
4453
period,
4554
}
4655
}
4756

48-
/// Creates a new [`FixedTime`] struct with a period specified in `f32` seconds
57+
/// Creates a new [`FixedTime`] struct with a period specified in seconds.
4958
pub fn new_from_secs(period: f32) -> Self {
5059
FixedTime {
5160
accumulated: Duration::ZERO,
5261
period: Duration::from_secs_f32(period),
5362
}
5463
}
5564

56-
/// Adds the `delta_time` to the accumulated time so far.
65+
/// Adds to this instance's accumulated time. `delta_time` should be the amount of in-game time
66+
/// that has passed since `tick` was last called.
67+
///
68+
/// Note that if you are using the default configuration of bevy, this will be called for you.
5769
pub fn tick(&mut self, delta_time: Duration) {
5870
self.accumulated += delta_time;
5971
}
6072

61-
/// Returns the current amount of accumulated time
73+
/// Returns the current amount of accumulated time.
74+
///
75+
/// Approximately, this represents how far behind the fixed update schedule is from the main schedule.
6276
pub fn accumulated(&self) -> Duration {
6377
self.accumulated
6478
}
6579

66-
/// Expends one `period` of accumulated time.
80+
/// Attempts to advance by a single period. This will return [`FixedUpdateError`] if there is not enough
81+
/// accumulated time -- in other words, if advancing time would put the fixed update schedule
82+
/// ahead of the main schedule.
6783
///
68-
/// [`Err(FixedUpdateError`)] will be returned if there is
69-
/// not enough accumulated time to span an entire period.
84+
/// Note that if you are using the default configuration of bevy, this will be called for you.
7085
pub fn expend(&mut self) -> Result<(), FixedUpdateError> {
7186
if let Some(new_value) = self.accumulated.checked_sub(self.period) {
7287
self.accumulated = new_value;
@@ -92,14 +107,19 @@ impl Default for FixedTime {
92107
/// An error returned when working with [`FixedTime`].
93108
#[derive(Debug, Error)]
94109
pub enum FixedUpdateError {
110+
/// There is not enough accumulated time to advance the fixed update schedule.
95111
#[error("At least one period worth of time must be accumulated.")]
96112
NotEnoughTime {
113+
/// The amount of time available to advance the fixed update schedule.
97114
accumulated: Duration,
115+
/// The length of one fixed update.
98116
period: Duration,
99117
},
100118
}
101119

102120
/// Ticks the [`FixedTime`] resource then runs the [`FixedUpdate`].
121+
///
122+
/// For more information, see the [module-level documentation](self).
103123
pub fn run_fixed_update_schedule(world: &mut World) {
104124
// Tick the time
105125
let delta_time = world.resource::<Time>().delta();

crates/bevy_time/src/lib.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![allow(clippy::type_complexity)]
2+
#![warn(missing_docs)]
3+
#![doc = include_str!("../README.md")]
24

35
/// Common run conditions
46
pub mod common_conditions;
@@ -69,23 +71,28 @@ impl Plugin for TimePlugin {
6971
/// you may prefer to set the next [`Time`] value manually.
7072
#[derive(Resource, Default)]
7173
pub enum TimeUpdateStrategy {
74+
/// [`Time`] will be automatically updated each frame using an [`Instant`] sent from the render world via a [`TimeSender`].
75+
/// If nothing is sent, the system clock will be used instead.
7276
#[default]
7377
Automatic,
74-
// Update [`Time`] with an exact `Instant` value
78+
/// [`Time`] will be updated to the specified [`Instant`] value each frame.
79+
/// In order for time to progress, this value must be manually updated each frame.
80+
///
81+
/// Note that the `Time` resource will not be updated until [`TimeSystem`] runs.
7582
ManualInstant(Instant),
76-
// Update [`Time`] with the last update time + a specified `Duration`
83+
/// [`Time`] will be incremented by the specified [`Duration`] each frame.
7784
ManualDuration(Duration),
7885
}
7986

80-
/// Channel resource used to receive time from render world
87+
/// Channel resource used to receive time from the render world.
8188
#[derive(Resource)]
8289
pub struct TimeReceiver(pub Receiver<Instant>);
8390

84-
/// Channel resource used to send time from render world
91+
/// Channel resource used to send time from the render world.
8592
#[derive(Resource)]
8693
pub struct TimeSender(pub Sender<Instant>);
8794

88-
/// Creates channels used for sending time between render world and app world
95+
/// Creates channels used for sending time between the render world and the main world.
8996
pub fn create_time_channels() -> (TimeSender, TimeReceiver) {
9097
// bound the channel to 2 since when pipelined the render phase can finish before
9198
// the time system runs.

crates/bevy_time/src/time.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use bevy_utils::{Duration, Instant};
44

55
/// A clock that tracks how much it has advanced (and how much real time has elapsed) since
66
/// its previous update and since its creation.
7+
///
8+
/// See [`TimeUpdateStrategy`], which allows you to customize the way that this is updated each frame.
9+
///
10+
/// [`TimeUpdateStrategy`]: crate::TimeUpdateStrategy
711
#[derive(Resource, Reflect, Debug, Clone)]
812
#[reflect(Resource, Default)]
913
pub struct Time {

0 commit comments

Comments
 (0)