mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
rendering: WorldRenderer: improve chunk cache clearing
This commit is contained in:
parent
3c6baf0935
commit
6bb865867e
@ -56,6 +56,7 @@ class RenderWindow(
|
||||
val connection: PlayConnection,
|
||||
val rendering: Rendering,
|
||||
) {
|
||||
private lateinit var renderThread: Thread
|
||||
val renderStats = RenderStats()
|
||||
var screenDimensions = Vec2i(900, 500)
|
||||
private set
|
||||
@ -116,6 +117,7 @@ class RenderWindow(
|
||||
}
|
||||
|
||||
fun init(latch: CountUpAndDownLatch) {
|
||||
renderThread = Thread.currentThread()
|
||||
Log.log(LogMessageType.RENDERING_LOADING) { "Creating window..." }
|
||||
val stopwatch = Stopwatch()
|
||||
// Setup an error callback. The default implementation
|
||||
@ -406,4 +408,8 @@ class RenderWindow(
|
||||
fun getClipboardText(): String {
|
||||
return glfwGetClipboardString(windowId) ?: ""
|
||||
}
|
||||
|
||||
fun assertOnRenderThread() {
|
||||
check(Thread.currentThread() == renderThread) { "Current thread (${Thread.currentThread().name} is not the render thread!" }
|
||||
}
|
||||
}
|
||||
|
@ -351,32 +351,36 @@ class WorldRenderer(
|
||||
fun clearChunkCache() {
|
||||
// ToDo: Stop all preparations
|
||||
queuedChunks.clear()
|
||||
val chunkMeshes = allChunkSections.toSynchronizedMap().values
|
||||
allChunkSections.clear()
|
||||
visibleChunks.clear()
|
||||
renderWindow.renderQueue.add {
|
||||
visibleChunks.clear()
|
||||
for ((location, _) in allChunkSections) {
|
||||
unloadChunk(location)
|
||||
for (meshCollection in chunkMeshes) {
|
||||
unloadMeshes(meshCollection.values)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun unloadChunk(chunkPosition: Vec2i) {
|
||||
queuedChunks.remove(chunkPosition)
|
||||
renderWindow.renderQueue.add {
|
||||
allChunkSections[chunkPosition]?.let {
|
||||
for ((_, meshCollection) in it) {
|
||||
meshCollection.opaqueSectionArrayMesh.let {
|
||||
it.unload()
|
||||
meshes--
|
||||
triangles -= it.trianglesCount
|
||||
}
|
||||
meshCollection.transparentSectionArrayMesh?.let {
|
||||
it.unload()
|
||||
meshes--
|
||||
triangles -= it.trianglesCount
|
||||
}
|
||||
}
|
||||
allChunkSections.remove(chunkPosition)
|
||||
visibleChunks.remove(chunkPosition)
|
||||
val chunkMesh = allChunkSections[chunkPosition] ?: return
|
||||
allChunkSections.remove(chunkPosition)
|
||||
visibleChunks.remove(chunkPosition)
|
||||
renderWindow.renderQueue.add { unloadMeshes(chunkMesh.values) }
|
||||
}
|
||||
|
||||
private fun unloadMeshes(meshes: Collection<ChunkMeshCollection>) {
|
||||
renderWindow.assertOnRenderThread()
|
||||
for (meshCollection in meshes) {
|
||||
meshCollection.opaqueSectionArrayMesh.let {
|
||||
it.unload()
|
||||
this.meshes--
|
||||
triangles -= it.trianglesCount
|
||||
}
|
||||
meshCollection.transparentSectionArrayMesh?.let {
|
||||
it.unload()
|
||||
this.meshes--
|
||||
triangles -= it.trianglesCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user