Skip to content

Commit

Permalink
Map scaling.
Browse files Browse the repository at this point in the history
  • Loading branch information
JackCrumpLeys committed Aug 22, 2023
1 parent a141acd commit 8e1b6b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
18 changes: 13 additions & 5 deletions crates/energy/benches/nearby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 * (<NumPoints as Into<usize>>::into(*num_entities) as f32).sqrt();
assert!(max_point_value > 0.);

let points = load_points(num_entities, max_point_value);
Expand Down Expand Up @@ -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
);
}
}

Expand Down
8 changes: 7 additions & 1 deletion crates/energy/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -130,6 +130,12 @@ pub struct NearbyUnits {
last_pos: Option<Vec2>,
}

impl NearbyUnits {
pub fn units(&self) -> TinyVec<[NearbyEntity; 256]> {
self.units.both()
}
}

fn setup(mut commands: Commands) {
commands.insert_resource(PowerGrid::default());
}
Expand Down
1 change: 1 addition & 0 deletions crates/test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8e1b6b3

Please sign in to comment.