world visibility graph: listen for chunk data change

This fixes a bug where the world was first rendererd after moving the camera once
This commit is contained in:
Bixilon 2022-12-23 18:48:45 +01:00
parent 072efe15eb
commit 536227206c
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 7 additions and 3 deletions

View File

@ -92,7 +92,7 @@ class DebugHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Layouted
layout += TextElement(guiRenderer, TextComponent(RunConfiguration.APPLICATION_NAME, ChatColors.RED))
layout += AutoTextElement(guiRenderer, 1) { "FPS §d${renderWindow.renderStats.smoothAvgFPS.rounded10}" }
renderWindow.renderer[WorldRenderer]?.apply {
layout += AutoTextElement(guiRenderer, 1) { "C v=${visible.sizeString}, m=${loaded.size.format()}, cQ=${culledQueue.size.format()}, q=${meshingQueue.size.format()}, pT=${meshingQueue.tasks.size.format()}/${meshingQueue.tasks.max.format()}, l=${loadingQueue.size.format()}/${meshingQueue.maxMeshesToLoad.format()}, w=${connection.world.chunks.size.format()}" }
layout += AutoTextElement(guiRenderer, 1) { "C v=${visible.sizeString}, l=${loaded.size.format()}, cQ=${culledQueue.size.format()}, q=${meshingQueue.size.format()}, pT=${meshingQueue.tasks.size.format()}/${meshingQueue.tasks.max.format()}, lQ=${loadingQueue.size.format()}/${meshingQueue.maxMeshesToLoad.format()}, w=${connection.world.chunks.size.format()}" }
}
layout += renderWindow.renderer[EntityRenderer]?.let {

View File

@ -33,6 +33,8 @@ import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.EMPTY
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.chunkPosition
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.sectionHeight
import de.bixilon.minosoft.modding.event.events.blocks.chunk.ChunkDataChangeEvent
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.chunk.ChunkUtil.isInViewDistance
import it.unimi.dsi.fastutil.ints.IntOpenHashSet
@ -85,6 +87,8 @@ class WorldVisibilityGraph(
init {
calculateGraph()
connection.world.occlusionUpdateCallback = this
connection.events.listen<ChunkDataChangeEvent> { recalculateNextFrame = true }
}
fun isInViewDistance(chunkPosition: Vec2i): Boolean {
@ -313,7 +317,7 @@ class WorldVisibilityGraph(
@Synchronized
private fun calculateGraph() {
if (!RenderConstants.OCCLUSION_CULLING_ENABLED) {
connection.fire(VisibilityGraphChangeEvent(renderWindow))
connection.events.fire(VisibilityGraphChangeEvent(renderWindow))
return
}
connection.world.chunks.lock.acquire()
@ -355,7 +359,7 @@ class WorldVisibilityGraph(
connection.world.chunks.lock.release()
connection.fire(VisibilityGraphChangeEvent(renderWindow))
connection.events.fire(VisibilityGraphChangeEvent(renderWindow))
}
override fun onOcclusionChange() {