From 94ae0c26b1cadd3df8a5097f1d64b2cbef5ce885 Mon Sep 17 00:00:00 2001 From: a dinosaur Date: Tue, 3 Sep 2024 23:42:28 +1000 Subject: [PATCH] adjust chunk generation range --- Sources/Voxelotl/ChunkGeneration.swift | 43 ++++++-------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/Sources/Voxelotl/ChunkGeneration.swift b/Sources/Voxelotl/ChunkGeneration.swift index cb007c2..9f67b61 100644 --- a/Sources/Voxelotl/ChunkGeneration.swift +++ b/Sources/Voxelotl/ChunkGeneration.swift @@ -37,10 +37,15 @@ public struct ChunkGeneration { return } let centerChunkID = World.makeID(position: position) - for offset in ChunkGeneration.chunkGenerateNeighbors { - let chunkID = centerChunkID &+ offset - if world.getChunk(id: chunkID) == nil { - self.generate(chunkID: chunkID) + let range = -2...2 + for z in range { + for y in range { + for x in range { + let chunkID = centerChunkID &+ SIMD3(x, y, z) + if world.getChunk(id: chunkID) == nil { + self.generate(chunkID: chunkID) + } + } } } } @@ -59,34 +64,4 @@ public struct ChunkGeneration { self.generatingChunkSet.remove(chunkID) } } - - private static let chunkGenerateNeighbors: [SIMD3] = [ - SIMD3(-1, -1, -1), - SIMD3(0, -1, -1), - SIMD3(1, -1, -1), - SIMD3(-1, 0, -1), - SIMD3(0, 0, -1), - SIMD3(1, 0, -1), - SIMD3(-1, 1, -1), - SIMD3(0, 1, -1), - SIMD3(1, 1, -1), - SIMD3(-1, -1, 0), - SIMD3(0, -1, 0), - SIMD3(1, -1, 0), - SIMD3(-1, 0, 0), - SIMD3(0, 0, 0), - SIMD3(1, 0, 0), - SIMD3(-1, 1, 0), - SIMD3(0, 1, 0), - SIMD3(1, 1, 0), - SIMD3(-1, -1, 1), - SIMD3(0, -1, 1), - SIMD3(1, -1, 1), - SIMD3(-1, 0, 1), - SIMD3(0, 0, 1), - SIMD3(1, 0, 1), - SIMD3(-1, 1, 1), - SIMD3(0, 1, 1), - SIMD3(1, 1, 1), - ] }