store agents in grids, not model

This commit is contained in:
Simon Gardling
2021-04-01 09:28:43 -04:00
parent 4e688c3fa7
commit 953c540263
3 changed files with 90 additions and 71 deletions

View File

@@ -1,4 +1,7 @@
use crate::blur::Blur;
use crate::{
blur::Blur,
model::Agent,
};
use rand::{distributions::Uniform, Rng};
@@ -88,6 +91,7 @@ pub struct Grid {
// Scratch space for the blur operation.
buf: Vec<f32>,
blur: Blur,
pub agents: Vec<Agent>
}
impl Clone for Grid {
@@ -99,13 +103,14 @@ impl Clone for Grid {
data: self.data.clone(),
buf: self.buf.clone(),
blur: self.blur.clone(),
agents: self.agents.clone(),
}
}
}
impl Grid {
// Create a new grid filled with random floats in the [0.0..1.0) range.
pub fn new<R: Rng + ?Sized>(width: usize, height: usize, rng: &mut R) -> Self {
pub fn new<R: Rng + ?Sized>(width: usize, height: usize, rng: &mut R, agents: Vec<Agent>) -> Self {
if !width.is_power_of_two() || !height.is_power_of_two() {
panic!("Grid dimensions must be a power of two.");
}
@@ -119,6 +124,7 @@ impl Grid {
config: PopulationConfig::new(rng),
buf: vec![0.0; width * height],
blur: Blur::new(width),
agents,
}
}