11use  crate :: modules:: { Module ,  ModuleCtx } ; 
22use  crate :: { WorldSync ,  my_peer_id} ; 
33use  eyre:: { ContextCompat ,  eyre} ; 
4- use  noita_api:: noita:: types:: { CellType ,  FireCell ,  GasCell ,  LiquidCell } ; 
4+ use  noita_api:: noita:: types:: { CellType ,  FireCell ,  GasCell ,  LiquidCell ,   Vec2i } ; 
55use  noita_api:: noita:: world:: ParticleWorldState ; 
66use  rayon:: iter:: { IntoParallelIterator ,  ParallelIterator } ; 
77use  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 {
7083pub  const  SCALE :  isize  = ( 512  / CHUNK_SIZE  as  isize ) . ilog2 ( )  as  isize ; 
7184#[ allow( unused) ]  
7285trait  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} 
8089impl  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 
0 commit comments