Compare commits

..

No commits in common. "7eba1d88fe922141126a5288fcba37894e3ba0cb" and "92805832f298616ddefb915b6a013ede19673073" have entirely different histories.

1 changed files with 4 additions and 30 deletions

View File

@ -3,7 +3,7 @@
mod boid_mesh;
mod boundary;
use bevy::{color::palettes::tailwind, prelude::*, reflect::List, sprite::MaterialMesh2dBundle};
use bevy::{color::palettes::tailwind, prelude::*, sprite::MaterialMesh2dBundle};
use boid_mesh::BoidMesh;
use rand::{Rng, SeedableRng};
@ -16,7 +16,7 @@ fn main() {
Update,
(
(seperation, cohesion, alignment),
(accelerate, move_boids).chain(),
move_boids,
boundary::boid_border_teleport,
)
.chain(),
@ -54,37 +54,11 @@ struct BoidBundle {
cache: BoidAccelerationBundle,
}
#[derive(Component, Default)]
struct LocalCache(Vec<Entity>);
fn is_local(a: Vec3, b: Vec3) -> bool {
const LOCAL_DISTANCE: f32 = 100.;
a.distance(b) < LOCAL_DISTANCE
}
fn build_local_cache(
mut boids_with_cache: Query<(Entity, &Transform, &mut LocalCache), With<Boid>>,
other_boids: Query<(Entity, &Transform), With<Boid>>,
) {
boids_with_cache
.par_iter_mut()
.for_each(|(id, transform, mut local_cache)| {
local_cache.0.clear();
for (other_id, other_transform) in other_boids.iter() {
if id != other_id && is_local(transform.translation, other_transform.translation) {
local_cache.0.push(other_id);
}
}
});
}
fn seperation(mut boids: Query<(Entity, &Transform, &mut SeperationAcceleration), With<Boid>>) {}
fn cohesion(mut boids: Query<(Entity, &Transform, &mut CohesionAcceleration), With<Boid>>) {}
fn cohesion(mut boids: Query<(Entity, &Transform, &mut SeperationAcceleration), With<Boid>>) {}
fn alignment(mut boids: Query<(Entity, &Transform, &mut AlignmentAcceleration), With<Boid>>) {}
fn alignment(mut boids: Query<(Entity, &Transform, &mut SeperationAcceleration), With<Boid>>) {}
fn accelerate(
mut boids: Query<