Skip to content

Commit f3b3e81

Browse files
committed
Restore world decoder, handle air pixels properly.
1 parent 8d18843 commit f3b3e81

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed

ewext/src/modules/world_sync.rs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::modules::{Module, ModuleCtx};
22
use crate::{WorldSync, my_peer_id};
33
use eyre::{ContextCompat, eyre};
4-
use noita_api::heap;
54
use noita_api::noita::types::{CellType, FireCell, GasCell, LiquidCell, Vec2i};
65
use noita_api::noita::world::ParticleWorldState;
6+
use noita_api::{game_print, heap};
77
use rayon::iter::{IntoParallelIterator, ParallelIterator};
88
use shared::NoitaOutbound;
99
use shared::world_sync::{
@@ -110,7 +110,6 @@ impl WorldData for ParticleWorldState {
110110
Ok(())
111111
}
112112
unsafe fn decode_world(&self, chunk: NoitaWorldUpdate) -> eyre::Result<()> {
113-
return Ok(()); // TODO
114113
let chunk_coord = chunk.coord;
115114
let (cx, cy) = (chunk_coord.0 as isize, chunk_coord.1 as isize);
116115
let Some(pixel_array) = unsafe { self.world_ptr.as_mut() }
@@ -129,35 +128,39 @@ impl WorldData for ParticleWorldState {
129128
let cell = pixel_array.get_mut_raw(shift_x + x, shift_y + y);
130129
let xs = start_x + x;
131130
let ys = start_y + y;
132-
let Some(mat) = self.material_list.get_static(pixel.mat() as usize) else {
133-
return Err(eyre!("mat does not exist"));
134-
};
135-
match mat.cell_type {
136-
CellType::None => {
137-
*cell = ptr::null_mut();
138-
}
139-
CellType::Liquid => {
140-
let mut liquid = unsafe {
141-
LiquidCell::create(mat, self.cell_vtables.liquid(), self.world_ptr)
142-
};
143-
liquid.x = xs;
144-
liquid.y = ys;
145-
*cell = heap::place_new(liquid).cast();
146-
}
147-
CellType::Gas => {
148-
let mut gas =
149-
unsafe { GasCell::create(mat, self.cell_vtables.gas(), self.world_ptr) };
150-
gas.x = xs;
151-
gas.y = ys;
152-
*cell = heap::place_new(gas).cast();
153-
}
154-
CellType::Solid => {}
155-
CellType::Fire => {
156-
let mut fire =
157-
unsafe { FireCell::create(mat, self.cell_vtables.fire(), self.world_ptr) };
158-
fire.x = xs;
159-
fire.y = ys;
160-
*cell = heap::place_new(fire).cast();
131+
if pixel.is_air() {
132+
*cell = ptr::null_mut();
133+
} else {
134+
let Some(mat) = self.material_list.get_static(pixel.mat() as usize) else {
135+
return Err(eyre!("mat does not exist"));
136+
};
137+
match mat.cell_type {
138+
CellType::None => {}
139+
CellType::Liquid => {
140+
let mut liquid = unsafe {
141+
LiquidCell::create(mat, self.cell_vtables.liquid(), self.world_ptr)
142+
};
143+
liquid.x = xs;
144+
liquid.y = ys;
145+
*cell = heap::place_new(liquid).cast();
146+
}
147+
CellType::Gas => {
148+
let mut gas = unsafe {
149+
GasCell::create(mat, self.cell_vtables.gas(), self.world_ptr)
150+
};
151+
gas.x = xs;
152+
gas.y = ys;
153+
*cell = heap::place_new(gas).cast();
154+
}
155+
CellType::Solid => {}
156+
CellType::Fire => {
157+
let mut fire = unsafe {
158+
FireCell::create(mat, self.cell_vtables.fire(), self.world_ptr)
159+
};
160+
fire.x = xs;
161+
fire.y = ys;
162+
*cell = heap::place_new(fire).cast();
163+
}
161164
}
162165
}
163166
}

shared/src/world_sync.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ impl Pixel {
6262
pub fn flags(self) -> PixelFlags {
6363
unsafe { std::mem::transmute((self.0 >> 12) as u8) }
6464
}
65+
66+
pub fn is_air(&self) -> bool {
67+
self.mat() == 0
68+
}
6569
}
6670

6771
#[derive(Debug, Encode, Decode, Clone)]

0 commit comments

Comments
 (0)