Skip to main content

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    /// Time spent for collecting awake constraints from islands.
14    pub island_constraints_collection_time: Timer,
15    /// Total time spent for the constraints resolution and position update.t
16    pub solver_time: Timer,
17    /// Total time spent for CCD and CCD resolution.
18    pub ccd_time: Timer,
19    /// Total time spent propagating user changes.
20    pub user_changes: Timer,
21}
22
23impl StagesCounters {
24    /// Create a new counter initialized to zero.
25    pub fn new() -> Self {
26        StagesCounters {
27            update_time: Timer::new(),
28            collision_detection_time: Timer::new(),
29            island_construction_time: Timer::new(),
30            island_constraints_collection_time: Timer::new(),
31            solver_time: Timer::new(),
32            ccd_time: Timer::new(),
33            user_changes: Timer::new(),
34        }
35    }
36
37    /// Resets all the counters and timers.
38    pub fn reset(&mut self) {
39        self.update_time.reset();
40        self.collision_detection_time.reset();
41        self.island_construction_time.reset();
42        self.island_constraints_collection_time.reset();
43        self.solver_time.reset();
44        self.ccd_time.reset();
45        self.user_changes.reset();
46    }
47}
48
49impl Display for StagesCounters {
50    fn fmt(&self, f: &mut Formatter) -> Result {
51        writeln!(f, "Update time: {}", self.update_time)?;
52        writeln!(
53            f,
54            "Collision detection time: {}",
55            self.collision_detection_time
56        )?;
57        writeln!(
58            f,
59            "Island construction time: {}",
60            self.island_construction_time
61        )?;
62        writeln!(
63            f,
64            "Island construction time: {}",
65            self.island_constraints_collection_time
66        )?;
67        writeln!(f, "Solver time: {}", self.solver_time)?;
68        writeln!(f, "CCD time: {}", self.ccd_time)?;
69        writeln!(f, "User changes time: {}", self.user_changes)
70    }
71}