From 0cdc495434c9bc8f896db62b75d85f54b44d23ae Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Mon, 2 Sep 2024 19:59:37 +1000 Subject: [PATCH] don't damage chunk if a one block change doesn't touch a solid --- Sources/Voxelotl/World.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/Voxelotl/World.swift b/Sources/Voxelotl/World.swift index b1517ff..4ba12a0 100644 --- a/Sources/Voxelotl/World.swift +++ b/Sources/Voxelotl/World.swift @@ -36,12 +36,18 @@ public class World { for (i, ofs) in zip(internalPos.indices, [ SIMD3.X, .Y, .Z ]) { if internalPos[i] == 0 { let id = chunkID &- ofs - if self._chunks.keys.contains(id) { + if let other = self._chunks[id], + // optim: Damage adjacent chunk only if block is touching a solid + case .solid = other.getBlock(internal: (internalPos &- ofs) & Chunk.mask).type + { self._chunkDamage.insert(id) } } else if internalPos[i] == Chunk.size - 1 { let id = chunkID &+ ofs - if self._chunks.keys.contains(id) { + if let other = self._chunks[id], + // optim: Damage adjacent chunk only if block is touching a solid + case .solid = other.getBlock(internal: (internalPos &+ ofs) & Chunk.mask).type + { self._chunkDamage.insert(id) } }