mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
some more world sync work
This commit is contained in:
parent
38f8fe4c59
commit
720b9e2396
3 changed files with 32 additions and 24 deletions
|
@ -23,13 +23,14 @@ impl Module for WorldSync {
|
|||
return Ok(());
|
||||
};
|
||||
let (x, y) = (ent.transform.pos.x, ent.transform.pos.y);
|
||||
let updates = (0..9)
|
||||
.into_par_iter()
|
||||
let tmr = std::time::Instant::now();
|
||||
let updates = (0..1)
|
||||
//.into_par_iter()
|
||||
.map(|i| {
|
||||
let dx = i % 3;
|
||||
let dy = i / 3;
|
||||
let cx = x as i32 / CHUNK_SIZE as i32 - 1 + dx;
|
||||
let cy = y as i32 / CHUNK_SIZE as i32 - 1 + dy;
|
||||
let cx = x as i32 / CHUNK_SIZE as i32 + dx;
|
||||
let cy = y as i32 / CHUNK_SIZE as i32 + dy;
|
||||
let mut update = NoitaWorldUpdate {
|
||||
coord: ChunkCoord(cx, cy),
|
||||
pixels: std::array::from_fn(|_| None),
|
||||
|
@ -49,6 +50,16 @@ impl Module for WorldSync {
|
|||
.collect::<Vec<_>>();
|
||||
let msg = NoitaOutbound::WorldSyncToProxy(WorldSyncToProxy::Updates(updates));
|
||||
ctx.net.send(&msg)?;
|
||||
let NoitaOutbound::WorldSyncToProxy(WorldSyncToProxy::Updates(updates)) = msg else {
|
||||
unreachable!()
|
||||
};
|
||||
updates.into_iter().flatten().for_each(|chunk| unsafe {
|
||||
let _ = self
|
||||
.particle_world_state
|
||||
.assume_init_ref()
|
||||
.decode_world(chunk);
|
||||
});
|
||||
noita_api::game_print!("{}", tmr.elapsed().as_nanos());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -123,10 +134,9 @@ impl WorldData for ParticleWorldState {
|
|||
*cell = ptr::null_mut();
|
||||
continue;
|
||||
};
|
||||
let mat = self
|
||||
.material_list
|
||||
.get_static(pixel.material() as usize)
|
||||
.unwrap();
|
||||
let Some(mat) = self.material_list.get_static(pixel.material() as usize) else {
|
||||
return Err(eyre!("mat does not exist"));
|
||||
};
|
||||
match mat.cell_type {
|
||||
CellType::None => {
|
||||
*cell = ptr::null_mut();
|
||||
|
@ -160,4 +170,4 @@ impl WorldData for ParticleWorldState {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -677,19 +677,17 @@ impl Chunk {
|
|||
#[inline]
|
||||
pub fn get_compact_pixel(&self, x: isize, y: isize) -> Option<CompactPixel> {
|
||||
self.get(x, y).map(|cell| {
|
||||
let mat = (cell.material.material_type as u16 + 1) << 1;
|
||||
CompactPixel(if cell.material.cell_type == CellType::Liquid {
|
||||
(cell.material.material_type as u16
|
||||
| if cell.get_liquid().is_static == cell.material.liquid_static {
|
||||
PixelFlags::Normal
|
||||
} else {
|
||||
PixelFlags::Abnormal
|
||||
} as u16)
|
||||
(mat | if cell.get_liquid().is_static == cell.material.liquid_static {
|
||||
PixelFlags::Normal
|
||||
} else {
|
||||
PixelFlags::Abnormal
|
||||
} as u16)
|
||||
.try_into()
|
||||
.unwrap()
|
||||
} else {
|
||||
(cell.material.material_type as u16 | PixelFlags::Normal as u16)
|
||||
.try_into()
|
||||
.unwrap()
|
||||
(mat | PixelFlags::Normal as u16).try_into().unwrap()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ pub enum PixelFlags {
|
|||
Abnormal = 16384,
|
||||
}
|
||||
|
||||
const BITS: u16 = 8191;
|
||||
|
||||
#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, Copy)]
|
||||
pub struct RawPixel {
|
||||
pub material: u16,
|
||||
|
@ -41,7 +43,7 @@ impl RawPixel {
|
|||
} else {
|
||||
1
|
||||
};
|
||||
let material = (self.material + 1) & 2047; // 11 bits for material
|
||||
let material = self.material & BITS; // 11 bits for material
|
||||
let raw = if self.flags == PixelFlags::Unknown {
|
||||
CompactPixel::UNKNOWN_RAW
|
||||
} else {
|
||||
|
@ -80,7 +82,7 @@ impl RawPixel {
|
|||
pub struct CompactPixel(pub NonZeroU16);
|
||||
|
||||
impl CompactPixel {
|
||||
const UNKNOWN_RAW: u16 = 4095;
|
||||
const UNKNOWN_RAW: u16 = BITS + 1;
|
||||
pub fn from_raw(val: u16) -> Self {
|
||||
CompactPixel(NonZeroU16::new(val).unwrap())
|
||||
}
|
||||
|
@ -88,8 +90,6 @@ impl CompactPixel {
|
|||
if val == 0 {
|
||||
None
|
||||
} else {
|
||||
let val = (val + 1) & 2047;
|
||||
let val = val << 1;
|
||||
Some(CompactPixel(NonZeroU16::new(val).unwrap()))
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ impl CompactPixel {
|
|||
u16::from(self.0)
|
||||
}
|
||||
pub fn material(self) -> u16 {
|
||||
(self.raw() >> 1) - 1
|
||||
self.raw() & BITS
|
||||
}
|
||||
pub fn flags(self) -> PixelFlags {
|
||||
if self.raw() & 1 == 1 {
|
||||
|
@ -122,4 +122,4 @@ pub enum WorldSyncToProxy {
|
|||
#[derive(Debug, Encode, Decode, Clone)]
|
||||
pub enum ProxyToWorldSync {
|
||||
Updates(Vec<NoitaWorldUpdate>),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue