Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
boralg committed Jun 26, 2024
1 parent 9647390 commit c446437
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions sursface/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,34 @@ mod platform_time {
fn now() -> f64;
}

pub fn now() -> f64 {
pub fn current_time() -> f64 {
now() / 1000.0 // Convert milliseconds to seconds
}
}

#[cfg(not(target_arch = "wasm32"))]
mod platform_time {
use lazy_static::lazy_static;
use std::time::Instant;
use lazy_static::lazy_static;

lazy_static! {
static ref TIME_AT_START: Instant = Instant::now();
}

pub fn now() -> f64 {
pub fn current_time() -> f64 {
TIME_AT_START.elapsed().as_secs_f64()
}
}

lazy_static! {
static ref TIME_AT_START: f64 = platform_time::now();
static ref TIME_AT_START: f64 = platform_time::current_time();
}

pub fn now() -> f32 {
(platform_time::now() - *TIME_AT_START) as f32
(platform_time::current_time() - *TIME_AT_START) as f32
}

fn main() {
// Example usage
println!("Current time: {} seconds since start", now());
}

0 comments on commit c446437

Please sign in to comment.