mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 02:59:37 +00:00 
			
		
		
		
	world regen clears all chunks
This commit is contained in:
		@ -14,12 +14,17 @@ public struct ChunkGeneration {
 | 
			
		||||
    self.queue.qualityOfService = .userInitiated
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public mutating func generate(chunkID: SIMD3<Int>) {
 | 
			
		||||
    if !generatingChunkSet.insert(chunkID).inserted {
 | 
			
		||||
      return
 | 
			
		||||
    }
 | 
			
		||||
  public mutating func cancelAndClearAll() {
 | 
			
		||||
    self.queue.cancelAllOperations()
 | 
			
		||||
    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>) {
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
    self.lock.lock()
 | 
			
		||||
    defer {
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,8 @@ class Game: GameDelegate {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private func generateWorld() {
 | 
			
		||||
    self.world.removeAllChunks()
 | 
			
		||||
    self.renderChunks.removeAll()
 | 
			
		||||
    let seed = UInt64(Arc4Random.instance.next()) | UInt64(Arc4Random.instance.next()) << 32
 | 
			
		||||
    printErr(seed)
 | 
			
		||||
#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) {
 | 
			
		||||
    self._generator.reset(seed: seed)
 | 
			
		||||
    let orig = SIMD3(width, height, depth) / 2
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user