Added reset system for unused persisted blocks

This commit is contained in:
Joshua Barretto 2021-06-25 13:21:03 +01:00
parent ee12924124
commit 22f95edf32
2 changed files with 17 additions and 2 deletions

View File

@ -156,8 +156,19 @@ impl<'a> System<'a> for Sys {
},
};
for (key, block) in terrain_persistence.load_chunk(key).blocks() {
chunk.set(key, block);
// Terrain persistence
let mut resets = Vec::new();
for (rpos, new_block) in terrain_persistence.load_chunk(key).blocks() {
chunk.map(rpos, |block| {
if block == new_block {
resets.push(rpos);
}
new_block
});
}
// Reset any unchanged blocks
for rpos in resets {
terrain_persistence.reset_block(key, rpos);
}
// Arcify the chunk

View File

@ -103,6 +103,10 @@ impl TerrainPersistence {
let key = pos.xy().map2(TerrainChunk::RECT_SIZE, |e, sz| e.div_euclid(sz as i32));
self.load_chunk(key).blocks.insert(pos - key * TerrainChunk::RECT_SIZE.map(|e| e as i32), block);
}
pub fn reset_block(&mut self, key: Vec2<i32>, rpos: Vec3<i32>) {
self.load_chunk(key).blocks.remove(&rpos);
}
}
#[derive(Default, Serialize, Deserialize)]