rapier3d/counters/
ccd_counters.rs

1use crate::counters::Timer;
2use std::fmt::{Display, Formatter, Result};
3
4/// Performance counters related to continuous collision detection (CCD).
5#[derive(Default, Clone, Copy)]
6pub struct CCDCounters {
7    /// The number of substeps actually performed by the CCD resolution.
8    pub num_substeps: usize,
9    /// The total time spent for TOI computation in the CCD resolution.
10    pub toi_computation_time: Timer,
11    /// The total time spent for force computation and integration in the CCD resolution.
12    pub solver_time: Timer,
13    /// The total time spent by the broad-phase in the CCD resolution.
14    pub broad_phase_time: Timer,
15    /// The total time spent by the narrow-phase in the CCD resolution.
16    pub narrow_phase_time: Timer,
17}
18
19impl CCDCounters {
20    /// Creates a new counter initialized to zero.
21    pub fn new() -> Self {
22        CCDCounters {
23            num_substeps: 0,
24            toi_computation_time: Timer::new(),
25            solver_time: Timer::new(),
26            broad_phase_time: Timer::new(),
27            narrow_phase_time: Timer::new(),
28        }
29    }
30
31    /// Resets this counter to 0.
32    pub fn reset(&mut self) {
33        self.num_substeps = 0;
34        self.toi_computation_time.reset();
35        self.solver_time.reset();
36        self.broad_phase_time.reset();
37        self.narrow_phase_time.reset();
38    }
39}
40
41impl Display for CCDCounters {
42    fn fmt(&self, f: &mut Formatter) -> Result {
43        writeln!(f, "Number of substeps: {}", self.num_substeps)?;
44        writeln!(f, "TOI computation time: {}", self.toi_computation_time)?;
45        writeln!(f, "Constraints solver time: {}", self.solver_time)?;
46        writeln!(f, "Broad-phase time: {}", self.broad_phase_time)?;
47        writeln!(f, "Narrow-phase time: {}", self.narrow_phase_time)
48    }
49}