par_iter for update_vel
This commit is contained in:
parent
3d7663e032
commit
1d6d1ccf10
1 changed files with 65 additions and 65 deletions
|
|
@ -10,18 +10,16 @@ use super::{
|
|||
};
|
||||
|
||||
// toid stuff
|
||||
const SPEED: f32 = 6.0;
|
||||
const SPEED_DIFF_RANGE: f32 = 0.2; // +/- 10%
|
||||
const MAX_DELTA_V: f32 = std::f32::consts::PI * 1.5; // basically 360
|
||||
// degrees/sec
|
||||
|
||||
const SPEED: f32 = 12.0;
|
||||
const SPEED_DIFF_RANGE: f32 = 0.1;
|
||||
const MAX_DELTA_V: f32 = std::f32::consts::PI * 2.0;
|
||||
// how far from origin before really wanting to come back
|
||||
const RADIUS: f32 = 40.0;
|
||||
const RADIUS: f32 = 30.0;
|
||||
|
||||
// how close to try to stay to your buddies
|
||||
const BUDDY_RADIUS: f32 = 10.0;
|
||||
const BUDDY_RADIUS: f32 = SPEED;
|
||||
|
||||
const MIN_ALTITUDE: f32 = 3.5;
|
||||
const MIN_ALTITUDE: f32 = 13.5;
|
||||
|
||||
pub fn setup_channels(mut commands: Commands) {
|
||||
let (raw_tx, raw_rx) = bounded(1);
|
||||
|
|
@ -153,7 +151,9 @@ pub fn update_vel(
|
|||
) {
|
||||
let dt = time.delta_secs();
|
||||
let max_delta = MAX_DELTA_V * dt;
|
||||
for (xform, mut vel, toid, buddies, entity) in toids.iter_mut() {
|
||||
toids
|
||||
.par_iter_mut()
|
||||
.for_each(|(xform, mut vel, toid, buddies, entity)| {
|
||||
let speed = toid.speed;
|
||||
let mut dir = vel.normalize();
|
||||
let pos = xform.translation;
|
||||
|
|
@ -174,7 +174,7 @@ pub fn update_vel(
|
|||
let min_dist = speed;
|
||||
for neighbor in index
|
||||
.index
|
||||
.locate_within_distance(pos.to_array(), min_dist)
|
||||
.locate_within_distance(pos.to_array(), min_dist * 10.0)
|
||||
.filter(|n| n.data != entity)
|
||||
{
|
||||
let bp = Vec3::from_array(*neighbor.geom());
|
||||
|
|
@ -215,7 +215,7 @@ pub fn update_vel(
|
|||
}
|
||||
|
||||
**vel = dir * speed;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn update_pos(
|
||||
|
|
|
|||
Loading…
Reference in a new issue