pub struct Metronome<N: NowSource> { /* private fields */ }
Expand description
The meat of the crate. Contains all state necessary to turn pure temporal chaos into an orderly stream of ticks and frames.
See the crate-level documentation for more information.
Implementations§
source§impl<N: NowSource> Metronome<N>
impl<N: NowSource> Metronome<N>
sourcepub fn new(now_source: N, tickrate: Rate, max_ticks_behind: u32) -> Metronome<N>
pub fn new(now_source: N, tickrate: Rate, max_ticks_behind: u32) -> Metronome<N>
Create a new Metronome
, initialized with the given properties.
now_source
: TheNowSource
to use.tickrate
: The target rate of ticks per second, represented as aRate
.max_ticks_behind
: The maximum number of ticks we can “fall behind” before we start dropping ticks. Increasing this value makes your game’s tick pacing more steady over time, at the cost of making the play experience more miserable on computers too slow to play the game in realtime.
For a non-multiplayer application this should be fairly low, e.g. in the 1-3 range. In multiplayer, we should try harder to keep up, and a value on the order of several seconds’ worth of ticks might be preferred.
sourcepub fn sample<'a>(
&'a mut self,
mode: Mode
) -> impl Iterator<Item = Reading> + 'a
pub fn sample<'a>( &'a mut self, mode: Mode ) -> impl Iterator<Item = Reading> + 'a
Call this from your logic loop, after checking for user input. Returns
an Iterator
of Reading
s, describing how you should respond to the
passage of time. See Reading
for info on what
each reading means.
sourcepub fn set_tickrate(&mut self, new_rate: Rate)
pub fn set_tickrate(&mut self, new_rate: Rate)
Dynamically change the tickrate. You can call this at any time and it
will take effect after the current tick. If you call this from within
a loop over an iterator returned by sample
, you should break
out of
the loop, because it does not currently detect the new tick rate
mid-loop.
Trait Implementations§
Auto Trait Implementations§
impl<N> RefUnwindSafe for Metronome<N>where N: RefUnwindSafe, <N as NowSource>::Instant: RefUnwindSafe,
impl<N> Send for Metronome<N>where N: Send, <N as NowSource>::Instant: Send,
impl<N> Sync for Metronome<N>where N: Sync, <N as NowSource>::Instant: Sync,
impl<N> Unpin for Metronome<N>where N: Unpin, <N as NowSource>::Instant: Unpin,
impl<N> UnwindSafe for Metronome<N>where N: UnwindSafe, <N as NowSource>::Instant: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more