avian3d/collision/
diagnostics.rs

1use bevy::{
2    diagnostic::DiagnosticPath,
3    prelude::{ReflectResource, Resource},
4    reflect::Reflect,
5};
6use core::time::Duration;
7
8use crate::diagnostics::{impl_diagnostic_paths, PhysicsDiagnostics};
9
10/// Diagnostics for collision detection.
11#[derive(Resource, Debug, Default, Reflect)]
12#[reflect(Resource, Debug)]
13pub struct CollisionDiagnostics {
14    /// Time spent finding potential collision pairs in the broad phase.
15    pub broad_phase: Duration,
16    /// Time spent updating contacts in the narrow phase.
17    pub narrow_phase: Duration,
18    /// The number of contacts.
19    pub contact_count: u32,
20}
21
22impl PhysicsDiagnostics for CollisionDiagnostics {
23    fn timer_paths(&self) -> Vec<(&'static DiagnosticPath, Duration)> {
24        vec![
25            (Self::BROAD_PHASE, self.broad_phase),
26            (Self::NARROW_PHASE, self.narrow_phase),
27        ]
28    }
29
30    fn counter_paths(&self) -> Vec<(&'static DiagnosticPath, u32)> {
31        vec![(Self::CONTACT_COUNT, self.contact_count)]
32    }
33}
34
35impl_diagnostic_paths! {
36    impl CollisionDiagnostics {
37        BROAD_PHASE: "avian/collision/broad_phase",
38        NARROW_PHASE: "avian/collision/update_contacts",
39        CONTACT_COUNT: "avian/collision/contact_count",
40    }
41}