Skip to main content

rapier2d/counters/
ccd_counters.rs

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