From 0f1b7f7e8950f116c275e0c4d9f7a81eaf73729e Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sat, 28 Jan 2023 20:32:26 +0100 Subject: [PATCH] properly remove chunk from loading queue This should fix another missing chunk bug --- .../gui/rendering/world/WorldRendererTest.kt | 4 +++- .../minosoft/gui/rendering/world/WorldRenderer.kt | 2 +- .../world/queue/loading/MeshLoadingQueue.kt | 12 ++++++++++-- .../rendering/world/queue/queue/ChunkQueueMaster.kt | 7 ++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/world/WorldRendererTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/world/WorldRendererTest.kt index acac8375a..11d48235f 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/world/WorldRendererTest.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/world/WorldRendererTest.kt @@ -32,7 +32,7 @@ class WorldRendererTest { } private fun WorldRenderer.awaitQueue(count: Int) { - for (i in 0 until 2000) { + for (i in 0 until 200) { Thread.sleep(16) frame() if (loaded.size == count) { @@ -73,6 +73,7 @@ class WorldRendererTest { Assert.assertEquals(renderer.loaded.size, 1) } + @Test(invocationCount = 10) fun queueMultipleChunks() { val chunks = setOf( RenderTestUtil.context.connection.world[Vec2i(0, 0)]!!, @@ -82,6 +83,7 @@ class WorldRendererTest { ) for (chunk in chunks) { chunk[Vec3i(0, 0, 0)] = StoneTestO.state + chunk[Vec3i(0, 16, 0)] = StoneTestO.state } val renderer = create() for (chunk in chunks) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/world/WorldRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/world/WorldRenderer.kt index 4efb0ad8f..0a3464c5c 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/world/WorldRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/world/WorldRenderer.kt @@ -197,7 +197,7 @@ class WorldRenderer( loaded.unload(position.position, position.sectionHeight, false) culledQueue.remove(position.position, position.sectionHeight, false) meshingQueue.remove(position, false) - loadingQueue.abort(position.position, false) + loadingQueue.abort(position, false) meshingQueue.tasks.interrupt(position.position, position.sectionHeight) lock.unlock() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/world/queue/loading/MeshLoadingQueue.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/world/queue/loading/MeshLoadingQueue.kt index d9f3dc907..e6d70fbfa 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/world/queue/loading/MeshLoadingQueue.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/world/queue/loading/MeshLoadingQueue.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -110,6 +110,14 @@ class MeshLoadingQueue( if (lock) unlock() } + fun abort(position: QueuePosition, lock: Boolean = true) { + if (lock) lock() + if (this.positions.remove(position)) { + this.meshes.removeAll { it.chunkPosition == position.position && it.sectionHeight == position.sectionHeight } + } + if (lock) unlock() + } + fun cleanup(lock: Boolean) { val remove: MutableSet = mutableSetOf() @@ -123,7 +131,7 @@ class MeshLoadingQueue( return@removeAll true } - this.meshes.removeAll { QueuePosition(it) in remove } + this.meshes.removeAll { QueuePosition(it) in remove; } if (lock) unlock() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/world/queue/queue/ChunkQueueMaster.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/world/queue/queue/ChunkQueueMaster.kt index b6cf76022..d0583bce6 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/world/queue/queue/ChunkQueueMaster.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/world/queue/queue/ChunkQueueMaster.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger + * Copyright (C) 2020-2023 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -101,10 +101,7 @@ class ChunkQueueMaster( private fun canQueue(): Boolean { val state = renderer.context.state - if (state == RenderingStates.PAUSED || state == RenderingStates.STOPPED || state == RenderingStates.QUITTING) { - return false - } - return true + return !(state == RenderingStates.PAUSED || state == RenderingStates.STOPPED || state == RenderingStates.QUITTING) } private companion object {