From b5cfe07d2427a53f33f7cb4ac6d7bf27ab33d671 Mon Sep 17 00:00:00 2001 From: Thierry Berger Date: Thu, 5 Dec 2024 12:34:39 +0100 Subject: [PATCH] remove instant dependency in favor of web-time --- .github/workflows/rapier-ci-build.yml | 4 ++-- CHANGELOG.md | 1 + crates/rapier2d-f64/Cargo.toml | 5 ++--- crates/rapier2d/Cargo.toml | 5 ++--- crates/rapier3d-f64/Cargo.toml | 5 ++--- crates/rapier3d/Cargo.toml | 5 ++--- crates/rapier_testbed2d-f64/Cargo.toml | 2 +- crates/rapier_testbed2d/Cargo.toml | 2 +- crates/rapier_testbed3d-f64/Cargo.toml | 2 +- crates/rapier_testbed3d/Cargo.toml | 2 +- src/counters/timer.rs | 26 ++++++++++++++----------- src/dynamics/island_manager.rs | 8 ++++---- src_testbed/ui.rs | 27 +++++++++++++------------- 13 files changed, 48 insertions(+), 46 deletions(-) diff --git a/.github/workflows/rapier-ci-build.yml b/.github/workflows/rapier-ci-build.yml index 8603f1d07..522840b5c 100644 --- a/.github/workflows/rapier-ci-build.yml +++ b/.github/workflows/rapier-ci-build.yml @@ -75,9 +75,9 @@ jobs: - uses: actions/checkout@v4 - run: rustup target add wasm32-unknown-unknown - name: build rapier2d - run: cd crates/rapier2d && cargo build --verbose --features wasm-bindgen --target wasm32-unknown-unknown; + run: cd crates/rapier2d && cargo build --verbose --target wasm32-unknown-unknown; - name: build rapier3d - run: cd crates/rapier3d && cargo build --verbose --features wasm-bindgen --target wasm32-unknown-unknown; + run: cd crates/rapier3d && cargo build --verbose --target wasm32-unknown-unknown; build-wasm-emscripten: runs-on: ubuntu-latest env: diff --git a/CHANGELOG.md b/CHANGELOG.md index 248e4021a..d19e379f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - `InteractionGroups` default value for `memberships` is now `GROUP_1` (#706) - `ImpulseJointSet::get_mut` has a new parameter `wake_up: bool`, to wake up connected bodies. +- Removed unmaintained `instant` in favor of `web-time`. ## v0.22.0 (20 July 2024) diff --git a/crates/rapier2d-f64/Cargo.toml b/crates/rapier2d-f64/Cargo.toml index 4a149e037..bd3a90c4a 100644 --- a/crates/rapier2d-f64/Cargo.toml +++ b/crates/rapier2d-f64/Cargo.toml @@ -36,7 +36,6 @@ simd-nightly = ["simba/portable_simd", "simd-is-enabled"] # Do not enable this feature directly. It is automatically # enabled with the "simd-stable" or "simd-nightly" feature. simd-is-enabled = ["dep:vec_map"] -wasm-bindgen = ["instant/wasm-bindgen"] serde-serialize = [ "nalgebra/serde-serialize", "parry2d-f64/serde-serialize", @@ -46,7 +45,7 @@ serde-serialize = [ ] enhanced-determinism = ["simba/libm_force", "parry2d-f64/enhanced-determinism"] debug-render = [] -profiler = ["dep:instant"] # Enables the internal profiler. +profiler = ["dep:web-time"] # Enables the internal profiler. # Feature used for debugging only. debug-disable-legitimate-fe-exceptions = [] @@ -66,7 +65,7 @@ required-features = ["dim2", "f64"] [dependencies] vec_map = { version = "0.8", optional = true } -instant = { version = "0.1", features = ["now"], optional = true } +web-time = { version = "1.1", optional = true } num-traits = "0.2" nalgebra = "0.33" parry2d-f64 = "0.17.0" diff --git a/crates/rapier2d/Cargo.toml b/crates/rapier2d/Cargo.toml index f854cb4d5..9757186c8 100644 --- a/crates/rapier2d/Cargo.toml +++ b/crates/rapier2d/Cargo.toml @@ -36,7 +36,6 @@ simd-nightly = ["simba/portable_simd", "simd-is-enabled"] # Do not enable this feature directly. It is automatically # enabled with the "simd-stable" or "simd-nightly" feature. simd-is-enabled = ["dep:vec_map"] -wasm-bindgen = ["instant/wasm-bindgen"] serde-serialize = [ "nalgebra/serde-serialize", "parry2d/serde-serialize", @@ -46,7 +45,7 @@ serde-serialize = [ ] enhanced-determinism = ["simba/libm_force", "parry2d/enhanced-determinism"] debug-render = [] -profiler = ["dep:instant"] # Enables the internal profiler. +profiler = ["dep:web-time"] # Enables the internal profiler. # Feature used for debugging only. debug-disable-legitimate-fe-exceptions = [] @@ -66,7 +65,7 @@ required-features = ["dim2", "f32"] [dependencies] vec_map = { version = "0.8", optional = true } -instant = { version = "0.1", features = ["now"], optional = true } +web-time = { version = "1.1", optional = true } num-traits = "0.2" nalgebra = "0.33" parry2d = "0.17.0" diff --git a/crates/rapier3d-f64/Cargo.toml b/crates/rapier3d-f64/Cargo.toml index a7ea58362..592382817 100644 --- a/crates/rapier3d-f64/Cargo.toml +++ b/crates/rapier3d-f64/Cargo.toml @@ -40,7 +40,6 @@ simd-nightly = [ # Do not enable this feature directly. It is automatically # enabled with the "simd-stable" or "simd-nightly" feature. simd-is-enabled = ["dep:vec_map"] -wasm-bindgen = ["instant/wasm-bindgen"] serde-serialize = [ "nalgebra/serde-serialize", "parry3d-f64/serde-serialize", @@ -49,7 +48,7 @@ serde-serialize = [ ] enhanced-determinism = ["simba/libm_force", "parry3d-f64/enhanced-determinism"] debug-render = [] -profiler = ["dep:instant"] # Enables the internal profiler. +profiler = ["dep:web-time"] # Enables the internal profiler. # Feature used for debugging only. debug-disable-legitimate-fe-exceptions = [] @@ -69,7 +68,7 @@ required-features = ["dim3", "f64"] [dependencies] vec_map = { version = "0.8", optional = true } -instant = { version = "0.1", features = ["now"], optional = true } +web-time = { version = "1.1", optional = true } num-traits = "0.2" nalgebra = "0.33" parry3d-f64 = "0.17.0" diff --git a/crates/rapier3d/Cargo.toml b/crates/rapier3d/Cargo.toml index bc048c140..7f8b4f39b 100644 --- a/crates/rapier3d/Cargo.toml +++ b/crates/rapier3d/Cargo.toml @@ -40,7 +40,6 @@ simd-nightly = [ # Do not enable this feature directly. It is automatically # enabled with the "simd-stable" or "simd-nightly" feature. simd-is-enabled = ["dep:vec_map"] -wasm-bindgen = ["instant/wasm-bindgen"] serde-serialize = [ "nalgebra/serde-serialize", "parry3d/serde-serialize", @@ -49,7 +48,7 @@ serde-serialize = [ ] enhanced-determinism = ["simba/libm_force", "parry3d/enhanced-determinism"] debug-render = [] -profiler = ["dep:instant"] # Enables the internal profiler. +profiler = ["dep:web-time"] # Enables the internal profiler. # Feature used for debugging only. debug-disable-legitimate-fe-exceptions = [] @@ -69,7 +68,7 @@ required-features = ["dim3", "f32"] [dependencies] vec_map = { version = "0.8", optional = true } -instant = { version = "0.1", features = ["now"], optional = true } +web-time = { version = "1.1", optional = true } num-traits = "0.2" nalgebra = "0.33" parry3d = "0.17.0" diff --git a/crates/rapier_testbed2d-f64/Cargo.toml b/crates/rapier_testbed2d-f64/Cargo.toml index fab895872..d8e34e310 100644 --- a/crates/rapier_testbed2d-f64/Cargo.toml +++ b/crates/rapier_testbed2d-f64/Cargo.toml @@ -45,7 +45,7 @@ features = ["parallel", "profiling"] nalgebra = { version = "0.33", features = ["rand", "glam027"] } rand = "0.8" rand_pcg = "0.3" -instant = { version = "0.1", features = ["web-sys", "now"] } +web-time = { version = "1.1" } bitflags = "2" num_cpus = { version = "1", optional = true } wrapped2d = { version = "0.4", optional = true } diff --git a/crates/rapier_testbed2d/Cargo.toml b/crates/rapier_testbed2d/Cargo.toml index b95966f3d..8ef8fd0c9 100644 --- a/crates/rapier_testbed2d/Cargo.toml +++ b/crates/rapier_testbed2d/Cargo.toml @@ -45,7 +45,7 @@ features = ["parallel", "other-backends", "profiling"] nalgebra = { version = "0.33", features = ["rand", "glam027"] } rand = "0.8" rand_pcg = "0.3" -instant = { version = "0.1", features = ["web-sys", "now"] } +web-time = { version = "1.1" } bitflags = "2" num_cpus = { version = "1", optional = true } wrapped2d = { version = "0.4", optional = true } diff --git a/crates/rapier_testbed3d-f64/Cargo.toml b/crates/rapier_testbed3d-f64/Cargo.toml index 97d1a5420..08bd69cad 100644 --- a/crates/rapier_testbed3d-f64/Cargo.toml +++ b/crates/rapier_testbed3d-f64/Cargo.toml @@ -47,7 +47,7 @@ features = ["parallel", "profiling"] nalgebra = { version = "0.33", features = ["rand", "glam027"] } rand = "0.8" rand_pcg = "0.3" -instant = { version = "0.1", features = ["web-sys", "now"] } +web-time = { version = "1.1" } bitflags = "2" num_cpus = { version = "1", optional = true } crossbeam = "0.8" diff --git a/crates/rapier_testbed3d/Cargo.toml b/crates/rapier_testbed3d/Cargo.toml index 2b536abd1..ace9c2db8 100644 --- a/crates/rapier_testbed3d/Cargo.toml +++ b/crates/rapier_testbed3d/Cargo.toml @@ -45,7 +45,7 @@ features = ["parallel", "other-backends", "profiling"] nalgebra = { version = "0.33", features = ["rand", "glam027"] } rand = "0.8" rand_pcg = "0.3" -instant = { version = "0.1", features = ["web-sys", "now"] } +web-time = { version = "1.1" } bitflags = "2" glam = { version = "0.27", optional = true } # For Physx num_cpus = { version = "1", optional = true } diff --git a/src/counters/timer.rs b/src/counters/timer.rs index bc0397d3a..28c674e9a 100644 --- a/src/counters/timer.rs +++ b/src/counters/timer.rs @@ -1,33 +1,37 @@ -use std::fmt::{Display, Error, Formatter}; +use std::{ + fmt::{Display, Error, Formatter}, + time::Duration, +}; +use web_time::Instant; /// A timer. #[derive(Copy, Clone, Debug, Default)] pub struct Timer { - time: f64, + time: Duration, #[allow(dead_code)] // The field isn’t used if the `profiler` feature isn’t enabled. - start: Option, + start: Option, } impl Timer { /// Creates a new timer initialized to zero and not started. pub fn new() -> Self { Timer { - time: 0.0, + time: Duration::from_secs(0), start: None, } } /// Resets the timer to 0. pub fn reset(&mut self) { - self.time = 0.0 + self.time = Duration::from_secs(0) } /// Start the timer. pub fn start(&mut self) { #[cfg(feature = "profiler")] { - self.time = 0.0; - self.start = Some(instant::now()); + self.time = Duration::from_secs(0); + self.start = Some(Instant::now()); } } @@ -36,7 +40,7 @@ impl Timer { #[cfg(feature = "profiler")] { if let Some(start) = self.start { - self.time += instant::now() - start; + self.time += Instant::now() - start; } self.start = None; } @@ -46,18 +50,18 @@ impl Timer { pub fn resume(&mut self) { #[cfg(feature = "profiler")] { - self.start = Some(instant::now()); + self.start = Some(Instant::now()); } } /// The measured time between the last `.start()` and `.pause()` calls. pub fn time(&self) -> f64 { - self.time + self.time.as_secs_f64() / 1000.0 } } impl Display for Timer { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, "{}s", self.time) + write!(f, "{}s", self.time.as_secs_f32()) } } diff --git a/src/dynamics/island_manager.rs b/src/dynamics/island_manager.rs index a576946e5..8a4fa4525 100644 --- a/src/dynamics/island_manager.rs +++ b/src/dynamics/island_manager.rs @@ -165,7 +165,7 @@ impl IslandManager { // Update the energy of every rigid body and // keep only those that may not sleep. - // let t = instant::now(); + // let t = Instant::now(); self.active_set_timestamp += 1; self.stack.clear(); self.can_sleep.clear(); @@ -235,9 +235,9 @@ impl IslandManager { push_contacting_bodies(&rb.colliders, colliders, narrow_phase, &mut self.stack); } - // println!("Selection: {}", instant::now() - t); + // println!("Selection: {}", Instant::now() - t); - // let t = instant::now(); + // let t = Instant::now(); // Propagation of awake state and awake island computation through the // traversal of the interaction graph. self.active_islands_additional_solver_iterations.clear(); @@ -310,7 +310,7 @@ impl IslandManager { self.active_islands.push(self.active_dynamic_set.len()); // println!( // "Extraction: {}, num islands: {}", - // instant::now() - t, + // Instant::now() - t, // self.active_islands.len() - 1 // ); diff --git a/src_testbed/ui.rs b/src_testbed/ui.rs index 8e543afd8..b90f751f3 100644 --- a/src_testbed/ui.rs +++ b/src_testbed/ui.rs @@ -14,6 +14,7 @@ use crate::PhysicsState; use bevy_egui::egui::{Slider, Ui}; use bevy_egui::{egui, EguiContexts}; use rapier::dynamics::IntegrationParameters; +use web_time::Instant; pub fn update_ui( ui_context: &mut EguiContexts, @@ -430,23 +431,23 @@ fn profiling_ui(ui: &mut Ui, counters: &Counters) { } fn serialization_string(timestep_id: usize, physics: &PhysicsState) -> String { - let t = instant::now(); - // let t = instant::now(); + let t = Instant::now(); + // let t = Instant::now(); let bf = bincode::serialize(&physics.broad_phase).unwrap(); - // println!("bf: {}", instant::now() - t); - // let t = instant::now(); + // println!("bf: {}", Instant::now() - t); + // let t = Instant::now(); let nf = bincode::serialize(&physics.narrow_phase).unwrap(); - // println!("nf: {}", instant::now() - t); - // let t = instant::now(); + // println!("nf: {}", Instant::now() - t); + // let t = Instant::now(); let bs = bincode::serialize(&physics.bodies).unwrap(); - // println!("bs: {}", instant::now() - t); - // let t = instant::now(); + // println!("bs: {}", Instant::now() - t); + // let t = Instant::now(); let cs = bincode::serialize(&physics.colliders).unwrap(); - // println!("cs: {}", instant::now() - t); - // let t = instant::now(); + // println!("cs: {}", Instant::now() - t); + // let t = Instant::now(); let js = bincode::serialize(&physics.impulse_joints).unwrap(); - // println!("js: {}", instant::now() - t); - let serialization_time = instant::now() - t; + // println!("js: {}", Instant::now() - t); + let serialization_time = Instant::now() - t; let hash_bf = md5::compute(&bf); let hash_nf = md5::compute(&nf); let hash_bodies = md5::compute(&bs); @@ -460,7 +461,7 @@ Hashes at frame: {} |_ &RigidBodySet [{:.1}KB]: {} |_ Colliders [{:.1}KB]: {} |_ Joints [{:.1}KB]: {}"#, - serialization_time, + serialization_time.as_secs_f64() / 1000.0, timestep_id, bf.len() as f32 / 1000.0, format!("{:?}", hash_bf).split_at(10).0,