litequad/time.rs
1//! Cross platform system time access and FPS counters.
2
3use crate::get_context;
4
5/// Returns current FPS
6pub fn get_fps() -> i32 {
7 let context = get_context();
8
9 (1. / context.frame_time) as i32
10}
11
12/// Returns duration in seconds of the last frame drawn
13pub fn get_frame_time() -> f32 {
14 let context = get_context();
15
16 if crate::experimental::scene::in_fixed_update() {
17 crate::experimental::scene::fixed_frame_time()
18 } else {
19 context.frame_time as f32
20 }
21}
22
23/// Returns elapsed wall-clock time in seconds since start
24///
25/// Note that as real world time progresses during computation,
26/// the value returned will change. Therefore if you want
27/// your game logic update to happen at the same *in-game* time
28/// for all game objects, you should call this function once
29/// save the value and reuse it throughout your code.
30pub fn get_time() -> f64 {
31 let context = get_context();
32
33 miniquad::date::now() - context.start_time
34}