Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
boralg committed Jun 26, 2024
1 parent d326160 commit 3dbd4e8
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions sursface/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
#![allow(dead_code, unused_imports)]

use wasm_bindgen::prelude::*;
use wasm_timer::{Instant};
use web_sys::window;
use std::convert::TryInto;
use std::ops::{Add, Sub, AddAssign, SubAssign};
use lazy_static::lazy_static;

#[cfg(not(target_arch = "wasm32"))]
lazy_static! {
static ref START_TIME: Instant = Instant::now();
static ref START_TIME: web_time::Instant = web_time::Instant::now();
}

pub fn now_secs() -> f32 {
#[cfg(not(target_arch = "wasm32"))]
{
Instant::now().duration_since(*START_TIME).as_secs_f64() as f32
}
#[cfg(target_arch = "wasm32")]
{
let window = window().expect("should have a window in this context");
let performance = window.performance().unwrap();

let elapsed = performance.now();
(elapsed / 1000.0) as f32 // Convert milliseconds to seconds
}
web_time::Instant::now().duration_since(*START_TIME).as_secs_f64() as f32
}

0 comments on commit 3dbd4e8

Please sign in to comment.