Skip to content

Commit c84dde8

Browse files
committed
Add a few constructors
1 parent 002279c commit c84dde8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

crates/bevy_time/src/fixed.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ pub struct Fixed {
4949
}
5050

5151
impl Time<Fixed> {
52+
/// Return new fixed time clock with given timestep as `Duration`
53+
pub fn from_duration(timestep: Duration) -> Self {
54+
let mut ret = Self::default();
55+
ret.set_timestep(timestep);
56+
ret
57+
}
58+
59+
/// Return new fixed time clock with given timestep seconds as `f64`
60+
pub fn from_seconds(seconds: f64) -> Self {
61+
let mut ret = Self::default();
62+
ret.set_timestep_seconds(seconds);
63+
ret
64+
}
65+
66+
/// Return new fixed time clock with given timestep frequency as `f64`
67+
pub fn from_hz(hz: f64) -> Self {
68+
let mut ret = Self::default();
69+
ret.set_timestep_hz(hz);
70+
ret
71+
}
72+
5273
/// Returns the amount of virtual time that must pass before the fixed
5374
/// timestep schedule is run again.
5475
pub fn timestep(&self) -> Duration {

crates/bevy_time/src/virt.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ pub struct Virtual {
6969
impl Time<Virtual> {
7070
const DEFAULT_MAX_DELTA: Duration = Duration::from_millis(333); // XXX: better value
7171

72+
/// Create new virtual clock with given maximum delta step `Duration`
73+
pub fn from_max_delta(max_delta: Duration) -> Self {
74+
let mut ret = Self::default();
75+
ret.set_max_delta(max_delta);
76+
ret
77+
}
78+
7279
/// Returns the maximum amount of time that can be added to this clock by a
7380
/// single update, as [`std::time::Duration`].
7481
///

0 commit comments

Comments
 (0)