make seperate struct for buffer

This commit is contained in:
Simon Gardling
2021-04-01 13:56:10 -04:00
parent d887b13579
commit af0b9f9222
6 changed files with 63 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
use crate::{
grid::Grid,
util::wrap,
buffer::Buf,
};
use rand::{seq::SliceRandom, Rng};
@@ -40,9 +40,10 @@ impl Agent {
i,
}
}
// Tick an agent
#[inline]
pub fn tick(&mut self, grid: &Grid, sensor_distance: f32, sensor_angle: f32, rotation_angle: f32, step_distance: f32, width: usize, height: usize) {
pub fn tick(&mut self, buf: &Buf, sensor_distance: f32, sensor_angle: f32, rotation_angle: f32, step_distance: f32, width: usize, height: usize) {
let xc = self.x + cos(self.angle) * sensor_distance;
let yc = self.y + sin(self.angle) * sensor_distance;
@@ -55,9 +56,9 @@ impl Agent {
let yr = self.y + sin(agent_add_sens) * sensor_distance;
// We sense from the buffer because this is where we previously combined data from all the grid.
let center = grid.get_buf(xc, yc);
let left = grid.get_buf(xl, yl);
let right = grid.get_buf(xr, yr);
let center = buf.get_buf(xc, yc);
let left = buf.get_buf(xl, yl);
let right = buf.get_buf(xr, yr);
// Rotate and move logic
let mut rng = rand::thread_rng();