Skip to content

Commit b39be10

Browse files
committed
actually send chunks to proxy again
1 parent 785e945 commit b39be10

File tree

5 files changed

+38
-46
lines changed

5 files changed

+38
-46
lines changed

ewext/src/modules/world_sync.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::modules::{Module, ModuleCtx};
22
use crate::{WorldSync, my_peer_id};
33
use eyre::{ContextCompat, eyre};
4-
use noita_api::noita::types::{CellType, FireCell, GasCell, LiquidCell};
4+
use noita_api::noita::types::{CellType, FireCell, GasCell, LiquidCell, Vec2i};
55
use noita_api::noita::world::ParticleWorldState;
66
use rayon::iter::{IntoParallelIterator, ParallelIterator};
77
use shared::NoitaOutbound;
@@ -23,21 +23,21 @@ impl Module for WorldSync {
2323
return Ok(());
2424
};
2525
let (x, y) = (ent.transform.pos.x, ent.transform.pos.y);
26-
let updates = (0..1)
27-
//.into_par_iter()
28-
.map(|i| {
26+
let updates = (0..9)
27+
.into_par_iter()
28+
.filter_map(|i| {
2929
let dx = i % 3;
3030
let dy = i / 3;
31-
let cx = x as i32 / CHUNK_SIZE as i32 + dx;
32-
let cy = y as i32 / CHUNK_SIZE as i32 + dy;
31+
let cx = x as i32 / CHUNK_SIZE as i32 - 1 + dx;
32+
let cy = y as i32 / CHUNK_SIZE as i32 - 1 + dy;
3333
let mut update = NoitaWorldUpdate {
3434
coord: ChunkCoord(cx, cy),
3535
pixels: std::array::from_fn(|_| Pixel::default()),
3636
};
3737
if unsafe {
3838
self.particle_world_state
3939
.assume_init_ref()
40-
.encode_world(update.coord, &mut update.pixels)
40+
.encode_world(&mut update)
4141
}
4242
.is_ok()
4343
{
@@ -49,6 +49,19 @@ impl Module for WorldSync {
4949
.collect::<Vec<_>>();
5050
let msg = NoitaOutbound::WorldSyncToProxy(WorldSyncToProxy::Updates(updates));
5151
ctx.net.send(&msg)?;
52+
let Vec2i { x: cx, y: cy } = ctx.globals.game_global.m_grid_world.cam_pos;
53+
let msg = NoitaOutbound::WorldSyncToProxy(WorldSyncToProxy::End(
54+
Some((
55+
x.div_euclid(CHUNK_SIZE as f32) as i32,
56+
y.div_euclid(CHUNK_SIZE as f32) as i32,
57+
cx.div_euclid(CHUNK_SIZE as isize) as i32,
58+
cy.div_euclid(CHUNK_SIZE as isize) as i32,
59+
false,
60+
)),
61+
1,
62+
self.world_num,
63+
));
64+
ctx.net.send(&msg)?;
5265
Ok(())
5366
}
5467
}
@@ -70,20 +83,14 @@ impl WorldSync {
7083
pub const SCALE: isize = (512 / CHUNK_SIZE as isize).ilog2() as isize;
7184
#[allow(unused)]
7285
trait WorldData {
73-
unsafe fn encode_world(
74-
&self,
75-
coord: ChunkCoord,
76-
chunk: &mut [Pixel; CHUNK_SIZE * CHUNK_SIZE],
77-
) -> eyre::Result<()>;
86+
unsafe fn encode_world(&self, chunk: &mut NoitaWorldUpdate) -> eyre::Result<()>;
7887
unsafe fn decode_world(&self, chunk: NoitaWorldUpdate) -> eyre::Result<()>;
7988
}
8089
impl WorldData for ParticleWorldState {
81-
unsafe fn encode_world(
82-
&self,
83-
coord: ChunkCoord,
84-
chunk: &mut [Pixel; CHUNK_SIZE * CHUNK_SIZE],
85-
) -> eyre::Result<()> {
86-
let (cx, cy) = (coord.0 as isize, coord.1 as isize);
90+
unsafe fn encode_world(&self, chunk: &mut NoitaWorldUpdate) -> eyre::Result<()> {
91+
let ChunkCoord(cx, cy) = chunk.coord;
92+
let (cx, cy) = (cx as isize, cy as isize);
93+
let chunk = &mut chunk.pixels;
8794
let Some(pixel_array) = unsafe { self.world_ptr.as_mut() }
8895
.wrap_err("no world")?
8996
.chunk_map

noita-proxy/src/net/world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3338,7 +3338,7 @@ impl WorldManager {
33383338
pub fn handle_noita_msg(&mut self, _: OmniPeerId, msg: WorldSyncToProxy) {
33393339
match msg {
33403340
WorldSyncToProxy::Updates(updates) => {
3341-
for update in updates.into_iter().flatten() {
3341+
for update in updates {
33423342
self.outbound_model
33433343
.apply_noita_update(update, &mut self.is_storage_recent)
33443344
}

noita-proxy/src/net/world/world_model.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,10 @@ impl ChunkData {
9292
}
9393

9494
impl WorldModel {
95-
fn get_chunk_coords(x: i32, y: i32) -> (ChunkCoord, usize) {
96-
let chunk_x = x.div_euclid(CHUNK_SIZE as i32);
97-
let chunk_y = y.div_euclid(CHUNK_SIZE as i32);
95+
fn get_chunk_offset(x: i32, y: i32) -> usize {
9896
let x = x.rem_euclid(CHUNK_SIZE as i32) as usize;
9997
let y = y.rem_euclid(CHUNK_SIZE as i32) as usize;
100-
let offset = x + y * CHUNK_SIZE;
101-
(ChunkCoord(chunk_x, chunk_y), offset)
98+
x + y * CHUNK_SIZE
10299
}
103100

104101
/*fn set_pixel(&mut self, x: i32, y: i32, pixel: Pixel) {
@@ -124,36 +121,21 @@ impl WorldModel {
124121
update: NoitaWorldUpdate,
125122
changed: &mut FxHashSet<ChunkCoord>,
126123
) {
127-
fn set_pixel(pixel: Pixel, chunk: &mut Chunk, offset: usize) -> bool {
128-
let current = chunk.pixel(offset);
129-
if current != pixel {
130-
chunk.set_pixel(offset, pixel);
131-
true
132-
} else {
133-
false
134-
}
135-
}
136124
let (start_x, start_y) = (
137125
update.coord.0 * CHUNK_SIZE as i32,
138126
update.coord.1 * CHUNK_SIZE as i32,
139127
);
140-
let mut chunk_coord = update.coord;
141-
let mut chunk = self.chunks.entry(update.coord).or_default();
128+
let chunk_coord = update.coord;
129+
let chunk = self.chunks.entry(update.coord).or_default();
142130
for (i, pixel) in update.pixels.into_iter().enumerate() {
143131
let x = (i % CHUNK_SIZE) as i32;
144132
let y = (i / CHUNK_SIZE) as i32;
145133
let xs = start_x + x;
146134
let ys = start_y + y;
147-
let (new_chunk_coord, offset) = Self::get_chunk_coords(xs, ys);
148-
if chunk_coord != new_chunk_coord {
149-
chunk_coord = new_chunk_coord;
150-
chunk = self.chunks.entry(chunk_coord).or_default();
151-
}
152-
if set_pixel(pixel, chunk, offset) {
135+
let offset = Self::get_chunk_offset(xs, ys);
136+
if chunk.set_pixel(offset, pixel) {
153137
self.updated_chunks.insert(chunk_coord);
154-
if changed.contains(&chunk_coord) {
155-
changed.remove(&chunk_coord);
156-
}
138+
changed.remove(&chunk_coord);
157139
}
158140
}
159141
}

noita-proxy/src/net/world/world_model/chunk.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ impl Chunk {
6666
self.pixels[offset]
6767
}
6868

69-
pub fn set_pixel(&mut self, offset: usize, pixel: Pixel) {
69+
pub fn set_pixel(&mut self, offset: usize, pixel: Pixel) -> bool {
7070
if self.pixels[offset] != pixel {
7171
self.pixels[offset] = pixel;
7272
self.mark_changed(offset);
73+
true
74+
} else {
75+
false
7376
}
7477
}
7578

shared/src/world_sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Pixel {
6666

6767
#[derive(Debug, Encode, Decode, Clone)]
6868
pub enum WorldSyncToProxy {
69-
Updates(Vec<Option<NoitaWorldUpdate>>),
69+
Updates(Vec<NoitaWorldUpdate>),
7070
End(Option<(i32, i32, i32, i32, bool)>, u8, u8),
7171
}
7272
#[derive(Debug, Encode, Decode, Clone)]

0 commit comments

Comments
 (0)