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 connection: PlayConnection,
|
||||||
val rendering: Rendering,
|
val rendering: Rendering,
|
||||||
) {
|
) {
|
||||||
|
private lateinit var renderThread: Thread
|
||||||
val renderStats = RenderStats()
|
val renderStats = RenderStats()
|
||||||
var screenDimensions = Vec2i(900, 500)
|
var screenDimensions = Vec2i(900, 500)
|
||||||
private set
|
private set
|
||||||
@ -116,6 +117,7 @@ class RenderWindow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun init(latch: CountUpAndDownLatch) {
|
fun init(latch: CountUpAndDownLatch) {
|
||||||
|
renderThread = Thread.currentThread()
|
||||||
Log.log(LogMessageType.RENDERING_LOADING) { "Creating window..." }
|
Log.log(LogMessageType.RENDERING_LOADING) { "Creating window..." }
|
||||||
val stopwatch = Stopwatch()
|
val stopwatch = Stopwatch()
|
||||||
// Setup an error callback. The default implementation
|
// Setup an error callback. The default implementation
|
||||||
@ -406,4 +408,8 @@ class RenderWindow(
|
|||||||
fun getClipboardText(): String {
|
fun getClipboardText(): String {
|
||||||
return glfwGetClipboardString(windowId) ?: ""
|
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() {
|
fun clearChunkCache() {
|
||||||
// ToDo: Stop all preparations
|
// ToDo: Stop all preparations
|
||||||
queuedChunks.clear()
|
queuedChunks.clear()
|
||||||
|
val chunkMeshes = allChunkSections.toSynchronizedMap().values
|
||||||
|
allChunkSections.clear()
|
||||||
|
visibleChunks.clear()
|
||||||
renderWindow.renderQueue.add {
|
renderWindow.renderQueue.add {
|
||||||
visibleChunks.clear()
|
for (meshCollection in chunkMeshes) {
|
||||||
for ((location, _) in allChunkSections) {
|
unloadMeshes(meshCollection.values)
|
||||||
unloadChunk(location)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unloadChunk(chunkPosition: Vec2i) {
|
fun unloadChunk(chunkPosition: Vec2i) {
|
||||||
queuedChunks.remove(chunkPosition)
|
queuedChunks.remove(chunkPosition)
|
||||||
renderWindow.renderQueue.add {
|
val chunkMesh = allChunkSections[chunkPosition] ?: return
|
||||||
allChunkSections[chunkPosition]?.let {
|
allChunkSections.remove(chunkPosition)
|
||||||
for ((_, meshCollection) in it) {
|
visibleChunks.remove(chunkPosition)
|
||||||
meshCollection.opaqueSectionArrayMesh.let {
|
renderWindow.renderQueue.add { unloadMeshes(chunkMesh.values) }
|
||||||
it.unload()
|
}
|
||||||
meshes--
|
|
||||||
triangles -= it.trianglesCount
|
private fun unloadMeshes(meshes: Collection<ChunkMeshCollection>) {
|
||||||
}
|
renderWindow.assertOnRenderThread()
|
||||||
meshCollection.transparentSectionArrayMesh?.let {
|
for (meshCollection in meshes) {
|
||||||
it.unload()
|
meshCollection.opaqueSectionArrayMesh.let {
|
||||||
meshes--
|
it.unload()
|
||||||
triangles -= it.trianglesCount
|
this.meshes--
|
||||||
}
|
triangles -= it.trianglesCount
|
||||||
}
|
}
|
||||||
allChunkSections.remove(chunkPosition)
|
meshCollection.transparentSectionArrayMesh?.let {
|
||||||
visibleChunks.remove(chunkPosition)
|
it.unload()
|
||||||
|
this.meshes--
|
||||||
|
triangles -= it.trianglesCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user