rapier2d/counters/
stages_counters.rs

1use crate::counters::Timer;
2use std::fmt::{Display, Formatter, Result};
3
4/// Performance counters related to each stage of the time step.
5#[derive(Default, Clone, Copy)]
6pub struct StagesCounters {
7    /// Time spent for updating the kinematic and dynamics of every body.
8    pub update_time: Timer,
9    /// Total time spent for the collision detection (including both broad- and narrow- phases).
10    pub collision_detection_time: Timer,
11    /// Time spent for the computation of collision island and body activation/deactivation (sleeping).
12    pub island_construction_time: Timer,
13    /// Total time spent for the constraints resolution and position update.t
14    pub solver_time: Timer,
15    /// Total time spent for CCD and CCD resolution.
16    pub ccd_time: Timer,
17    /// Total time spent propagating user changes.
18    pub user_changes: Timer,
19}
20
21impl StagesCounters {
22    /// Create a new counter initialized to zero.
23    pub fn new() -> Self {
24        StagesCounters {
25            update_time: Timer::new(),
26            collision_detection_time: Timer::new(),
27            island_construction_time: Timer::new(),
28            solver_time: Timer::new(),
29            ccd_time: Timer::new(),
30            user_changes: Timer::new(),
31        }
32    }
33
34    /// Resets all the counters and timers.
35    pub fn reset(&mut self) {
36        self.update_time.reset();
37        self.collision_detection_time.reset();
38        self.island_construction_time.reset();
39        self.solver_time.reset();
40        self.ccd_time.reset();
41        self.user_changes.reset();
42    }
43}
44
45impl Display for StagesCounters {
46    fn fmt(&self, f: &mut Formatter) -> Result {
47        writeln!(f, "Update time: {}", self.update_time)?;
48        writeln!(
49            f,
50            "Collision detection time: {}",
51            self.collision_detection_time
52        )?;
53        writeln!(
54            f,
55            "Island construction time: {}",
56            self.island_construction_time
57        )?;
58        writeln!(f, "Solver time: {}", self.solver_time)?;
59        writeln!(f, "CCD time: {}", self.ccd_time)?;
60        writeln!(f, "User changes time: {}", self.user_changes)
61    }
62}