-
-
Notifications
You must be signed in to change notification settings - Fork 352
Expand file tree
/
Copy pathcollision_detection_counters.rs
More file actions
39 lines (35 loc) · 1.25 KB
/
collision_detection_counters.rs
File metadata and controls
39 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::counters::Timer;
use std::fmt::{Display, Formatter, Result};
/// Performance counters related to collision detection.
#[derive(Default, Debug, 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(),
}
}
/// Resets all the counters and timers.
pub fn reset(&mut self) {
self.ncontact_pairs = 0;
self.broad_phase_time.reset();
self.narrow_phase_time.reset();
}
}
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)
}
}