Merge branch 'crabman/terrain-persistence-crash' into 'master'

don't remove blocks when applying changes for new chunks

See merge request veloren/veloren!4276
This commit is contained in:
Imbris 2024-01-26 02:08:59 +00:00
commit fd2e45cfde
2 changed files with 4 additions and 10 deletions

View File

@ -672,10 +672,12 @@ impl Block {
#[must_use]
pub fn from_u32(x: u32) -> Option<Self> {
let [bk, r, g, b] = x.to_le_bytes();
Some(Self {
let block = Self {
kind: BlockKind::from_u8(bk)?,
data: [r, g, b],
})
};
(block.kind.is_filled() || SpriteKind::from_block(block).is_some()).then_some(block)
}
#[inline]

View File

@ -74,15 +74,11 @@ impl TerrainPersistence {
}
}
let removed = resets.len();
// Reset any unchanged blocks (this is an optimisation only)
for rpos in resets {
loaded_chunk.chunk.reset_block(rpos);
loaded_chunk.modified = true;
}
self.cached_chunks.limiter_mut().remove_blocks(removed);
}
/// Maintain terrain persistence (writing changes changes back to
@ -314,10 +310,6 @@ impl ByBlockLimiter {
/// This function should only be used when it is guaranteed that a block has
/// been added
fn add_block(&mut self) { self.counted_blocks += 1; }
/// This function should only be used when it is guaranteed that this number
/// of blocks has been removed
fn remove_blocks(&mut self, removed: usize) { self.counted_blocks -= removed; }
}
/// # Adding a new chunk format version