mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Restore world decoder, handle air pixels properly.
This commit is contained in:
parent
8d18843147
commit
f3b3e81c01
2 changed files with 38 additions and 31 deletions
|
@ -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,13 +128,14 @@ 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;
|
||||||
|
if pixel.is_air() {
|
||||||
|
*cell = ptr::null_mut();
|
||||||
|
} else {
|
||||||
let Some(mat) = self.material_list.get_static(pixel.mat() as usize) else {
|
let Some(mat) = self.material_list.get_static(pixel.mat() as usize) else {
|
||||||
return Err(eyre!("mat does not exist"));
|
return Err(eyre!("mat does not exist"));
|
||||||
};
|
};
|
||||||
match mat.cell_type {
|
match mat.cell_type {
|
||||||
CellType::None => {
|
CellType::None => {}
|
||||||
*cell = ptr::null_mut();
|
|
||||||
}
|
|
||||||
CellType::Liquid => {
|
CellType::Liquid => {
|
||||||
let mut liquid = unsafe {
|
let mut liquid = unsafe {
|
||||||
LiquidCell::create(mat, self.cell_vtables.liquid(), self.world_ptr)
|
LiquidCell::create(mat, self.cell_vtables.liquid(), self.world_ptr)
|
||||||
|
@ -145,22 +145,25 @@ impl WorldData for ParticleWorldState {
|
||||||
*cell = heap::place_new(liquid).cast();
|
*cell = heap::place_new(liquid).cast();
|
||||||
}
|
}
|
||||||
CellType::Gas => {
|
CellType::Gas => {
|
||||||
let mut gas =
|
let mut gas = unsafe {
|
||||||
unsafe { GasCell::create(mat, self.cell_vtables.gas(), self.world_ptr) };
|
GasCell::create(mat, self.cell_vtables.gas(), self.world_ptr)
|
||||||
|
};
|
||||||
gas.x = xs;
|
gas.x = xs;
|
||||||
gas.y = ys;
|
gas.y = ys;
|
||||||
*cell = heap::place_new(gas).cast();
|
*cell = heap::place_new(gas).cast();
|
||||||
}
|
}
|
||||||
CellType::Solid => {}
|
CellType::Solid => {}
|
||||||
CellType::Fire => {
|
CellType::Fire => {
|
||||||
let mut fire =
|
let mut fire = unsafe {
|
||||||
unsafe { FireCell::create(mat, self.cell_vtables.fire(), self.world_ptr) };
|
FireCell::create(mat, self.cell_vtables.fire(), self.world_ptr)
|
||||||
|
};
|
||||||
fire.x = xs;
|
fire.x = xs;
|
||||||
fire.y = ys;
|
fire.y = ys;
|
||||||
*cell = heap::place_new(fire).cast();
|
*cell = heap::place_new(fire).cast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue