Remove instant dependency in favor of web-time (#767)

This commit is contained in:
Thierry Berger
2024-12-06 12:54:00 +01:00
committed by GitHub
parent 93bd37d814
commit cf77b5bf57
15 changed files with 107 additions and 83 deletions

View File

@@ -75,9 +75,9 @@ jobs:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- run: rustup target add wasm32-unknown-unknown - run: rustup target add wasm32-unknown-unknown
- name: build rapier2d - 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 - 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: build-wasm-emscripten:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:

View File

@@ -18,6 +18,7 @@
- `InteractionGroups` default value for `memberships` is now `GROUP_1` (#706) - `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. - `ImpulseJointSet::get_mut` has a new parameter `wake_up: bool`, to wake up connected bodies.
- Removed unmaintained `instant` in favor of `web-time`. This effectively removes the `wasm-bindgen` transitive dependency as it's no longer needed.
## v0.22.0 (20 July 2024) ## v0.22.0 (20 July 2024)

View File

@@ -36,7 +36,6 @@ simd-nightly = ["simba/portable_simd", "simd-is-enabled"]
# Do not enable this feature directly. It is automatically # Do not enable this feature directly. It is automatically
# enabled with the "simd-stable" or "simd-nightly" feature. # enabled with the "simd-stable" or "simd-nightly" feature.
simd-is-enabled = ["dep:vec_map"] simd-is-enabled = ["dep:vec_map"]
wasm-bindgen = ["instant/wasm-bindgen"]
serde-serialize = [ serde-serialize = [
"nalgebra/serde-serialize", "nalgebra/serde-serialize",
"parry2d-f64/serde-serialize", "parry2d-f64/serde-serialize",
@@ -46,7 +45,7 @@ serde-serialize = [
] ]
enhanced-determinism = ["simba/libm_force", "parry2d-f64/enhanced-determinism"] enhanced-determinism = ["simba/libm_force", "parry2d-f64/enhanced-determinism"]
debug-render = [] debug-render = []
profiler = ["dep:instant"] # Enables the internal profiler. profiler = ["dep:web-time"] # Enables the internal profiler.
# Feature used for debugging only. # Feature used for debugging only.
debug-disable-legitimate-fe-exceptions = [] debug-disable-legitimate-fe-exceptions = []
@@ -66,7 +65,7 @@ required-features = ["dim2", "f64"]
[dependencies] [dependencies]
vec_map = { version = "0.8", optional = true } 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" num-traits = "0.2"
nalgebra = "0.33" nalgebra = "0.33"
parry2d-f64 = "0.17.0" parry2d-f64 = "0.17.0"

View File

@@ -36,7 +36,6 @@ simd-nightly = ["simba/portable_simd", "simd-is-enabled"]
# Do not enable this feature directly. It is automatically # Do not enable this feature directly. It is automatically
# enabled with the "simd-stable" or "simd-nightly" feature. # enabled with the "simd-stable" or "simd-nightly" feature.
simd-is-enabled = ["dep:vec_map"] simd-is-enabled = ["dep:vec_map"]
wasm-bindgen = ["instant/wasm-bindgen"]
serde-serialize = [ serde-serialize = [
"nalgebra/serde-serialize", "nalgebra/serde-serialize",
"parry2d/serde-serialize", "parry2d/serde-serialize",
@@ -46,7 +45,7 @@ serde-serialize = [
] ]
enhanced-determinism = ["simba/libm_force", "parry2d/enhanced-determinism"] enhanced-determinism = ["simba/libm_force", "parry2d/enhanced-determinism"]
debug-render = [] debug-render = []
profiler = ["dep:instant"] # Enables the internal profiler. profiler = ["dep:web-time"] # Enables the internal profiler.
# Feature used for debugging only. # Feature used for debugging only.
debug-disable-legitimate-fe-exceptions = [] debug-disable-legitimate-fe-exceptions = []
@@ -66,7 +65,7 @@ required-features = ["dim2", "f32"]
[dependencies] [dependencies]
vec_map = { version = "0.8", optional = true } 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" num-traits = "0.2"
nalgebra = "0.33" nalgebra = "0.33"
parry2d = "0.17.0" parry2d = "0.17.0"

View File

@@ -40,7 +40,6 @@ simd-nightly = [
# Do not enable this feature directly. It is automatically # Do not enable this feature directly. It is automatically
# enabled with the "simd-stable" or "simd-nightly" feature. # enabled with the "simd-stable" or "simd-nightly" feature.
simd-is-enabled = ["dep:vec_map"] simd-is-enabled = ["dep:vec_map"]
wasm-bindgen = ["instant/wasm-bindgen"]
serde-serialize = [ serde-serialize = [
"nalgebra/serde-serialize", "nalgebra/serde-serialize",
"parry3d-f64/serde-serialize", "parry3d-f64/serde-serialize",
@@ -49,7 +48,7 @@ serde-serialize = [
] ]
enhanced-determinism = ["simba/libm_force", "parry3d-f64/enhanced-determinism"] enhanced-determinism = ["simba/libm_force", "parry3d-f64/enhanced-determinism"]
debug-render = [] debug-render = []
profiler = ["dep:instant"] # Enables the internal profiler. profiler = ["dep:web-time"] # Enables the internal profiler.
# Feature used for debugging only. # Feature used for debugging only.
debug-disable-legitimate-fe-exceptions = [] debug-disable-legitimate-fe-exceptions = []
@@ -69,7 +68,7 @@ required-features = ["dim3", "f64"]
[dependencies] [dependencies]
vec_map = { version = "0.8", optional = true } 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" num-traits = "0.2"
nalgebra = "0.33" nalgebra = "0.33"
parry3d-f64 = "0.17.0" parry3d-f64 = "0.17.0"

View File

@@ -40,7 +40,6 @@ simd-nightly = [
# Do not enable this feature directly. It is automatically # Do not enable this feature directly. It is automatically
# enabled with the "simd-stable" or "simd-nightly" feature. # enabled with the "simd-stable" or "simd-nightly" feature.
simd-is-enabled = ["dep:vec_map"] simd-is-enabled = ["dep:vec_map"]
wasm-bindgen = ["instant/wasm-bindgen"]
serde-serialize = [ serde-serialize = [
"nalgebra/serde-serialize", "nalgebra/serde-serialize",
"parry3d/serde-serialize", "parry3d/serde-serialize",
@@ -49,7 +48,7 @@ serde-serialize = [
] ]
enhanced-determinism = ["simba/libm_force", "parry3d/enhanced-determinism"] enhanced-determinism = ["simba/libm_force", "parry3d/enhanced-determinism"]
debug-render = [] debug-render = []
profiler = ["dep:instant"] # Enables the internal profiler. profiler = ["dep:web-time"] # Enables the internal profiler.
# Feature used for debugging only. # Feature used for debugging only.
debug-disable-legitimate-fe-exceptions = [] debug-disable-legitimate-fe-exceptions = []
@@ -69,7 +68,7 @@ required-features = ["dim3", "f32"]
[dependencies] [dependencies]
vec_map = { version = "0.8", optional = true } 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" num-traits = "0.2"
nalgebra = "0.33" nalgebra = "0.33"
parry3d = "0.17.0" parry3d = "0.17.0"

View File

@@ -48,7 +48,7 @@ needless_lifetimes = "allow"
nalgebra = { version = "0.33", features = ["rand", "glam027"] } nalgebra = { version = "0.33", features = ["rand", "glam027"] }
rand = "0.8" rand = "0.8"
rand_pcg = "0.3" rand_pcg = "0.3"
instant = { version = "0.1", features = ["web-sys", "now"] } web-time = { version = "1.1" }
bitflags = "2" bitflags = "2"
num_cpus = { version = "1", optional = true } num_cpus = { version = "1", optional = true }
wrapped2d = { version = "0.4", optional = true } wrapped2d = { version = "0.4", optional = true }

View File

@@ -48,7 +48,7 @@ needless_lifetimes = "allow"
nalgebra = { version = "0.33", features = ["rand", "glam027"] } nalgebra = { version = "0.33", features = ["rand", "glam027"] }
rand = "0.8" rand = "0.8"
rand_pcg = "0.3" rand_pcg = "0.3"
instant = { version = "0.1", features = ["web-sys", "now"] } web-time = { version = "1.1" }
bitflags = "2" bitflags = "2"
num_cpus = { version = "1", optional = true } num_cpus = { version = "1", optional = true }
wrapped2d = { version = "0.4", optional = true } wrapped2d = { version = "0.4", optional = true }

View File

@@ -50,7 +50,7 @@ needless_lifetimes = "allow"
nalgebra = { version = "0.33", features = ["rand", "glam027"] } nalgebra = { version = "0.33", features = ["rand", "glam027"] }
rand = "0.8" rand = "0.8"
rand_pcg = "0.3" rand_pcg = "0.3"
instant = { version = "0.1", features = ["web-sys", "now"] } web-time = { version = "1.1" }
bitflags = "2" bitflags = "2"
num_cpus = { version = "1", optional = true } num_cpus = { version = "1", optional = true }
crossbeam = "0.8" crossbeam = "0.8"

View File

@@ -48,7 +48,7 @@ needless_lifetimes = "allow"
nalgebra = { version = "0.33", features = ["rand", "glam027"] } nalgebra = { version = "0.33", features = ["rand", "glam027"] }
rand = "0.8" rand = "0.8"
rand_pcg = "0.3" rand_pcg = "0.3"
instant = { version = "0.1", features = ["web-sys", "now"] } web-time = { version = "1.1" }
bitflags = "2" bitflags = "2"
glam = { version = "0.27", optional = true } # For Physx glam = { version = "0.27", optional = true } # For Physx
num_cpus = { version = "1", optional = true } num_cpus = { version = "1", optional = true }

View File

@@ -1,5 +1,6 @@
//! Counters for benchmarking various parts of the physics engine. //! Counters for benchmarking various parts of the physics engine.
use core::time::Duration;
use std::fmt::{Display, Formatter, Result}; use std::fmt::{Display, Formatter, Result};
pub use self::ccd_counters::CCDCounters; pub use self::ccd_counters::CCDCounters;
@@ -77,10 +78,15 @@ impl Counters {
} }
/// Total time spent for one of the physics engine. /// Total time spent for one of the physics engine.
pub fn step_time(&self) -> f64 { pub fn step_time(&self) -> Duration {
self.step_time.time() self.step_time.time()
} }
/// Total time spent for one of the physics engine, in milliseconds.
pub fn step_time_ms(&self) -> f64 {
self.step_time.time_ms()
}
/// Notify that the custom operation has started. /// Notify that the custom operation has started.
pub fn custom_started(&mut self) { pub fn custom_started(&mut self) {
if self.enabled { if self.enabled {
@@ -96,10 +102,15 @@ impl Counters {
} }
/// Total time of a custom event. /// Total time of a custom event.
pub fn custom_time(&self) -> f64 { pub fn custom_time(&self) -> Duration {
self.custom.time() self.custom.time()
} }
/// Total time of a custom event, in milliseconds.
pub fn custom_time_ms(&self) -> f64 {
self.custom.time_ms()
}
/// Set the number of constraints generated. /// Set the number of constraints generated.
pub fn set_nconstraints(&mut self, n: usize) { pub fn set_nconstraints(&mut self, n: usize) {
self.solver.nconstraints = n; self.solver.nconstraints = n;
@@ -129,7 +140,7 @@ impl Counters {
} }
macro_rules! measure_method { macro_rules! measure_method {
($started:ident, $stopped:ident, $time:ident, $info:ident. $timer:ident) => { ($started:ident, $stopped:ident, $time_ms:ident, $info:ident. $timer:ident) => {
impl Counters { impl Counters {
/// Start this timer. /// Start this timer.
pub fn $started(&mut self) { pub fn $started(&mut self) {
@@ -145,10 +156,10 @@ macro_rules! measure_method {
} }
} }
/// Gets the time elapsed for this timer. /// Gets the time elapsed for this timer, in milliseconds.
pub fn $time(&self) -> f64 { pub fn $time_ms(&self) -> f64 {
if self.enabled { if self.enabled {
self.$info.$timer.time() self.$info.$timer.time_ms()
} else { } else {
0.0 0.0
} }
@@ -160,63 +171,63 @@ macro_rules! measure_method {
measure_method!( measure_method!(
update_started, update_started,
update_completed, update_completed,
update_time, update_time_ms,
stages.update_time stages.update_time
); );
measure_method!( measure_method!(
collision_detection_started, collision_detection_started,
collision_detection_completed, collision_detection_completed,
collision_detection_time, collision_detection_time_ms,
stages.collision_detection_time stages.collision_detection_time
); );
measure_method!( measure_method!(
island_construction_started, island_construction_started,
island_construction_completed, island_construction_completed,
island_construction_time, island_construction_time_ms,
stages.island_construction_time stages.island_construction_time
); );
measure_method!( measure_method!(
solver_started, solver_started,
solver_completed, solver_completed,
solver_time, solver_time_ms,
stages.solver_time stages.solver_time
); );
measure_method!(ccd_started, ccd_completed, ccd_time, stages.ccd_time); measure_method!(ccd_started, ccd_completed, ccd_time_ms, stages.ccd_time);
measure_method!( measure_method!(
query_pipeline_update_started, query_pipeline_update_started,
query_pipeline_update_completed, query_pipeline_update_completed,
query_pipeline_update_time, query_pipeline_update_time_ms,
stages.query_pipeline_time stages.query_pipeline_time
); );
measure_method!( measure_method!(
assembly_started, assembly_started,
assembly_completed, assembly_completed,
assembly_time, assembly_time_ms,
solver.velocity_assembly_time solver.velocity_assembly_time
); );
measure_method!( measure_method!(
velocity_resolution_started, velocity_resolution_started,
velocity_resolution_completed, velocity_resolution_completed,
velocity_resolution_time, velocity_resolution_time_ms,
solver.velocity_resolution_time solver.velocity_resolution_time
); );
measure_method!( measure_method!(
velocity_update_started, velocity_update_started,
velocity_update_completed, velocity_update_completed,
velocity_update_time, velocity_update_time_ms,
solver.velocity_update_time solver.velocity_update_time
); );
measure_method!( measure_method!(
broad_phase_started, broad_phase_started,
broad_phase_completed, broad_phase_completed,
broad_phase_time, broad_phase_time_ms,
cd.broad_phase_time cd.broad_phase_time
); );
measure_method!( measure_method!(
narrow_phase_started, narrow_phase_started,
narrow_phase_completed, narrow_phase_completed,
narrow_phase_time, narrow_phase_time_ms,
cd.narrow_phase_time cd.narrow_phase_time
); );

View File

@@ -1,33 +1,36 @@
use std::fmt::{Display, Error, Formatter}; use std::{
fmt::{Display, Error, Formatter},
time::Duration,
};
/// A timer. /// A timer.
#[derive(Copy, Clone, Debug, Default)] #[derive(Copy, Clone, Debug, Default)]
pub struct Timer { pub struct Timer {
time: f64, time: Duration,
#[allow(dead_code)] // The field isnt used if the `profiler` feature isnt enabled. #[allow(dead_code)] // The field isnt used if the `profiler` feature isnt enabled.
start: Option<f64>, start: Option<std::time::Instant>,
} }
impl Timer { impl Timer {
/// Creates a new timer initialized to zero and not started. /// Creates a new timer initialized to zero and not started.
pub fn new() -> Self { pub fn new() -> Self {
Timer { Timer {
time: 0.0, time: Duration::from_secs(0),
start: None, start: None,
} }
} }
/// Resets the timer to 0. /// Resets the timer to 0.
pub fn reset(&mut self) { pub fn reset(&mut self) {
self.time = 0.0 self.time = Duration::from_secs(0)
} }
/// Start the timer. /// Start the timer.
pub fn start(&mut self) { pub fn start(&mut self) {
#[cfg(feature = "profiler")] #[cfg(feature = "profiler")]
{ {
self.time = 0.0; self.time = Duration::from_secs(0);
self.start = Some(instant::now()); self.start = Some(web_time::Instant::now());
} }
} }
@@ -36,7 +39,7 @@ impl Timer {
#[cfg(feature = "profiler")] #[cfg(feature = "profiler")]
{ {
if let Some(start) = self.start { if let Some(start) = self.start {
self.time += instant::now() - start; self.time += web_time::Instant::now().duration_since(start);
} }
self.start = None; self.start = None;
} }
@@ -46,18 +49,23 @@ impl Timer {
pub fn resume(&mut self) { pub fn resume(&mut self) {
#[cfg(feature = "profiler")] #[cfg(feature = "profiler")]
{ {
self.start = Some(instant::now()); self.start = Some(web_time::Instant::now());
} }
} }
/// The measured time between the last `.start()` and `.pause()` calls. /// The measured time between the last `.start()` and `.pause()` calls.
pub fn time(&self) -> f64 { pub fn time(&self) -> Duration {
self.time self.time
} }
/// The measured time in milliseconds between the last `.start()` and `.pause()` calls.
pub fn time_ms(&self) -> f64 {
self.time.as_secs_f64() * 1000.0
}
} }
impl Display for Timer { impl Display for Timer {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
write!(f, "{}s", self.time) write!(f, "{}ms", self.time_ms())
} }
} }

View File

@@ -165,7 +165,7 @@ impl IslandManager {
// Update the energy of every rigid body and // Update the energy of every rigid body and
// keep only those that may not sleep. // keep only those that may not sleep.
// let t = instant::now(); // let t = Instant::now();
self.active_set_timestamp += 1; self.active_set_timestamp += 1;
self.stack.clear(); self.stack.clear();
self.can_sleep.clear(); self.can_sleep.clear();
@@ -235,9 +235,9 @@ impl IslandManager {
push_contacting_bodies(&rb.colliders, colliders, narrow_phase, &mut self.stack); 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 // Propagation of awake state and awake island computation through the
// traversal of the interaction graph. // traversal of the interaction graph.
self.active_islands_additional_solver_iterations.clear(); self.active_islands_additional_solver_iterations.clear();
@@ -310,7 +310,7 @@ impl IslandManager {
self.active_islands.push(self.active_dynamic_set.len()); self.active_islands.push(self.active_dynamic_set.len());
// println!( // println!(
// "Extraction: {}, num islands: {}", // "Extraction: {}, num islands: {}",
// instant::now() - t, // Instant::now() - t,
// self.active_islands.len() - 1 // self.active_islands.len() - 1
// ); // );

View File

@@ -393,7 +393,8 @@ impl TestbedApp {
// Skip the first update. // Skip the first update.
if k > 0 { if k > 0 {
timings.push(self.harness.physics.pipeline.counters.step_time.time()); timings
.push(self.harness.physics.pipeline.counters.step_time.time_ms());
} }
} }
results.push(timings); results.push(timings);

View File

@@ -14,6 +14,7 @@ use crate::PhysicsState;
use bevy_egui::egui::{Slider, Ui}; use bevy_egui::egui::{Slider, Ui};
use bevy_egui::{egui, EguiContexts}; use bevy_egui::{egui, EguiContexts};
use rapier::dynamics::IntegrationParameters; use rapier::dynamics::IntegrationParameters;
use web_time::Instant;
pub fn update_ui( pub fn update_ui(
ui_context: &mut EguiContexts, ui_context: &mut EguiContexts,
@@ -359,94 +360,100 @@ fn scene_infos_ui(ui: &mut Ui, physics: &PhysicsState) {
fn profiling_ui(ui: &mut Ui, counters: &Counters) { fn profiling_ui(ui: &mut Ui, counters: &Counters) {
egui::CollapsingHeader::new(format!( egui::CollapsingHeader::new(format!(
"Total: {:.2}ms - {} fps", "Total: {:.2}ms - {} fps",
counters.step_time(), counters.step_time_ms(),
(1000.0 / counters.step_time()).round() (1000.0 / counters.step_time_ms()).round()
)) ))
.id_source("total") .id_source("total")
.show(ui, |ui| { .show(ui, |ui| {
egui::CollapsingHeader::new(format!( egui::CollapsingHeader::new(format!(
"Collision detection: {:.2}ms", "Collision detection: {:.2}ms",
counters.collision_detection_time() counters.collision_detection_time_ms()
)) ))
.id_source("collision detection") .id_source("collision detection")
.show(ui, |ui| { .show(ui, |ui| {
ui.label(format!("Broad-phase: {:.2}ms", counters.broad_phase_time())); ui.label(format!(
"Broad-phase: {:.2}ms",
counters.broad_phase_time_ms()
));
ui.label(format!( ui.label(format!(
"Narrow-phase: {:.2}ms", "Narrow-phase: {:.2}ms",
counters.narrow_phase_time() counters.narrow_phase_time_ms()
)); ));
}); });
egui::CollapsingHeader::new(format!("Solver: {:.2}ms", counters.solver_time())) egui::CollapsingHeader::new(format!("Solver: {:.2}ms", counters.solver_time_ms()))
.id_source("solver") .id_source("solver")
.show(ui, |ui| { .show(ui, |ui| {
ui.label(format!( ui.label(format!(
"Velocity assembly: {:.2}ms", "Velocity assembly: {:.2}ms",
counters.solver.velocity_assembly_time.time() counters.solver.velocity_assembly_time.time_ms()
)); ));
ui.label(format!( ui.label(format!(
"Velocity resolution: {:.2}ms", "Velocity resolution: {:.2}ms",
counters.velocity_resolution_time() counters.velocity_resolution_time_ms()
)); ));
ui.label(format!( ui.label(format!(
"Velocity integration: {:.2}ms", "Velocity integration: {:.2}ms",
counters.solver.velocity_update_time.time() counters.solver.velocity_update_time.time_ms()
)); ));
ui.label(format!( ui.label(format!(
"Writeback: {:.2}ms", "Writeback: {:.2}ms",
counters.solver.velocity_writeback_time.time() counters.solver.velocity_writeback_time.time_ms()
)); ));
}); });
egui::CollapsingHeader::new(format!("CCD: {:.2}ms", counters.ccd_time())) egui::CollapsingHeader::new(format!("CCD: {:.2}ms", counters.ccd_time_ms()))
.id_source("ccd") .id_source("ccd")
.show(ui, |ui| { .show(ui, |ui| {
ui.label(format!("# of substeps: {}", counters.ccd.num_substeps)); ui.label(format!("# of substeps: {}", counters.ccd.num_substeps));
ui.label(format!( ui.label(format!(
"TOI computation: {:.2}ms", "TOI computation: {:.2}ms",
counters.ccd.toi_computation_time.time(), counters.ccd.toi_computation_time.time_ms(),
)); ));
ui.label(format!( ui.label(format!(
"Broad-phase: {:.2}ms", "Broad-phase: {:.2}ms",
counters.ccd.broad_phase_time.time() counters.ccd.broad_phase_time.time_ms()
)); ));
ui.label(format!( ui.label(format!(
"Narrow-phase: {:.2}ms", "Narrow-phase: {:.2}ms",
counters.ccd.narrow_phase_time.time(), counters.ccd.narrow_phase_time.time_ms(),
));
ui.label(format!(
"Solver: {:.2}ms",
counters.ccd.solver_time.time_ms()
)); ));
ui.label(format!("Solver: {:.2}ms", counters.ccd.solver_time.time()));
}); });
ui.label(format!( ui.label(format!(
"Island computation: {:.2}ms", "Island computation: {:.2}ms",
counters.island_construction_time() counters.island_construction_time_ms()
)); ));
ui.label(format!( ui.label(format!(
"Query pipeline: {:.2}ms", "Query pipeline: {:.2}ms",
counters.query_pipeline_update_time() counters.query_pipeline_update_time_ms()
)); ));
ui.label(format!( ui.label(format!(
"User changes: {:.2}ms", "User changes: {:.2}ms",
counters.stages.user_changes.time() counters.stages.user_changes.time_ms()
)); ));
}); });
} }
fn serialization_string(timestep_id: usize, physics: &PhysicsState) -> String { 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(); let bf = bincode::serialize(&physics.broad_phase).unwrap();
// println!("bf: {}", instant::now() - t); // println!("bf: {}", Instant::now() - t);
// let t = instant::now(); // let t = Instant::now();
let nf = bincode::serialize(&physics.narrow_phase).unwrap(); let nf = bincode::serialize(&physics.narrow_phase).unwrap();
// println!("nf: {}", instant::now() - t); // println!("nf: {}", Instant::now() - t);
// let t = instant::now(); // let t = Instant::now();
let bs = bincode::serialize(&physics.bodies).unwrap(); let bs = bincode::serialize(&physics.bodies).unwrap();
// println!("bs: {}", instant::now() - t); // println!("bs: {}", Instant::now() - t);
// let t = instant::now(); // let t = Instant::now();
let cs = bincode::serialize(&physics.colliders).unwrap(); let cs = bincode::serialize(&physics.colliders).unwrap();
// println!("cs: {}", instant::now() - t); // println!("cs: {}", Instant::now() - t);
// let t = instant::now(); // let t = Instant::now();
let js = bincode::serialize(&physics.impulse_joints).unwrap(); let js = bincode::serialize(&physics.impulse_joints).unwrap();
// println!("js: {}", instant::now() - t); // println!("js: {}", Instant::now() - t);
let serialization_time = instant::now() - t; let serialization_time = Instant::now() - t;
let hash_bf = md5::compute(&bf); let hash_bf = md5::compute(&bf);
let hash_nf = md5::compute(&nf); let hash_nf = md5::compute(&nf);
let hash_bodies = md5::compute(&bs); let hash_bodies = md5::compute(&bs);
@@ -460,7 +467,7 @@ Hashes at frame: {}
|_ &RigidBodySet [{:.1}KB]: {} |_ &RigidBodySet [{:.1}KB]: {}
|_ Colliders [{:.1}KB]: {} |_ Colliders [{:.1}KB]: {}
|_ Joints [{:.1}KB]: {}"#, |_ Joints [{:.1}KB]: {}"#,
serialization_time, serialization_time.as_secs_f64() * 1000.0,
timestep_id, timestep_id,
bf.len() as f32 / 1000.0, bf.len() as f32 / 1000.0,
format!("{:?}", hash_bf).split_at(10).0, format!("{:?}", hash_bf).split_at(10).0,