mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 02:59:37 +00:00 
			
		
		
		
	fix ghost chunks and wait for generation on startup
This commit is contained in:
		@ -50,6 +50,10 @@ public struct ChunkGeneration {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public func waitForActiveOperations() {
 | 
			
		||||
    self.queue.waitUntilAllOperationsAreFinished()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public mutating func acceptReadyChunks() {
 | 
			
		||||
    guard let world = self.world else {
 | 
			
		||||
      return
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,7 @@ import Foundation
 | 
			
		||||
 | 
			
		||||
public struct ChunkMeshGeneration {
 | 
			
		||||
  private let queue: OperationQueue
 | 
			
		||||
  private let localReadyMeshes = ConcurrentDictionary<SIMD3<Int>, RendererMesh>()
 | 
			
		||||
  private let localReadyMeshes = ConcurrentDictionary<SIMD3<Int>, RendererMesh?>()
 | 
			
		||||
 | 
			
		||||
  weak var game: Game?
 | 
			
		||||
  weak var renderer: Renderer?
 | 
			
		||||
 | 
			
		||||
@ -7,13 +7,14 @@ class Game: GameDelegate {
 | 
			
		||||
  var projection: matrix_float4x4 = .identity
 | 
			
		||||
  var world = World(generator: StandardWorldGenerator())
 | 
			
		||||
  var cubeMesh: RendererMesh?
 | 
			
		||||
  var renderChunks = [SIMD3<Int>: RendererMesh]()
 | 
			
		||||
  var renderChunks = [SIMD3<Int>: RendererMesh?]()
 | 
			
		||||
  var chunkMeshGeneration: ChunkMeshGeneration!
 | 
			
		||||
  var modelBatch: ModelBatch!
 | 
			
		||||
 | 
			
		||||
  func create(_ renderer: Renderer) {
 | 
			
		||||
    self.resetPlayer()
 | 
			
		||||
    self.generateWorld()
 | 
			
		||||
    self.world.waitForActiveOperations()
 | 
			
		||||
 | 
			
		||||
    self.cubeMesh = renderer.createMesh(CubeMeshBuilder.build(bound: .fromUnitCube(position: .zero, scale: .one)))
 | 
			
		||||
 | 
			
		||||
@ -104,8 +105,11 @@ class Game: GameDelegate {
 | 
			
		||||
    self.modelBatch.begin(camera: camera, environment: env)
 | 
			
		||||
 | 
			
		||||
    for (id, chunk) in self.renderChunks {
 | 
			
		||||
      if chunk == nil {
 | 
			
		||||
        continue
 | 
			
		||||
      }
 | 
			
		||||
      let drawPos = SIMD3<Float>(id &<< Chunk.shift)
 | 
			
		||||
      self.modelBatch.draw(.init(mesh: chunk, material: material), position: drawPos)
 | 
			
		||||
      self.modelBatch.draw(.init(mesh: chunk!, material: material), position: drawPos)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if let position = player.rayhitPos {
 | 
			
		||||
 | 
			
		||||
@ -106,6 +106,10 @@ public class World {
 | 
			
		||||
    self._chunkGeneration.acceptReadyChunks()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public func waitForActiveOperations() {
 | 
			
		||||
    self._chunkGeneration.waitForActiveOperations()
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  func handleRenderDamagedChunks(_ body: (_ id: ChunkID, _ chunk: Chunk) -> Void) {
 | 
			
		||||
    for id in self._chunkDamage {
 | 
			
		||||
      body(id, self._chunks[id]!)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user