Factor out single chunk saving code into a function

This commit is contained in:
crumblingstatue 2023-04-14 17:42:22 +02:00
parent 7c4af574cd
commit 80e10e4e91

View file

@ -91,6 +91,12 @@ impl World {
} }
pub fn save_chunks(&self) { pub fn save_chunks(&self) {
for (pos, chk) in self.chunks.iter() { for (pos, chk) in self.chunks.iter() {
save_chunk(pos, chk);
}
}
}
fn save_chunk(pos: &ChunkPos, chk: &Chunk) {
let reg_file_name = format_reg_file_name(pos.region()); let reg_file_name = format_reg_file_name(pos.region());
dbg!(&reg_file_name); dbg!(&reg_file_name);
let reg_file_exists = Path::new(&reg_file_name).exists(); let reg_file_exists = Path::new(&reg_file_name).exists();
@ -139,8 +145,6 @@ impl World {
let result = f.write_all(&zstd::encode_all(&region_tile_data[..], COMP_LEVEL).unwrap()); let result = f.write_all(&zstd::encode_all(&region_tile_data[..], COMP_LEVEL).unwrap());
log::info!("{result:?}"); log::info!("{result:?}");
} }
}
}
fn loc_byte_idx_xy(x: u8, y: u8) -> usize { fn loc_byte_idx_xy(x: u8, y: u8) -> usize {
loc_byte_idx(loc_idx(y, x)) loc_byte_idx(loc_idx(y, x))