Grid: inline deposit

This commit is contained in:
Simon Gardling 2025-03-28 10:22:28 -04:00
parent ff769df97b
commit e3fff76792
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -76,12 +76,6 @@ impl Grid {
crate::util::index(self.width, self.height, x, y)
}
/// Add a value to the grid data at a given position.
pub fn deposit(&mut self, x: f32, y: f32) {
let idx = self.index(x, y);
self.data[idx] += self.config.deposition_amount;
}
/// Diffuse grid data and apply a decay multiplier.
pub fn diffuse(&mut self, radius: usize) {
self.blur.run(
@ -119,9 +113,9 @@ impl Grid {
}
pub fn deposit_all(&mut self) {
let agent_list = self.agents.clone();
for agent in agent_list.iter() {
self.deposit(agent.x, agent.y);
for agent in self.agents.iter() {
let idx = self.index(agent.x, agent.y);
self.data[idx] += self.config.deposition_amount;
}
}
}