make types a bit nicer

This commit is contained in:
bgkillas 2025-07-23 15:18:41 -04:00
parent 6b15e58202
commit 3fdd72c363
6 changed files with 123 additions and 138 deletions

View file

@ -1,5 +1,4 @@
use crate::chunk::Chunks;
use crate::chunk::SCALE;
use crate::chunk::{CellType, ChunkPos, Pos};
use crate::{CHUNK_AMOUNT, State};
#[cfg(target_arch = "x86")]
@ -24,16 +23,14 @@ impl State {
let mean = blob.mean();
blob.update_pos()?;
let start = Pos::new(mean.0, mean.1).to_chunk();
if !unsafe { self.particle_world_state.assume_init_ref() }
.exists::<SCALE>(start.x, start.y)
|| self
.world
.read(
unsafe { self.particle_world_state.assume_init_ref() },
self.blob_guy,
start,
)
.is_err()
if self
.world
.read(
unsafe { self.particle_world_state.assume_init_ref() },
self.blob_guy,
start,
)
.is_err()
{
blob.update(start, &mut self.world, mean, false)?;
continue 'upper;

View file

@ -154,7 +154,6 @@ impl ChunkOps for ParticleWorldState {
let Some(pixel_array) = unsafe { self.world_ptr.as_mut() }
.wrap_err("no world")?
.chunk_map
.chunk_array
.get(x >> SCALE, y >> SCALE)
else {
return Err(eyre!("chunk not loaded"));
@ -164,7 +163,7 @@ impl ChunkOps for ParticleWorldState {
.flat_map(|i| (0..CHUNK_SIZE as isize).map(move |j| (i, j)))
.zip(chunk.iter_mut())
{
*pixel = if let Some(cell) = pixel_array.data.get(shift_x + i, shift_y + j) {
*pixel = if let Some(cell) = pixel_array.get(shift_x + i, shift_y + j) {
match cell.material.cell_type {
types::CellType::Liquid => {
if cell.material.material_type as u16 == blob {
@ -206,7 +205,6 @@ impl ChunkOps for ParticleWorldState {
let Some(pixel_array) = unsafe { self.world_ptr.as_mut() }
.wrap_err("no world")?
.chunk_map
.chunk_array
.get_mut(cx >> SCALE, cy >> SCALE)
else {
return Err(eyre!("chunk not loaded"));
@ -229,17 +227,15 @@ impl ChunkOps for ParticleWorldState {
CellType::Blob => {
let world_x = x + i;
let world_y = y + j;
if let Some(cell) = pixel_array.data.get_mut(shift_x + i, shift_y + j) {
let new = Box::leak(blob_cell.clone());
new.x = world_x;
new.y = world_y;
cell.0 = (new as *mut types::LiquidCell).cast();
}
let cell = pixel_array.get_mut_raw(shift_x + i, shift_y + j);
let new = Box::leak(blob_cell.clone());
new.x = world_x;
new.y = world_y;
*cell = (new as *mut types::LiquidCell).cast();
}
CellType::Remove => {
if let Some(cell) = pixel_array.data.get_mut(shift_x + i, shift_y + j) {
cell.0 = std::ptr::null_mut()
}
let cell = pixel_array.get_mut_raw(shift_x + i, shift_y + j);
*cell = std::ptr::null_mut();
}
_ => {}
}