pub struct FrameClock { /* private fields */ }Expand description
Algorithm for deciding how to execute simulation and rendering frames. Platform-independent; does not consult any clocks, only makes decisions given the provided information.
Implementations§
Source§impl FrameClock
impl FrameClock
Sourcepub fn new(schedule: TickSchedule) -> Self
pub fn new(schedule: TickSchedule) -> Self
Constructs a new FrameClock.
This operation is independent of the system clock.
Source§impl FrameClock
impl FrameClock
Sourcepub fn advance_to(&mut self, instant: Instant)
pub fn advance_to(&mut self, instant: Instant)
Advance the clock using a source of absolute time.
This cannot be meaningfully used in combination with
FrameClock::request_frame() or FrameClock::advance_by().
Sourcepub fn advance_by(&mut self, duration: Duration)
pub fn advance_by(&mut self, duration: Duration)
Advance the clock using a source of relative time.
Sourcepub fn request_frame(&mut self, time_since_last_frame: Duration) -> bool
pub fn request_frame(&mut self, time_since_last_frame: Duration) -> bool
Reacts to a callback from the environment requesting drawing a frame ASAP if
we’re going to (i.e. requestAnimationFrame on the web). Drives the simulation
clock based on this input (it will not advance if no requests are made).
Returns whether a frame should actually be rendered now. The caller should also
consult FrameClock::should_step() afterward to schedule game state steps.
This cannot be meaningfully used in combination with FrameClock::advance_to().
Sourcepub fn next_step_or_draw_time(&self) -> Option<Instant>
pub fn next_step_or_draw_time(&self) -> Option<Instant>
Returns the next time at which FrameClock::should_step(), and then
FrameClock::should_draw(), should be consulted.
FrameClock::advance_to() must have previously been called to give an absolute
time reference.
Sourcepub fn should_draw(&self) -> bool
pub fn should_draw(&self) -> bool
Indicates whether a new frame should be drawn, given the amount of time that this
FrameClock has been informed has passed.
When a frame is drawn, FrameClock::did_draw] must be called; otherwise, this
will always return true.
Sourcepub fn did_draw(&mut self)
pub fn did_draw(&mut self)
Informs the FrameClock that a frame was just drawn.
Sourcepub fn should_step(&self) -> bool
pub fn should_step(&self) -> bool
Indicates whether Universe::step() should be performed,
given the amount of time that this FrameClock has been informed has passed.
When a step is performd, FrameClock::did_step must be called; otherwise, this
will always return true.
Sourcepub fn did_step(&mut self, schedule: TickSchedule)
pub fn did_step(&mut self, schedule: TickSchedule)
Informs the FrameClock that a step was just performed.
The caller must also provide an updated schedule, in case it has changed.
Trait Implementations§
Source§impl Clone for FrameClock
impl Clone for FrameClock
Source§fn clone(&self) -> FrameClock
fn clone(&self) -> FrameClock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FrameClock
impl Debug for FrameClock
Source§impl PartialEq for FrameClock
impl PartialEq for FrameClock
impl Eq for FrameClock
impl StructuralPartialEq for FrameClock
Auto Trait Implementations§
impl Freeze for FrameClock
impl RefUnwindSafe for FrameClock
impl Send for FrameClock
impl Sync for FrameClock
impl Unpin for FrameClock
impl UnwindSafe for FrameClock
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more