ready_paint/
time.rs

1#[cfg(not(target_arch = "wasm32"))]
2pub type TimeStamp = std::time::Instant;
3
4#[cfg(target_arch = "wasm32")]
5pub type TimeStamp = f32; // 用秒或毫秒表示,如果你习惯用秒就转换成秒
6
7/// 获取当前时间戳
8#[cfg(not(target_arch = "wasm32"))]
9pub fn now() -> TimeStamp {
10    std::time::Instant::now()
11}
12
13#[cfg(target_arch = "wasm32")]
14pub fn now() -> TimeStamp {
15    (web_sys::window()
16        .expect("should have a Window")
17        .performance()
18        .expect("should have a Performance")
19        .now()
20        / 1000.) as f32
21}