mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 05:10:57 +00:00
world regen clears all chunks
This commit is contained in:
parent
c80e456d3e
commit
ee54e011a1
@ -14,12 +14,17 @@ public struct ChunkGeneration {
|
|||||||
self.queue.qualityOfService = .userInitiated
|
self.queue.qualityOfService = .userInitiated
|
||||||
}
|
}
|
||||||
|
|
||||||
public mutating func generate(chunkID: SIMD3<Int>) {
|
public mutating func cancelAndClearAll() {
|
||||||
if !generatingChunkSet.insert(chunkID).inserted {
|
self.queue.cancelAllOperations()
|
||||||
return
|
self.queue.waitUntilAllOperationsAreFinished()
|
||||||
}
|
self.localReadyChunks.removeAll()
|
||||||
|
self.generatingChunkSet.removeAll()
|
||||||
|
}
|
||||||
|
|
||||||
self.queueGenerateJob(chunkID: chunkID)
|
public mutating func generate(chunkID: SIMD3<Int>) {
|
||||||
|
if generatingChunkSet.insert(chunkID).inserted {
|
||||||
|
self.queueGenerateJob(chunkID: chunkID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func queueGenerateJob(chunkID: SIMD3<Int>) {
|
func queueGenerateJob(chunkID: SIMD3<Int>) {
|
||||||
|
@ -70,6 +70,12 @@ public class ConcurrentDictionary<V: Hashable, T>: Collection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func removeAll(keepingCapacity keep: Bool = false) {
|
||||||
|
self.locked {
|
||||||
|
self.inner.removeAll(keepingCapacity: keep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fileprivate func locked<X>(_ perform: () -> X) -> X {
|
fileprivate func locked<X>(_ perform: () -> X) -> X {
|
||||||
self.lock.lock()
|
self.lock.lock()
|
||||||
defer {
|
defer {
|
||||||
|
@ -32,6 +32,8 @@ class Game: GameDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func generateWorld() {
|
private func generateWorld() {
|
||||||
|
self.world.removeAllChunks()
|
||||||
|
self.renderChunks.removeAll()
|
||||||
let seed = UInt64(Arc4Random.instance.next()) | UInt64(Arc4Random.instance.next()) << 32
|
let seed = UInt64(Arc4Random.instance.next()) | UInt64(Arc4Random.instance.next()) << 32
|
||||||
printErr(seed)
|
printErr(seed)
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -68,6 +68,11 @@ public class World {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeAllChunks() {
|
||||||
|
self._chunkGeneration.cancelAndClearAll()
|
||||||
|
self._chunks.removeAll()
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user