Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace instant by web-time #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/salva2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ num-traits = "0.2"
fnv = "1.0"
itertools = "0.13"
generational-arena = "0.2"
instant = { version = "0.1", features = [ "now" ] }
web-time = { version = "1.1" }
rayon = { version = "1.8", optional = true }

nalgebra = "0.33"
Expand Down
2 changes: 1 addition & 1 deletion build/salva3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ num-traits = "0.2"
fnv = "1.0"
itertools = "0.13"
generational-arena = "0.2"
instant = { version = "0.1", features = [ "now" ] }
web-time = { version = "1.1" }
rayon = { version = "1.8", optional = true }

nalgebra = "0.33"
Expand Down
7 changes: 4 additions & 3 deletions src/counters/timer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::{Display, Error, Formatter};
use web_time::Instant;

/// A timer.
#[derive(Copy, Clone, Debug, Default)]
Expand Down Expand Up @@ -37,15 +38,15 @@ impl Timer {
pub fn start(&mut self) {
if self.enabled {
self.time = 0.0;
self.start = Some(instant::now());
self.start = Some(Instant::now().elapsed().as_secs_f64());
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// Pause the timer.
pub fn pause(&mut self) {
if self.enabled {
if let Some(start) = self.start {
self.time += instant::now() - start;
self.time += Instant::now().elapsed().as_secs_f64() - start;
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
}
self.start = None;
}
Expand All @@ -54,7 +55,7 @@ impl Timer {
/// Resume the timer.
pub fn resume(&mut self) {
if self.enabled {
self.start = Some(instant::now());
self.start = Some(Instant::now().elapsed().as_secs_f64());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there's a less verbose way to get that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.start = Some(Instant::now().elapsed().as_secs_f64());
self.start = Some(Instant::now());

}
}

Expand Down
5 changes: 3 additions & 2 deletions src/integrations/rapier/harness_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::FluidsPipeline;
use rapier_testbed::harness::RunState;
use rapier_testbed::physics::PhysicsEvents;
use rapier_testbed::{HarnessPlugin, PhysicsState};
use web_time::Instant;

/// A user-defined callback executed at each frame.
pub type FluidCallback =
Expand Down Expand Up @@ -57,7 +58,7 @@ impl HarnessPlugin for FluidsHarnessPlugin {
}

fn step(&mut self, physics: &mut PhysicsState, _run_state: &RunState) {
let step_time = instant::now();
let step_time = Instant::now().elapsed().as_secs_f64();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let step_time = Instant::now().elapsed().as_secs_f64();
let step_time = Instant::now();

let dt = physics.integration_parameters.dt;
self.fluids_pipeline.step(
&physics.gravity,
Expand All @@ -66,7 +67,7 @@ impl HarnessPlugin for FluidsHarnessPlugin {
&mut physics.bodies,
);

self.step_time = instant::now() - step_time;
self.step_time = Instant::now().elapsed().as_secs_f64() - step_time;
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
}

fn profiling_string(&self) -> String {
Expand Down
5 changes: 3 additions & 2 deletions src/integrations/rapier/testbed_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rapier_testbed::{

use crate::integrations::rapier::FluidsPipeline;
use std::collections::HashMap;
use web_time::Instant;

//FIXME: handle this with macros, or use bevy-inspectable-egui
pub const FLUIDS_RENDERING_MAP: [(&str, FluidsRenderingMode); 3] = [
Expand Down Expand Up @@ -330,7 +331,7 @@ impl TestbedPlugin for FluidsTestbedPlugin {
}

fn step(&mut self, physics: &mut PhysicsState) {
let step_time = instant::now();
let step_time = Instant::now().elapsed().as_secs_f64();
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
let dt = physics.integration_parameters.dt;
self.fluids_pipeline.step(
&physics.gravity,
Expand All @@ -339,7 +340,7 @@ impl TestbedPlugin for FluidsTestbedPlugin {
&mut physics.bodies,
);

self.step_time = instant::now() - step_time;
self.step_time = Instant::now().elapsed().as_secs_f64() - step_time;
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
}

fn draw(
Expand Down
Loading