Skip to content

Commit

Permalink
fix: chunk writing with async read
Browse files Browse the repository at this point in the history
  • Loading branch information
Mili-ssm authored Feb 22, 2025
1 parent fb271f9 commit 40e4c34
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pumpkin-world/src/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,25 @@ impl Level {
let chunk_saver = self.chunk_saver.clone();
let level_folder = self.level_folder.clone();

let chunks_to_write = chunks_to_write.to_vec();

let futures = chunks_to_write
.iter()
.map(|chunk| chunk.blocking_read())
.map(|chunk| chunk.read())
.collect::<Vec<_>>();

let chunks = futures
let mut chunks_guards = Vec::new();
for guard in futures {
let chunk = guard.await;
chunks_guards.push(chunk);
}

let chunks = chunks_guards
.iter()
.map(|chunk| (chunk.position, chunk.deref()))
.collect::<Vec<_>>();

trace!("Writing chunks to disk {:}", chunks.len());
if let Err(error) = chunk_saver.save_chunks(&level_folder, chunks).await {
trace!("Writing chunks to disk {:}", chunks_guards.len());

if let Err(error) = chunk_saver.save_chunks(&level_folder, chunks.as_slice()) {
log::error!("Failed writing Chunk to disk {}", error.to_string());
}
}
Expand Down

0 comments on commit 40e4c34

Please sign in to comment.