Struct ftvf::Metronome

source ·
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>

source

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: The NowSource to use.
  • tickrate: The target rate of ticks per second, represented as a Rate.
  • 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.
source

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 Readings, describing how you should respond to the passage of time. See Reading for info on what each reading means.

source

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§

source§

impl<N: Clone + NowSource> Clone for Metronome<N>where N::Instant: Clone,

source§

fn clone(&self) -> Metronome<N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<N: Debug + NowSource> Debug for Metronome<N>where N::Instant: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.