Skip to content

Commit

Permalink
Made it skip not-available chunks. Fixed import issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sweattypalms committed Sep 10, 2024
1 parent 36ab769 commit 6ee538a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
Binary file added README/assets/chunk_loading.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn start_server() -> Result<()> {

let state = create_state(listener).await?;

if env::args().nth(0).unwrap_or_default() == "--import" {
if env::args().any(|arg| arg == "--import") {
world::importing::import_regions(state.clone()).await?;
exit(0);
}
Expand Down
15 changes: 1 addition & 14 deletions src/net/packets/incoming/set_player_pos_and_rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,7 @@ impl IncomingPacket for SetPlayerPosAndRotate {
let mut rotation = component_storage.get_mut::<Rotation>(my_entity_id).await?;

ChunkSender::send_chunks_to_player_if_needed(state.clone(), my_entity_id, (position.x >> 4, position.z >> 4)).await?;
/*let old_chunk_pos = (position.x >> 4, position.z >> 4);
let new_chunk_pos = (self.x as i32 >> 4, self.z as i32 >> 4);
if old_chunk_pos != new_chunk_pos {
let state_clone = state.clone();
tokio::spawn(
async move {
ChunkSender::send_chunks_to_player(state_clone, my_entity_id).await?;
Ok::<(), Error>(())
}
);
}
*/

*position = Position {
x: self.x as i32,
y: self.y as i16,
Expand Down
15 changes: 10 additions & 5 deletions src/net/systems/chunk_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::utils::encoding::position::Position;
use crate::utils::prelude::*;
use ferrumc_macros::AutoGenName;

pub const CHUNK_RADIUS: i32 = 32;
pub const CHUNK_RADIUS: i32 = 16;
const CHUNK_TX_INTERVAL_MS: u64 = 50000;

#[derive(AutoGenName)]
Expand Down Expand Up @@ -67,7 +67,7 @@ impl ChunkSender {

let distance = last_chunk_tx_pos.distance_to(current_pos.0, current_pos.1);

if distance < (CHUNK_RADIUS as f64 / 4f64) {
if distance < (CHUNK_RADIUS as f64 / 5f64) {
return Ok(());
}

Expand Down Expand Up @@ -126,13 +126,18 @@ impl ChunkSender {
let pos_x = pos.x;
let pos_z = pos.z;

'x: for x in -CHUNK_RADIUS..=CHUNK_RADIUS {
for x in -CHUNK_RADIUS..=CHUNK_RADIUS {
for z in -CHUNK_RADIUS..=CHUNK_RADIUS {
let packet = ChunkDataAndUpdateLight::new(state.clone(), (pos_x >> 4) + x, (pos_z >> 4) + z).await?;
let Ok(packet) = ChunkDataAndUpdateLight::new(
state.clone(),
(pos_x >> 4) + x,
(pos_z >> 4) + z,
).await else {
continue;
};
let conn_read = conn.read().await;
if let Err(e) = conn_read.send_packet(packet).await {
warn!("Failed to send chunk to player: {}", e);
break 'x;
}
}
}
Expand Down

0 comments on commit 6ee538a

Please sign in to comment.