Skip to main content

boxddd/types/
stats.rs

1//! Runtime capacity, profiling, counter, and version snapshots.
2
3use super::*;
4
5/// Native world capacity snapshot.
6#[repr(C)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
9pub struct Capacity {
10    /// Static shape capacity.
11    pub static_shape_count: i32,
12    /// Dynamic shape capacity.
13    pub dynamic_shape_count: i32,
14    /// Static body capacity.
15    pub static_body_count: i32,
16    /// Dynamic body capacity.
17    pub dynamic_body_count: i32,
18    /// Contact capacity.
19    pub contact_count: i32,
20}
21
22impl Capacity {
23    /// Converts a raw Box3D capacity snapshot into the Rust value type.
24    #[inline]
25    pub const fn from_raw(raw: ffi::b3Capacity) -> Self {
26        Self {
27            static_shape_count: raw.staticShapeCount,
28            dynamic_shape_count: raw.dynamicShapeCount,
29            static_body_count: raw.staticBodyCount,
30            dynamic_body_count: raw.dynamicBodyCount,
31            contact_count: raw.contactCount,
32        }
33    }
34
35    /// Converts this value into the raw Box3D representation.
36    #[inline]
37    pub const fn into_raw(self) -> ffi::b3Capacity {
38        ffi::b3Capacity {
39            staticShapeCount: self.static_shape_count,
40            dynamicShapeCount: self.dynamic_shape_count,
41            staticBodyCount: self.static_body_count,
42            dynamicBodyCount: self.dynamic_body_count,
43            contactCount: self.contact_count,
44        }
45    }
46}
47
48/// Per-step timing profile reported by Box3D.
49#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
50#[derive(Copy, Clone, Debug, Default, PartialEq)]
51pub struct Profile {
52    /// Total step time.
53    pub step: f32,
54    /// Broad-phase pair update time.
55    pub pairs: f32,
56    /// Collision detection time.
57    pub collide: f32,
58    /// Solver time.
59    pub solve: f32,
60    /// Solver setup time.
61    pub solver_setup: f32,
62    /// Constraint solve time.
63    pub constraints: f32,
64    /// Constraint preparation time.
65    pub prepare_constraints: f32,
66    /// Velocity integration time.
67    pub integrate_velocities: f32,
68    /// Warm-start time.
69    pub warm_start: f32,
70    /// Impulse solve time.
71    pub solve_impulses: f32,
72    /// Position integration time.
73    pub integrate_positions: f32,
74    /// Impulse relaxation time.
75    pub relax_impulses: f32,
76    /// Restitution application time.
77    pub apply_restitution: f32,
78    /// Impulse storage time.
79    pub store_impulses: f32,
80    /// Island splitting time.
81    pub split_islands: f32,
82    /// Transform update time.
83    pub transforms: f32,
84    /// Sensor hit processing time.
85    pub sensor_hits: f32,
86    /// Joint event processing time.
87    pub joint_events: f32,
88    /// Hit event processing time.
89    pub hit_events: f32,
90    /// Broad-phase refit time.
91    pub refit: f32,
92    /// Bullet/continuous collision time.
93    pub bullets: f32,
94    /// Sleep island processing time.
95    pub sleep_islands: f32,
96    /// Sensor processing time.
97    pub sensors: f32,
98}
99
100impl Profile {
101    /// Converts a raw Box3D profile into the Rust value type.
102    #[inline]
103    pub const fn from_raw(raw: ffi::b3Profile) -> Self {
104        Self {
105            step: raw.step,
106            pairs: raw.pairs,
107            collide: raw.collide,
108            solve: raw.solve,
109            solver_setup: raw.solverSetup,
110            constraints: raw.constraints,
111            prepare_constraints: raw.prepareConstraints,
112            integrate_velocities: raw.integrateVelocities,
113            warm_start: raw.warmStart,
114            solve_impulses: raw.solveImpulses,
115            integrate_positions: raw.integratePositions,
116            relax_impulses: raw.relaxImpulses,
117            apply_restitution: raw.applyRestitution,
118            store_impulses: raw.storeImpulses,
119            split_islands: raw.splitIslands,
120            transforms: raw.transforms,
121            sensor_hits: raw.sensorHits,
122            joint_events: raw.jointEvents,
123            hit_events: raw.hitEvents,
124            refit: raw.refit,
125            bullets: raw.bullets,
126            sleep_islands: raw.sleepIslands,
127            sensors: raw.sensors,
128        }
129    }
130}
131
132/// World counters reported by Box3D for diagnostics and tests.
133#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
134#[derive(Copy, Clone, Debug, PartialEq, Eq)]
135pub struct Counters {
136    /// Number of live bodies.
137    pub body_count: i32,
138    /// Number of live shapes.
139    pub shape_count: i32,
140    /// Number of live contacts.
141    pub contact_count: i32,
142    /// Number of live joints.
143    pub joint_count: i32,
144    /// Number of solver islands.
145    pub island_count: i32,
146    /// Stack memory used by Box3D.
147    pub stack_used: i32,
148    /// Arena memory capacity.
149    pub arena_capacity: i32,
150    /// Static broad-phase tree height.
151    pub static_tree_height: i32,
152    /// Dynamic broad-phase tree height.
153    pub tree_height: i32,
154    /// Number of separating-axis test calls.
155    pub sat_call_count: i32,
156    /// Number of separating-axis cache hits.
157    pub sat_cache_hit_count: i32,
158    /// Native byte count reported by Box3D.
159    pub byte_count: i32,
160    /// Number of native tasks scheduled by the last step.
161    pub task_count: i32,
162    /// Solver graph color distribution.
163    pub color_counts: [i32; 24],
164    /// Contact manifold point-count distribution.
165    pub manifold_counts: [i32; 8],
166    /// Number of awake contacts.
167    pub awake_contact_count: i32,
168    /// Number of recycled contacts.
169    pub recycled_contact_count: i32,
170    /// Distance solver iteration count.
171    pub distance_iterations: i32,
172    /// Push-back solver iteration count.
173    pub push_back_iterations: i32,
174    /// Root solver iteration count.
175    pub root_iterations: i32,
176}
177
178impl Counters {
179    /// Converts raw Box3D counters into the Rust value type.
180    #[inline]
181    pub const fn from_raw(raw: ffi::b3Counters) -> Self {
182        Self {
183            body_count: raw.bodyCount,
184            shape_count: raw.shapeCount,
185            contact_count: raw.contactCount,
186            joint_count: raw.jointCount,
187            island_count: raw.islandCount,
188            stack_used: raw.stackUsed,
189            arena_capacity: raw.arenaCapacity,
190            static_tree_height: raw.staticTreeHeight,
191            tree_height: raw.treeHeight,
192            sat_call_count: raw.satCallCount,
193            sat_cache_hit_count: raw.satCacheHitCount,
194            byte_count: raw.byteCount,
195            task_count: raw.taskCount,
196            color_counts: raw.colorCounts,
197            manifold_counts: raw.manifoldCounts,
198            awake_contact_count: raw.awakeContactCount,
199            recycled_contact_count: raw.recycledContactCount,
200            distance_iterations: raw.distanceIterations,
201            push_back_iterations: raw.pushBackIterations,
202            root_iterations: raw.rootIterations,
203        }
204    }
205}
206
207impl Default for Counters {
208    fn default() -> Self {
209        Self {
210            body_count: 0,
211            shape_count: 0,
212            contact_count: 0,
213            joint_count: 0,
214            island_count: 0,
215            stack_used: 0,
216            arena_capacity: 0,
217            static_tree_height: 0,
218            tree_height: 0,
219            sat_call_count: 0,
220            sat_cache_hit_count: 0,
221            byte_count: 0,
222            task_count: 0,
223            color_counts: [0; 24],
224            manifold_counts: [0; 8],
225            awake_contact_count: 0,
226            recycled_contact_count: 0,
227            distance_iterations: 0,
228            push_back_iterations: 0,
229            root_iterations: 0,
230        }
231    }
232}
233
234/// Box3D version number.
235#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
236#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
237pub struct Version {
238    /// Major version.
239    pub major: i32,
240    /// Minor version.
241    pub minor: i32,
242    /// Revision or patch version.
243    pub revision: i32,
244}
245
246impl Version {
247    /// Converts a raw Box3D version into the Rust value type.
248    #[inline]
249    pub const fn from_raw(raw: ffi::b3Version) -> Self {
250        Self {
251            major: raw.major,
252            minor: raw.minor,
253            revision: raw.revision,
254        }
255    }
256}