diff --git a/crates/energy/benches/nearby.rs b/crates/energy/benches/nearby.rs index 01149b87..01d03730 100644 --- a/crates/energy/benches/nearby.rs +++ b/crates/energy/benches/nearby.rs @@ -13,8 +13,8 @@ use de_test_utils::{load_points, NumPoints}; use parry3d::math::{Isometry, Vector}; use parry3d::shape::{Cuboid, TriMesh}; -const MAP_SIZE: f32 = 2000.; -const MOVEMENT_RADIUS: f32 = 100.; +const UNIT_SPACING: f32 = 7.; +const MOVEMENT_RADIUS: f32 = 40.; const SPEED: f32 = 10.; // based on MAX_H_SPEED in movement #[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] @@ -53,8 +53,8 @@ fn update_index( fn init_world_with_entities_moving(world: &mut World, num_entities: &NumPoints) { let mut index = EntityIndex::new(); - let max_point_value = MAP_SIZE - MOVEMENT_RADIUS * 2.; - + let max_point_value = + UNIT_SPACING * (>::into(*num_entities) as f32).sqrt(); assert!(max_point_value > 0.); let points = load_points(num_entities, max_point_value); @@ -149,9 +149,17 @@ fn nearby_benchmark(c: &mut Criterion) { } time.elapsed() - duration_updating_other_stuff - }) + }); }, ); + let mut amount_of_connections_formed = 0; + for connections in app.world.query::<&mut NearbyUnits>().iter(&app.world) { + amount_of_connections_formed += connections.units().len() + } + println!( + "We ended up with {} connections between {} units", + amount_of_connections_formed, number_of_units + ); } } diff --git a/crates/energy/src/graph.rs b/crates/energy/src/graph.rs index ae713e79..d3ca7f54 100644 --- a/crates/energy/src/graph.rs +++ b/crates/energy/src/graph.rs @@ -48,7 +48,7 @@ impl Plugin for GraphPlugin { /// wrapped entity to allow for default values (se we can work with TinyVec) #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -struct NearbyEntity(Entity); +pub struct NearbyEntity(Entity); impl Default for NearbyEntity { fn default() -> Self { @@ -130,6 +130,12 @@ pub struct NearbyUnits { last_pos: Option, } +impl NearbyUnits { + pub fn units(&self) -> TinyVec<[NearbyEntity; 256]> { + self.units.both() + } +} + fn setup(mut commands: Commands) { commands.insert_resource(PowerGrid::default()); } diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 2fcce0e1..9b80ece9 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -5,6 +5,7 @@ use std::path::PathBuf; use glam::Vec2; /// An enum to allow for safe selection of the number of points to load from the test data +#[derive(Copy, Clone, Debug)] pub enum NumPoints { OneHundred, OneThousand,