Restore world decoder, handle air pixels properly.

This commit is contained in:
IQuant 2025-10-12 17:12:39 +03:00
parent 8d18843147
commit f3b3e81c01
2 changed files with 38 additions and 31 deletions

View file

@ -1,9 +1,9 @@
use crate::modules::{Module, ModuleCtx}; use crate::modules::{Module, ModuleCtx};
use crate::{WorldSync, my_peer_id}; use crate::{WorldSync, my_peer_id};
use eyre::{ContextCompat, eyre}; use eyre::{ContextCompat, eyre};
use noita_api::heap;
use noita_api::noita::types::{CellType, FireCell, GasCell, LiquidCell, Vec2i}; use noita_api::noita::types::{CellType, FireCell, GasCell, LiquidCell, Vec2i};
use noita_api::noita::world::ParticleWorldState; use noita_api::noita::world::ParticleWorldState;
use noita_api::{game_print, heap};
use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rayon::iter::{IntoParallelIterator, ParallelIterator};
use shared::NoitaOutbound; use shared::NoitaOutbound;
use shared::world_sync::{ use shared::world_sync::{
@ -110,7 +110,6 @@ impl WorldData for ParticleWorldState {
Ok(()) Ok(())
} }
unsafe fn decode_world(&self, chunk: NoitaWorldUpdate) -> eyre::Result<()> { unsafe fn decode_world(&self, chunk: NoitaWorldUpdate) -> eyre::Result<()> {
return Ok(()); // TODO
let chunk_coord = chunk.coord; let chunk_coord = chunk.coord;
let (cx, cy) = (chunk_coord.0 as isize, chunk_coord.1 as isize); let (cx, cy) = (chunk_coord.0 as isize, chunk_coord.1 as isize);
let Some(pixel_array) = unsafe { self.world_ptr.as_mut() } let Some(pixel_array) = unsafe { self.world_ptr.as_mut() }
@ -129,35 +128,39 @@ impl WorldData for ParticleWorldState {
let cell = pixel_array.get_mut_raw(shift_x + x, shift_y + y); let cell = pixel_array.get_mut_raw(shift_x + x, shift_y + y);
let xs = start_x + x; let xs = start_x + x;
let ys = start_y + y; let ys = start_y + y;
let Some(mat) = self.material_list.get_static(pixel.mat() as usize) else { if pixel.is_air() {
return Err(eyre!("mat does not exist")); *cell = ptr::null_mut();
}; } else {
match mat.cell_type { let Some(mat) = self.material_list.get_static(pixel.mat() as usize) else {
CellType::None => { return Err(eyre!("mat does not exist"));
*cell = ptr::null_mut(); };
} match mat.cell_type {
CellType::Liquid => { CellType::None => {}
let mut liquid = unsafe { CellType::Liquid => {
LiquidCell::create(mat, self.cell_vtables.liquid(), self.world_ptr) let mut liquid = unsafe {
}; LiquidCell::create(mat, self.cell_vtables.liquid(), self.world_ptr)
liquid.x = xs; };
liquid.y = ys; liquid.x = xs;
*cell = heap::place_new(liquid).cast(); liquid.y = ys;
} *cell = heap::place_new(liquid).cast();
CellType::Gas => { }
let mut gas = CellType::Gas => {
unsafe { GasCell::create(mat, self.cell_vtables.gas(), self.world_ptr) }; let mut gas = unsafe {
gas.x = xs; GasCell::create(mat, self.cell_vtables.gas(), self.world_ptr)
gas.y = ys; };
*cell = heap::place_new(gas).cast(); gas.x = xs;
} gas.y = ys;
CellType::Solid => {} *cell = heap::place_new(gas).cast();
CellType::Fire => { }
let mut fire = CellType::Solid => {}
unsafe { FireCell::create(mat, self.cell_vtables.fire(), self.world_ptr) }; CellType::Fire => {
fire.x = xs; let mut fire = unsafe {
fire.y = ys; FireCell::create(mat, self.cell_vtables.fire(), self.world_ptr)
*cell = heap::place_new(fire).cast(); };
fire.x = xs;
fire.y = ys;
*cell = heap::place_new(fire).cast();
}
} }
} }
} }

View file

@ -62,6 +62,10 @@ impl Pixel {
pub fn flags(self) -> PixelFlags { pub fn flags(self) -> PixelFlags {
unsafe { std::mem::transmute((self.0 >> 12) as u8) } unsafe { std::mem::transmute((self.0 >> 12) as u8) }
} }
pub fn is_air(&self) -> bool {
self.mat() == 0
}
} }
#[derive(Debug, Encode, Decode, Clone)] #[derive(Debug, Encode, Decode, Clone)]