Skip to content

Commit

Permalink
Fix instant usage on web
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Jun 16, 2023
1 parent b7c73f6 commit 850697b
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 5 deletions.
147 changes: 147 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ crate-type = ["cdylib", "rlib"]
bytemuck = { version = "*", features = ["derive"] }
env_logger = "*"
log = "*"
instant = { version = "*", features = ["stdweb"] }
pollster = "*"
rand = "*"
rand_chacha = "*"
Expand Down
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod event_loop;

use std::time::Instant;

use rand::prelude::*;
use rand_chacha::ChaCha20Rng;

Expand Down Expand Up @@ -124,7 +122,7 @@ pub async fn run() -> ! {

pub struct State<'a> {
elapsed_time: f32,
last_time: Instant,
last_time: instant::Instant,
device: wgpu::Device,
queue: wgpu::Queue,
texture_view_descriptor: wgpu::TextureViewDescriptor<'a>,
Expand Down Expand Up @@ -680,7 +678,7 @@ impl<'a> State<'a> {
surface_format,
);

let last_time = Instant::now();
let last_time = instant::Instant::now();
let elapsed_time = 0.;

Ok(Self {
Expand Down Expand Up @@ -780,7 +778,7 @@ impl<'a> State<'a> {
const SIM_DT: f32 = 1.0 / 4.0;
self.elapsed_time += self.last_time.elapsed().as_secs_f32();
let advance_state = self.elapsed_time > SIM_DT;
self.last_time = Instant::now();
self.last_time = instant::Instant::now();

if advance_state {
self.elapsed_time = 0.;
Expand Down

0 comments on commit 850697b

Please sign in to comment.