Disable multithreading in world sync for now, also other stuff

This commit is contained in:
IQuant 2025-11-15 13:36:48 +03:00
parent 3bff16fc89
commit 2d6f7fe047
5 changed files with 24 additions and 22 deletions

View file

@ -43,7 +43,7 @@ impl Chunks {
start: ChunkPos,
) -> eyre::Result<()> {
self.0
.par_iter_mut()
.iter_mut()
.enumerate()
.try_for_each(|(i, chunk)| unsafe {
let x = i as isize / CHUNK_AMOUNT as isize + start.x;
@ -166,16 +166,16 @@ impl ChunkOps for ParticleWorldState {
.zip(chunk.iter_mut())
{
*pixel = if let Some(cell) = pixel_array.get(shift_x + i, shift_y + j) {
match cell.material.unwrap().cell_type {
match cell.material.cell_type {
types::CellType::Liquid => {
if cell.material.unwrap().material_type as u16 == blob {
if cell.material.material_type as u16 == blob {
modified = true;
CellType::Remove
} else {
let lcell = cell.get_liquid();
if lcell.is_static {
CellType::Solid
} else if cell.material.unwrap().liquid_sand {
} else if cell.material.liquid_sand {
CellType::Sand
} else {
CellType::Liquid

View file

@ -9,6 +9,12 @@ crate-type = ["cdylib"]
[profile.dev]
panic = "abort"
[profile.dev.package.bitcode]
opt-level = 3
[profile.dev.package.shared]
opt-level = 3
[profile.release]
lto = true
#strip = true # Not having that causes wine debugger to crash.

View file

@ -43,7 +43,7 @@ impl Module for WorldSync {
}
let updates = (0..9)
.into_par_iter()
.into_iter()
.filter_map(|i| {
let dx = i % 3;
let dy = i / 3;
@ -89,7 +89,7 @@ impl WorldSync {
match msg {
ProxyToWorldSync::Updates(updates) => {
// TODO should check that updates don't touch the same chunk
updates.into_par_iter().for_each(|chunk| unsafe {
updates.into_iter().for_each(|chunk| unsafe {
let _ = self
.particle_world_state
.assume_init_ref()
@ -150,11 +150,11 @@ impl WorldData for ParticleWorldState {
if !cell.is_null() {
let cell = unsafe { &**cell };
// Don't touch box2d stuff.
if cell.material.unwrap().cell_type == CellType::Solid {
if cell.material.cell_type == CellType::Solid {
continue;
}
// No point replacing cells with themselves.
if cell.material.unwrap().material_type == pixel.mat() as isize {
if cell.material.material_type == pixel.mat() as isize {
continue;
}
}

View file

@ -1,6 +1,6 @@
use crate::heap;
use crate::noita::types::objects::{ConfigExplosion, ConfigGridCosmeticParticle};
use crate::noita::types::{StdMap, StdString, StdVec, ThiscallFn, Vec2, Vec2i};
use crate::{heap, print};
use shared::world_sync::{Pixel, PixelFlags};
use std::ffi::c_void;
use std::fmt::{Debug, Formatter};
@ -335,7 +335,7 @@ pub struct Cell {
pub is_burning: bool,
pub temperature_of_fire: u8,
unknown2: [u8; 2],
pub material: Option<&'static CellData>,
pub material: &'static CellData,
}
unsafe impl Sync for Cell {}
@ -352,7 +352,7 @@ pub enum FullCell {
}
impl From<&Cell> for FullCell {
fn from(value: &Cell) -> Self {
match value.material.unwrap().cell_type {
match value.material.cell_type {
CellType::Liquid => FullCell::LiquidCell(*value.get_liquid()),
CellType::Fire => FullCell::FireCell(*value.get_fire()),
CellType::Gas => FullCell::GasCell(*value.get_gas()),
@ -534,7 +534,7 @@ impl Cell {
is_burning: material.on_fire,
temperature_of_fire: material.temperature_of_fire as u8,
unknown2: [0, 0],
material: Some(material),
material,
}
}
}
@ -718,20 +718,17 @@ impl Chunk {
#[inline]
pub fn get_pixel(&self, x: isize, y: isize) -> Pixel {
if let Some(cell) = self.get(x, y) {
if cell.material.unwrap().cell_type == CellType::Liquid {
if cell.material.cell_type == CellType::Liquid {
Pixel::new(
cell.material.unwrap().material_type as u16,
if cell.get_liquid().is_static == cell.material.unwrap().liquid_static {
cell.material.material_type as u16,
if cell.get_liquid().is_static == cell.material.liquid_static {
PixelFlags::Normal
} else {
PixelFlags::Abnormal
},
)
} else {
Pixel::new(
cell.material.unwrap().material_type as u16,
PixelFlags::Normal,
)
Pixel::new(cell.material.material_type as u16, PixelFlags::Normal)
}
} else {
Pixel::new(0, PixelFlags::Normal)
@ -787,8 +784,7 @@ impl Debug for Chunk {
.iter()
.enumerate()
.filter_map(|(i, a)| {
unsafe { a.as_ref() }
.map(|a| (i % 512, i / 512, a.material.unwrap().material_type))
unsafe { a.as_ref() }.map(|a| (i % 512, i / 512, a.material.material_type))
})
.collect::<Vec<_>>(),
)

View file

@ -32,7 +32,7 @@ pub struct MessageSocket<Inbound, Outbound> {
impl<Inbound: DecodeOwned + Send + 'static, Outbound: Encode> MessageSocket<Inbound, Outbound> {
pub fn new(socket: TcpStream) -> eyre::Result<Self> {
socket.set_write_timeout(Some(Duration::from_secs(10)))?;
let (sender, recv_messages) = mpsc::channel();
let (sender, recv_messages) = mpsc::sync_channel(32);
let reader_thread = Some(thread::spawn({
let socket = socket.try_clone()?;
move || {