[−][src]Struct ftvf::Metronome
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.
Methods
impl<N: NowSource> Metronome<N>
[src]
pub fn new(
now_source: N,
ticks_per_second: (u32, u32),
max_ticks_behind: u32
) -> Metronome<N>
[src]
now_source: N,
ticks_per_second: (u32, u32),
max_ticks_behind: u32
) -> Metronome<N>
Create a new Metronome
, initialized with the given properties.
now_source
: TheNowSource
to use.ticks_per_second
: The target rate of ticks per second, represented as a fraction. For example,(20, 1)
→ 20 ticks per 1 second.(60000, 1001)
→ 60000 ticks per 1001 seconds (color NTSC framerate). Even very large values are acceptable; the only problem you would have from(u32::MAX, 1)
would be actually processingTick
s that quickly, and the only problem you would have from(1, u32::MAX)
would be dying of old age waiting for your firstTick
.max_ticks_behind
: The maximum number of ticks we can "fall behind" before we start dropping ticks. 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 would be preferred.
pub fn sample(&mut self)
[src]
Take a temporal sample. This should be called before each batch of
status
calls.
pub fn status(&mut self, mode: Mode) -> Option<Status>
[src]
Call in a loop after calling sample
. Returns the actions that you
should take to advance your game world, possibly interspersed with
status information about unusual temporal conditions.
pub fn amount_to_sleep_until_next_tick(&mut self) -> Option<Duration>
[src]
Return the exact amount that you should sleep, starting at the last
temporal sample, to arrive at the moment of the next tick. You should
usually call sleep_until_next_tick
instead unless you're testing
ftvf
. See that method for other information.
pub fn sleep_until_next_tick(&mut self)
[src]
Assuming that the current time is fairly close to the most recent
temporal sample, sleep until the moment of the next tick. Good for
saving CPU time on mobile devices / dedicated servers. You should only
call this in response to an Idle
return from sample
.
pub fn set_paused(&mut self, paused: bool)
[src]
Pauses (or unpauses) time. When time is paused, time is being eaten; no
Tick
s occur, but Frame
s may still occur as normal. When resumed,
Tick
s will start again, as though no time had passed.
pub fn set_tickrate(&mut self, ticks_per_second: (u32, u32))
[src]
Dynamically change the tickrate. This can be called during the handling
of a Tick
, and should not be called at other times, lest temporal
anomalies occur.
Trait Implementations
impl<N: Clone + NowSource> Clone for Metronome<N>
[src]
impl<N: Copy + NowSource> Copy for Metronome<N>
[src]
impl<N: Debug + NowSource> Debug for Metronome<N>
[src]
Auto Trait Implementations
impl<N> Send for Metronome<N> where
N: Send,
N: Send,
impl<N> Unpin for Metronome<N> where
N: Unpin,
N: Unpin,
impl<N> Sync for Metronome<N> where
N: Sync,
N: Sync,
impl<N> UnwindSafe for Metronome<N> where
N: UnwindSafe,
N: UnwindSafe,
impl<N> RefUnwindSafe for Metronome<N> where
N: RefUnwindSafe,
N: RefUnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,