avian2d/dynamics/solver/
diagnostics.rs1use bevy::{
2 diagnostic::DiagnosticPath,
3 prelude::{ReflectResource, Resource},
4 reflect::Reflect,
5};
6use core::time::Duration;
7
8use crate::diagnostics::{PhysicsDiagnostics, impl_diagnostic_paths};
9
10#[derive(Resource, Debug, Default, Reflect)]
12#[reflect(Resource, Debug)]
13pub struct SolverDiagnostics {
14 pub prepare_constraints: Duration,
16 pub update_velocity_increments: Duration,
20 pub integrate_velocities: Duration,
22 pub warm_start: Duration,
24 pub solve_constraints: Duration,
26 pub integrate_positions: Duration,
28 pub relax_velocities: Duration,
30 pub apply_restitution: Duration,
32 pub finalize: Duration,
34 pub store_impulses: Duration,
36 pub swept_ccd: Duration,
38 pub contact_constraint_count: u32,
40}
41
42impl PhysicsDiagnostics for SolverDiagnostics {
43 fn timer_paths(&self) -> Vec<(&'static DiagnosticPath, Duration)> {
44 vec![
45 (Self::PREPARE_CONSTRAINTS, self.prepare_constraints),
46 (
47 Self::UPDATE_VELOCITY_INCREMENTS,
48 self.update_velocity_increments,
49 ),
50 (Self::INTEGRATE_VELOCITIES, self.integrate_velocities),
51 (Self::WARM_START, self.warm_start),
52 (Self::SOLVE_CONSTRAINTS, self.solve_constraints),
53 (Self::INTEGRATE_POSITIONS, self.integrate_positions),
54 (Self::RELAX_VELOCITIES, self.relax_velocities),
55 (Self::APPLY_RESTITUTION, self.apply_restitution),
56 (Self::FINALIZE, self.finalize),
57 (Self::STORE_IMPULSES, self.store_impulses),
58 (Self::SWEPT_CCD, self.swept_ccd),
59 ]
60 }
61
62 fn counter_paths(&self) -> Vec<(&'static DiagnosticPath, u32)> {
63 vec![(
64 Self::CONTACT_CONSTRAINT_COUNT,
65 self.contact_constraint_count,
66 )]
67 }
68}
69
70impl_diagnostic_paths! {
71 impl SolverDiagnostics {
72 PREPARE_CONSTRAINTS: "avian/solver/prepare_constraints",
73 UPDATE_VELOCITY_INCREMENTS: "avian/solver/update_velocity_increments",
74 INTEGRATE_VELOCITIES: "avian/solver/integrate_velocities",
75 WARM_START: "avian/solver/warm_start",
76 SOLVE_CONSTRAINTS: "avian/solver/solve_constraints",
77 INTEGRATE_POSITIONS: "avian/solver/integrate_positions",
78 RELAX_VELOCITIES: "avian/solver/relax_velocities",
79 APPLY_RESTITUTION: "avian/solver/apply_restitution",
80 FINALIZE: "avian/solver/finalize",
81 STORE_IMPULSES: "avian/solver/store_impulses",
82 SWEPT_CCD: "avian/solver/swept_ccd",
83 CONTACT_CONSTRAINT_COUNT: "avian/solver/contact_constraint_count",
84 }
85}