Skip to main content

Clock

Struct Clock 

Source
pub struct Clock {
    target_dt: Duration,
    real_time: Duration,
    game_time: Duration,
    last_tick: Instant,
    last_work: Instant,
    tick: u64,
    average_dt: f64,
    average_busy: f64,
    average_variance: f64,
    last_real_dt: f64,
    last_game_dt: f64,
}
Expand description

A type for maintaining consistent tick/frame pacing.

Fields§

§target_dt: Duration

This is the dt that the Clock tries to archive with each call of tick.

§real_time: Duration

The amount of real time that has passed on the clock

§game_time: Duration

The amount of game time that has passed on the clock

§last_tick: Instant

The last time the clock was ticked

§last_work: Instant

The last time we started performing work

§tick: u64

The number of ticks that have elapsed so far

§average_dt: f64

The average time between ticks, seconds

§average_busy: f64

The average amount of time within each tick in which we’re busy (i.e: not sleeping)

§average_variance: f64

The average amount of variance between ticks

§last_real_dt: f64

The time that passed between the last tick, and the tick before it

§last_game_dt: f64

The dt to be used for the next game tick, in game time.

Implementations§

Source§

impl Clock

Source

pub fn new(target_dt: Duration) -> Self

Source

pub fn set_target_dt(&mut self, target_dt: Duration)

Source

pub fn stats(&self) -> ClockStats

Source

pub fn real_dt(&self) -> Duration

Source

pub fn game_dt(&self) -> Duration

Source

pub fn tick(&mut self)

Auto Trait Implementations§

§

impl Freeze for Clock

§

impl RefUnwindSafe for Clock

§

impl Send for Clock

§

impl Sync for Clock

§

impl Unpin for Clock

§

impl UnsafeUnpin for Clock

§

impl UnwindSafe for Clock

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> Resource for T
where T: Any + Send + Sync,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Storable for T
where T: Send + Sync + 'static,

Source§

impl<Context> SubContext<Context> for Context

Source§

fn sub_context(self) -> Context

Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more