mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 05:10:57 +00:00
Parallelize chunk generation using fan-out pattern.
This commit is contained in:
parent
fbf66585eb
commit
a149de885c
@ -62,16 +62,32 @@ public class World {
|
|||||||
func generate(width: Int, height: Int, depth: Int, seed: UInt64) {
|
func generate(width: Int, height: Int, depth: Int, seed: UInt64) {
|
||||||
self._generator.reset(seed: seed)
|
self._generator.reset(seed: seed)
|
||||||
let orig = SIMD3(width, height, depth) / 2
|
let orig = SIMD3(width, height, depth) / 2
|
||||||
|
|
||||||
|
var localChunks: [SIMD3<Int>: Chunk] = [:]
|
||||||
|
let localChunksLock = NSLock()
|
||||||
|
let queue = OperationQueue()
|
||||||
|
queue.qualityOfService = .userInitiated
|
||||||
for z in 0..<depth {
|
for z in 0..<depth {
|
||||||
for y in 0..<height {
|
for y in 0..<height {
|
||||||
for x in 0..<width {
|
for x in 0..<width {
|
||||||
let chunkID = SIMD3(x, y, z) &- orig
|
let chunkID = SIMD3(x, y, z) &- orig
|
||||||
self._chunks[chunkID] = self._generator.makeChunk(id: chunkID)
|
queue.addOperation {
|
||||||
|
let chunk = self._generator.makeChunk(id: chunkID)
|
||||||
|
localChunksLock.lock()
|
||||||
|
defer {
|
||||||
|
localChunksLock.unlock()
|
||||||
|
}
|
||||||
|
localChunks[chunkID] = chunk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
queue.waitUntilAllOperationsAreFinished()
|
||||||
|
for (chunkID, chunk) in localChunks {
|
||||||
|
self._chunks[chunkID] = chunk
|
||||||
self._chunkDamage.insert(chunkID)
|
self._chunkDamage.insert(chunkID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func generate(chunkID: ChunkID) {
|
func generate(chunkID: ChunkID) {
|
||||||
self._chunks[chunkID] = self._generator.makeChunk(id: chunkID)
|
self._chunks[chunkID] = self._generator.makeChunk(id: chunkID)
|
||||||
|
Loading…
Reference in New Issue
Block a user