Compressing with lz4

This commit is contained in:
Piotrek
2021-05-10 13:30:15 +02:00
parent 3bd9fa942e
commit 4eaa0fab56
5 changed files with 76 additions and 44 deletions
+5 -3
View File
@@ -72,16 +72,17 @@ impl World {
data_file.write_all(data_str.as_bytes()).expect("Failed to write");
}
pub fn load(&mut self) {
pub fn load(&mut self) -> bool {
// Get directory
let mut dir = dirs::data_local_dir().unwrap();
dir.push("Voxelgame");
if !dir.is_dir() {
println!("Not exists: {:?}", dir);
return;
return false;
}
// Load all chunks
let mut count = 0;
for entry in fs::read_dir(dir).unwrap() {
let path: PathBuf = entry.unwrap().path();
if path.extension().unwrap().to_str() != Some("dat") {
@@ -102,10 +103,11 @@ impl World {
println!("loaded {:?}", pos);
self.chunks.insert(pos, chunk);
count += 1;
}
// Load metadata
return count > 0;
}
pub fn gen_block(&mut self, block_wpos: &Point3<u32>) -> &WorldBlock {