Struct Time

Source
pub struct Time;
Expand description

This class contains time information for the current session and frame! https://stereokit.net/Pages/StereoKit/Time.html

§Examples

use stereokit_rust::util::Time;

// These are the expected results for tests on a PC:
assert_eq!(Time::get_totalf(), 0.0);
assert_eq!(Time::get_total(), 0.0);
assert_eq!(Time::get_stepf(), 0.0);
assert_eq!(Time::get_step(), 0.0);

// Time passes slowly:
Time::scale(0.5);

let mut total = 0.0f64;
let mut totalf = 0.0f32;
number_of_steps = 100;
test_steps!( // !!!! Get a proper main loop !!!!
   if iter < number_of_steps + 2 {
       assert_eq!(Time::get_frame(), iter + 1);

       assert_eq!(Time::get_step_unscaled(), Time::get_step() * 2.0);

       assert_eq!(Time::get_total(),          total + Time::get_step());
       assert_eq!(Time::get_total_unscaled(), total * 2.0 + Time::get_step() * 2.0);

       // precision is worse for f32
       assert!((Time::get_totalf()          
                - totalf - Time::get_stepf()).abs() < 0.000001);
       assert!((Time::get_total_unscaledf()
                - totalf * 2.0 - Time::get_stepf() * 2.0).abs() < 0.000001);
   }
   totalf = Time::get_totalf();
   total = Time::get_total();
);

Implementations§

Source§

impl Time

Source

pub fn scale(factor: f64)

Time is scaled by this value! Want time to pass slower? Set it to 0.5! Faster? Try 2! https://stereokit.net/Pages/StereoKit/Time/Scale.html

see also time_scale

§Examples
use stereokit_rust::util::Time;

// Time passes faster:
Time::scale(2.0);

let mut total = 0.0f64;
let mut totalf = 0.0f32;
number_of_steps = 100;
test_steps!( // !!!! Get a proper main loop !!!!
    assert_eq!(Time::get_step_unscaled(), Time::get_step() / 2.0);
);
Source

pub fn set_time(total_seconds: f64, frame_elapsed_seconds: f64)

This allows you to override the application time! The application will progress from this time using the current timescale. https://stereokit.net/Pages/StereoKit/Time/SetTime.html

  • total_seconds - What time should it now be? The app will progress from this point in time.
  • frame_elapsed_seconds - How long was the previous frame? This is a number often used in motion calculations. If left to zero, it’ll use the previous frame’s time, and if the previous frame’s time was also zero, it’ll use 1/90.

see also time_set_time

§Examples
use stereokit_rust::util::Time;

// Time passes faster:
Time::set_time(10.0, 0.01);

assert_eq!(Time::get_total(), 10.0);
assert_eq!(Time::get_step(), 0.01);
Source

pub fn get_frame() -> u64

The number of frames/steps since the app started. https://stereokit.net/Pages/StereoKit/Time/Frame.html

see also time_frame

§Examples
use stereokit_rust::util::Time;

assert_eq!(Time::get_frame(), 0);

test_steps!( // !!!! Get a proper main loop !!!!
    if iter < number_of_steps + 2 {
        assert_eq!(Time::get_frame(), iter + 1);
    }
);
Source

pub fn get_step() -> f64

How many seconds have elapsed since the last frame? 64 bit time precision, calculated at the start of the frame. https://stereokit.net/Pages/StereoKit/Time/Step.html

see also time_step

§Examples
use stereokit_rust::util::Time;

assert_eq!(Time::get_step(), 0.0);

let mut total = 0.0f64;
number_of_steps = 1000;
test_steps!( // !!!! Get a proper main loop !!!!
    if iter < number_of_steps + 2 {
        assert_eq!(Time::get_total(), total + Time::get_step());
    }
    total = Time::get_total();
);
Source

pub fn get_stepf() -> f32

How many seconds have elapsed since the last frame? 32 bit time precision, calculated at the start of the frame. https://stereokit.net/Pages/StereoKit/Time/Stepf.html

see also time_stepf

§Examples
use stereokit_rust::util::Time;

assert_eq!(Time::get_stepf(), 0.0);

let mut totalf = 0.0f32;
number_of_steps = 1000;
test_steps!( // !!!! Get a proper main loop !!!!
    if iter < number_of_steps + 2 {
        assert!((Time::get_totalf() - totalf - Time::get_stepf()).abs() < 0.000001);
    }
    totalf = Time::get_totalf();
);
Source

pub fn get_step_unscaled() -> f64

How many seconds have elapsed since the last frame? 64 bit time precision, calculated at the start of the frame. This version is unaffected by the Time::scale value! https://stereokit.net/Pages/StereoKit/Time/StepUnscaled.html

see also time_step_unscaled

§Examples
use stereokit_rust::util::Time;

assert_eq!(Time::get_step_unscaled(), 0.0);

let mut total = 0.0f64;
number_of_steps = 1000;
test_steps!( // !!!! Get a proper main loop !!!!
    if iter < number_of_steps + 2 {
        assert_eq!(Time::get_total_unscaled(), total + Time::get_step_unscaled());
    }
    total = Time::get_total_unscaled();
);
Source

pub fn get_step_unscaledf() -> f32

How many seconds have elapsed since the last frame? 32 bit time precision, calculated at the start of the frame. This version is unaffected by the Time.Scale value! https://stereokit.net/Pages/StereoKit/Time/StepUnscaledf.html

see also time_stepf_unscaled

§Examples
use stereokit_rust::util::Time;

assert_eq!(Time::get_step_unscaledf(), 0.0);

let mut totalf = 0.0f32;
number_of_steps = 1000;
test_steps!( // !!!! Get a proper main loop !!!!
    if iter < number_of_steps + 2 {
        assert!((Time::get_total_unscaledf() - totalf - Time::get_step_unscaledf().abs() < 0.000001));
    }
    totalf = Time::get_total_unscaledf();
);
Source

pub fn get_total() -> f64

How many seconds have elapsed since StereoKit was initialized? 64 bit time precision, calculated at the start of the frame. https://stereokit.net/Pages/StereoKit/Time/Total.html

see also time_total

§Examples
use stereokit_rust::util::Time;

// Time passes faster:
Time::scale(2.0);

assert_eq!(Time::get_total(), 0.0);

number_of_steps = 1000;
test_steps!( // !!!! Get a proper main loop !!!!
    if iter < number_of_steps + 2 {
        assert_eq!(Time::get_total(), Time::get_total_unscaled() * 2.0);
    }
);
Source

pub fn get_totalf() -> f32

How many seconds have elapsed since StereoKit was initialized? 32 bit time precision, calculated at the start of the frame. https://stereokit.net/Pages/StereoKit/Time/Totalf.html

see also time_totalf

§Examples
use stereokit_rust::util::Time;

// Time passes faster:
Time::scale(0.25);

assert_eq!(Time::get_totalf(), 0.0);

number_of_steps = 1000;
test_steps!( // !!!! Get a proper main loop !!!!
    if iter < number_of_steps + 2 {
        assert_eq!(Time::get_totalf(), Time::get_total_unscaledf() / 4.0);
    }
);
Source

pub fn get_total_unscaled() -> f64

How many seconds have elapsed since StereoKit was initialized? 64 bit time precision, calculated at the start of the frame. This version is unaffected by the Time::scale value! https://stereokit.net/Pages/StereoKit/Time/TotalUnscaled.html

see also time_total_unscaled see example in Time::get_total

Source

pub fn get_total_unscaledf() -> f32

How many seconds have elapsed since StereoKit was initialized? 32 bit time precision, calculated at the start of the frame. This version is unaffected by the Time::scale value! https://stereokit.net/Pages/StereoKit/Time/TotalUnscaledf.html

see also time_totalf_unscaled see example in Time::get_total_unscaled

Auto Trait Implementations§

§

impl Freeze for Time

§

impl RefUnwindSafe for Time

§

impl Send for Time

§

impl Sync for Time

§

impl Unpin for Time

§

impl UnwindSafe for Time

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

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

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

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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