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
impl Time
Sourcepub fn scale(factor: f64)
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);
);
Sourcepub fn set_time(total_seconds: f64, frame_elapsed_seconds: f64)
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);
Sourcepub fn get_frame() -> u64
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);
}
);
Sourcepub fn get_step() -> f64
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 = 100;
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();
);
Sourcepub fn get_stepf() -> f32
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 = 100;
test_steps!( // !!!! Get a proper main loop !!!!
if iter < number_of_steps + 2 {
assert!((Time::get_totalf() - totalf - Time::get_stepf()).abs() < 0.0001);
}
totalf = Time::get_totalf();
);
Sourcepub fn get_step_unscaled() -> f64
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 = 100;
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();
);
Sourcepub fn get_step_unscaledf() -> f32
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 = 100;
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.0001));
}
totalf = Time::get_total_unscaledf();
);
Sourcepub fn get_total() -> f64
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 = 100;
test_steps!( // !!!! Get a proper main loop !!!!
if iter < number_of_steps + 2 {
assert_eq!(Time::get_total(), Time::get_total_unscaled() * 2.0);
}
);
Sourcepub fn get_totalf() -> f32
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 = 100;
test_steps!( // !!!! Get a proper main loop !!!!
if iter < number_of_steps + 2 {
assert_eq!(Time::get_totalf(), Time::get_total_unscaledf() / 4.0);
}
);
Sourcepub fn get_total_unscaled() -> f64
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
Sourcepub fn get_total_unscaledf() -> f32
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