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
|
// toid stuff
|
||||||
const SPEED: f32 = 6.0;
|
const SPEED: f32 = 12.0;
|
||||||
const SPEED_DIFF_RANGE: f32 = 0.2; // +/- 10%
|
const SPEED_DIFF_RANGE: f32 = 0.1;
|
||||||
const MAX_DELTA_V: f32 = std::f32::consts::PI * 1.5; // basically 360
|
const MAX_DELTA_V: f32 = std::f32::consts::PI * 2.0;
|
||||||
// degrees/sec
|
|
||||||
|
|
||||||
// how far from origin before really wanting to come back
|
// 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
|
// 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) {
|
pub fn setup_channels(mut commands: Commands) {
|
||||||
let (raw_tx, raw_rx) = bounded(1);
|
let (raw_tx, raw_rx) = bounded(1);
|
||||||
|
|
@ -153,7 +151,9 @@ pub fn update_vel(
|
||||||
) {
|
) {
|
||||||
let dt = time.delta_secs();
|
let dt = time.delta_secs();
|
||||||
let max_delta = MAX_DELTA_V * dt;
|
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 speed = toid.speed;
|
||||||
let mut dir = vel.normalize();
|
let mut dir = vel.normalize();
|
||||||
let pos = xform.translation;
|
let pos = xform.translation;
|
||||||
|
|
@ -174,7 +174,7 @@ pub fn update_vel(
|
||||||
let min_dist = speed;
|
let min_dist = speed;
|
||||||
for neighbor in index
|
for neighbor in index
|
||||||
.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)
|
.filter(|n| n.data != entity)
|
||||||
{
|
{
|
||||||
let bp = Vec3::from_array(*neighbor.geom());
|
let bp = Vec3::from_array(*neighbor.geom());
|
||||||
|
|
@ -215,7 +215,7 @@ pub fn update_vel(
|
||||||
}
|
}
|
||||||
|
|
||||||
**vel = dir * speed;
|
**vel = dir * speed;
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_pos(
|
pub fn update_pos(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue