feat: redone visualization to be human-generated

This commit is contained in:
Rendo 2026-08-01 23:44:56 +05:00
commit 5b4ad9a47a
9 changed files with 214 additions and 24 deletions

View file

@ -10,7 +10,9 @@ impl<'a> GridManipulationTools<'a> {
Self { grid }
}
pub fn set_xyz(&mut self,x: u32, y: u32, z: u32, element: GridElement) {
let index = self.grid.indexify(UVec3::new(x,y,z));
let Some(index) = self.grid.indexify(UVec3::new(x,y,z)) else {
return;
};
self.grid.data[index] = element;
}
pub fn fill_xyz(&mut self,x1: u32, y1: u32, z1: u32, x2: u32, y2: u32, z2: u32, element: GridElement) {
@ -21,7 +23,9 @@ impl<'a> GridManipulationTools<'a> {
for x in x1..=x2 {
for y in y1..=y2 {
for z in z1..=z2 {
let index = self.grid.indexify(UVec3::new(x,y,z));
let Some(index) = self.grid.indexify(UVec3::new(x,y,z)) else {
continue;
};
self.grid.data[index] = element.clone();
}

View file

@ -26,21 +26,26 @@ impl Grid {
data
}
}
pub fn indexify(&self, vector: UVec3) -> usize{
let clamped_vector = vector.min(self.size - UVec3::ONE);
return (clamped_vector.x + self.size.x * clamped_vector.y + self.size.x * self.size.y * clamped_vector.z) as usize;
pub fn cell_amount(&self) -> u32 {
return self.size.x * self.size.y * self.size.z;
}
pub fn deindexify(&self, index: usize) -> UVec3 {
let undex = index as u32;
pub fn indexify(&self, vector: UVec3) -> Option<usize>{
if vector.x >= self.size.x || vector.y >= self.size.y || vector.z >= self.size.z {
return None;
}
return Some((vector.x + self.size.x * vector.y + self.size.x * self.size.y * vector.z) as usize);
}
pub fn deindexify(&self, index: u32) -> UVec3 {
return UVec3::new(
undex % self.size.x,
undex / self.size.x % self.size.y,
undex / (self.size.x*self.size.y)
index % self.size.x,
index / self.size.x % self.size.y,
index / (self.size.x*self.size.y)
);
}
pub fn tranfer_fluid(&mut self,from: usize, to: usize, transfer_amount: u32) {
let bounds = self.indexify(self.size);
let bounds = self.cell_amount() as usize;
if from >= bounds || to >= bounds {
error!("Trying to transfer fluid out of bounds!");
return;
}