diff options
| author | Sébastien Crozet <developer@crozet.re> | 2020-08-25 22:10:25 +0200 |
|---|---|---|
| committer | Sébastien Crozet <developer@crozet.re> | 2020-08-25 22:10:25 +0200 |
| commit | 754a48b7ff6d8c58b1ee08651e60112900b60455 (patch) | |
| tree | 7d777a6c003f1f5d8f8d24f533f35a95a88957fe /src | |
| download | rapier-0.1.0.tar.gz rapier-0.1.0.tar.bz2 rapier-0.1.0.zip | |
First public release of Rapier.v0.1.0
Diffstat (limited to 'src')
114 files changed, 24539 insertions, 0 deletions
diff --git a/src/counters/ccd_counters.rs b/src/counters/ccd_counters.rs new file mode 100644 index 0000000..682adfc --- /dev/null +++ b/src/counters/ccd_counters.rs @@ -0,0 +1,49 @@ +use crate::counters::Timer; +use std::fmt::{Display, Formatter, Result}; + +/// Performance counters related to continuous collision detection (CCD). +#[derive(Default, Clone, Copy)] +pub struct CCDCounters { + /// The number of substeps actually performed by the CCD resolution. + pub num_substeps: usize, + /// The total time spent for TOI computation in the CCD resolution. + pub toi_computation_time: Timer, + /// The total time spent for force computation and integration in the CCD resolution. + pub solver_time: Timer, + /// The total time spent by the broad-phase in the CCD resolution. + pub broad_phase_time: Timer, + /// The total time spent by the narrow-phase in the CCD resolution. + pub narrow_phase_time: Timer, +} + +impl CCDCounters { + /// Creates a new counter initialized to zero. + pub fn new() -> Self { + CCDCounters { + num_substeps: 0, + toi_computation_time: Timer::new(), + solver_time: Timer::new(), + broad_phase_time: Timer::new(), + narrow_phase_time: Timer::new(), + } + } + + /// Resets this counter to 0. + pub fn reset(&mut self) { + self.num_substeps = 0; + self.toi_computation_time.reset(); + self.solver_time.reset(); + self.broad_phase_time.reset(); + self.narrow_phase_time.reset(); + } +} + +impl Display for CCDCounters { + fn fmt(&self, f: &mut Formatter) -> Result { + writeln!(f, "Number of substeps: {}", self.num_substeps)?; + writeln!(f, "TOI computation time: {}", self.toi_computation_time)?; + writeln!(f, "Constraints solver time: {}", self.solver_time)?; + writeln!(f, "Broad-phase time: {}", self.broad_phase_time)?; + writeln!(f, "Narrow-phase time: {}", self.narrow_phase_time) + } +} diff --git a/src/counters/collision_detection_counters.rs b/src/counters/collision_detection_counters.rs new file mode 100644 index 0000000..d164452 --- /dev/null +++ b/src/counters/collision_detection_counters.rs @@ -0,0 +1,32 @@ +use crate::counters::Timer; +use std::fmt::{Display, Formatter, Result}; + +/// Performance counters related to collision detection. +#[derive(Default, Clone, Copy)] +pub struct CollisionDetectionCounters { + /// Number of contact pairs detected. + pub ncontact_pairs: usize, + /// Time spent for the broad-phase of the collision detection. + pub broad_phase_time: Timer, + /// Time spent for the narrow-phase of the collision detection. + pub narrow_phase_time: Timer, +} + +impl CollisionDetectionCounters { + /// Creates a new counter initialized to zero. + pub fn new() -> Self { + CollisionDetectionCounters { + ncontact_pairs: 0, + broad_phase_time: Timer::new(), + narrow_phase_time: Timer::new(), + } + } +} + +impl Display for CollisionDetectionCounters { + fn fmt(&self, f: &mut Formatter) -> Result { + writeln!(f, "Number of contact pairs: {}", self.ncontact_pairs)?; + writeln!(f, "Broad-phase time: {}", self.broad_phase_time)?; + writeln!(f, "Narrow-phase time: {}", self.narrow_phase_time) + } +} diff --git a/src/counters/mod.rs b/src/counters/mod.rs new file mode 100644 index 0000000..c172350 --- /dev/null +++ b/src/counters/mod.rs @@ -0,0 +1,225 @@ +//! Counters for benchmarking various parts of the physics engine. + +use std::fmt::{Display, Formatter, Result}; + +pub use self::ccd_counters::CCDCounters; +pub use self::collision_detection_counters::CollisionDetectionCounters; +pub use self::solver_counters::SolverCounters; +pub use self::stages_counters::StagesCounters; +pub use self::timer::Timer; + +mod ccd_counters; +mod collision_detection_counters; +mod solver_counters; +mod stages_counters; +mod timer; + +/// Aggregation of all the performances counters tracked by nphysics. +#[derive(Clone, Copy)] +pub struct Counters { + /// Whether thi counter is enabled or not. + pub enabled: bool, + /// Timer for a whole timestep. + pub step_time: Timer, + /// Timer used for debugging. + pub custom: Timer, + /// Counters of every satge of one time step. + pub stages: StagesCounters, + /// Counters of the collision-detection stage. + pub cd: CollisionDetectionCounters, + /// Counters of the constraints resolution and force computation stage. + pub solver: SolverCounters, + /// Counters for the CCD resolution stage. + pub ccd: CCDCounters, +} + +impl Counters { + /// Create a new set of counters initialized to wero. + pub fn new(enabled: bool) -> Self { + Counters { + enabled, + step_time: Timer::new(), + custom: Timer::new(), + stages: StagesCounters::new(), + cd: CollisionDetectionCounters::new(), + solver: SolverCounters::new(), + ccd: CCDCounters::new(), + } + } + + /// Enable all the counters. + pub fn enable(&mut self) { + self.enabled = true; + } + + /// Return `true` if the counters are enabled. + pub fn enabled(&self) -> bool { + self.enabled + } + + /// Disable all the counters. + pub fn disable(&mut self) { + self.enabled = false; + } + + /// Notify that the time-step has started. + pub fn step_started(&mut self) { + if self.enabled { + self.step_time.start(); + } + } + + /// Notfy that the time-step has finished. + pub fn step_completed(&mut self) { + if self.enabled { + self.step_time.pause(); + } + } + + /// Total time spent for one of the physics engine. + pub fn step_time(&self) -> f64 { + self.step_time.time() + } + + /// Notify that the custom operation has started. + pub fn custom_started(&mut self) { + if self.enabled { + self.custom.start(); + } + } + + /// Notfy that the custom operation has finished. + pub fn custom_completed(&mut self) { + if self.enabled { + self.custom.pause(); + } + } + + /// Total time of a custom event. + pub fn custom_time(&self) -> f64 { + self.custom.time() + } + + /// Set the number of constraints generated. + pub fn set_nconstraints(&mut self, n: usize) { + self.solver.nconstraints = n; + } + + /// Set the number of contacts generated. |
