mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 21:21:34 +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() {
|
public mutating func acceptReadyChunks() {
|
||||||
guard let world = self.world else {
|
guard let world = self.world else {
|
||||||
return
|
return
|
||||||
|
@ -2,7 +2,7 @@ import Foundation
|
|||||||
|
|
||||||
public struct ChunkMeshGeneration {
|
public struct ChunkMeshGeneration {
|
||||||
private let queue: OperationQueue
|
private let queue: OperationQueue
|
||||||
private let localReadyMeshes = ConcurrentDictionary<SIMD3<Int>, RendererMesh>()
|
private let localReadyMeshes = ConcurrentDictionary<SIMD3<Int>, RendererMesh?>()
|
||||||
|
|
||||||
weak var game: Game?
|
weak var game: Game?
|
||||||
weak var renderer: Renderer?
|
weak var renderer: Renderer?
|
||||||
|
@ -7,13 +7,14 @@ class Game: GameDelegate {
|
|||||||
var projection: matrix_float4x4 = .identity
|
var projection: matrix_float4x4 = .identity
|
||||||
var world = World(generator: StandardWorldGenerator())
|
var world = World(generator: StandardWorldGenerator())
|
||||||
var cubeMesh: RendererMesh?
|
var cubeMesh: RendererMesh?
|
||||||
var renderChunks = [SIMD3<Int>: RendererMesh]()
|
var renderChunks = [SIMD3<Int>: RendererMesh?]()
|
||||||
var chunkMeshGeneration: ChunkMeshGeneration!
|
var chunkMeshGeneration: ChunkMeshGeneration!
|
||||||
var modelBatch: ModelBatch!
|
var modelBatch: ModelBatch!
|
||||||
|
|
||||||
func create(_ renderer: Renderer) {
|
func create(_ renderer: Renderer) {
|
||||||
self.resetPlayer()
|
self.resetPlayer()
|
||||||
self.generateWorld()
|
self.generateWorld()
|
||||||
|
self.world.waitForActiveOperations()
|
||||||
|
|
||||||
self.cubeMesh = renderer.createMesh(CubeMeshBuilder.build(bound: .fromUnitCube(position: .zero, scale: .one)))
|
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)
|
self.modelBatch.begin(camera: camera, environment: env)
|
||||||
|
|
||||||
for (id, chunk) in self.renderChunks {
|
for (id, chunk) in self.renderChunks {
|
||||||
|
if chunk == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
let drawPos = SIMD3<Float>(id &<< Chunk.shift)
|
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 {
|
if let position = player.rayhitPos {
|
||||||
|
@ -106,6 +106,10 @@ public class World {
|
|||||||
self._chunkGeneration.acceptReadyChunks()
|
self._chunkGeneration.acceptReadyChunks()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func waitForActiveOperations() {
|
||||||
|
self._chunkGeneration.waitForActiveOperations()
|
||||||
|
}
|
||||||
|
|
||||||
func handleRenderDamagedChunks(_ body: (_ id: ChunkID, _ chunk: Chunk) -> Void) {
|
func handleRenderDamagedChunks(_ body: (_ id: ChunkID, _ chunk: Chunk) -> Void) {
|
||||||
for id in self._chunkDamage {
|
for id in self._chunkDamage {
|
||||||
body(id, self._chunks[id]!)
|
body(id, self._chunks[id]!)
|
||||||
|
Reference in New Issue
Block a user