Skip to main content

goud_engine/ecs/broad_phase/
stats.rs

1//! Statistics types for spatial hash performance analysis.
2
3/// Statistics for spatial hash performance analysis.
4#[derive(Clone, Debug, Default)]
5pub struct SpatialHashStats {
6    /// Total number of entities in the hash.
7    pub entity_count: usize,
8
9    /// Number of occupied cells.
10    pub cell_count: usize,
11
12    /// Total number of entity-cell mappings.
13    pub total_cell_entries: usize,
14
15    /// Maximum entities in a single cell.
16    pub max_entities_per_cell: usize,
17
18    /// Average entities per occupied cell.
19    pub avg_entities_per_cell: f32,
20
21    /// Number of potential collision pairs found in last query.
22    pub last_query_pairs: usize,
23}
24
25impl std::fmt::Display for SpatialHashStats {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(
28            f,
29            "SpatialHash Stats:\n\
30             - Entities: {}\n\
31             - Cells: {}\n\
32             - Total entries: {}\n\
33             - Max per cell: {}\n\
34             - Avg per cell: {:.2}\n\
35             - Last query pairs: {}",
36            self.entity_count,
37            self.cell_count,
38            self.total_cell_entries,
39            self.max_entities_per_cell,
40            self.avg_entities_per_cell,
41            self.last_query_pairs
42        )
43    }
44}