diff --git a/build.gradle.kts b/build.gradle.kts index 4ff971b7..98fe1f05 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -81,7 +81,7 @@ dependencies { implementation("com.github.jnr:jnr-ffi:2.2.13") implementation("ru.dbotthepony:kbox2d:2.4.1.6") - implementation("ru.dbotthepony:kvector:2.2.9") + implementation("ru.dbotthepony:kvector:2.4.0") implementation("com.github.ben-manes.caffeine:caffeine:3.1.5") } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt index ae7d8eca..55d58e58 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/client/ClientChunk.kt @@ -1,5 +1,6 @@ package ru.dbotthepony.kstarbound.client +import it.unimi.dsi.fastutil.objects.ReferenceArraySet import org.lwjgl.opengl.GL11.GL_LINES import org.lwjgl.opengl.GL11.GL_TRIANGLES import ru.dbotthepony.kstarbound.client.gl.GLStateTracker @@ -278,6 +279,24 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk() + private var liquidTypesVer = 0 + + private fun getLiquidTypes(): Collection { + if (liquidTypesVer != liquidChangeset) { + liquidTypes.clear() + liquidTypesVer = liquidChangeset + + for (x in 0 until CHUNK_SIZE) { + for (y in 0 until CHUNK_SIZE) { + getCell(x, y).liquid.def?.let { liquidTypes.add(it) } + } + } + } + + return liquidTypes + } + inner class Renderer(val renderOrigin: ChunkPos = pos) : GPULightRenderer.ShadowGeometryRenderer { override fun renderHardGeometry( renderer: GPULightRenderer, @@ -379,47 +398,40 @@ class ClientChunk(world: ClientWorld, pos: ChunkPos) : Chunk() + val types = getLiquidTypes() - for (x in 0 until CHUNK_SIZE) { - for (y in 0 until CHUNK_SIZE) { - val state = getCell(x, y) + if (types.isNotEmpty()) { + layers.add(Z_LEVEL_LIQUID) { + it.push().last().translateWithMultiplication(renderOrigin.x * CHUNK_SIZEf, renderOrigin.y * CHUNK_SIZEf) - if (state.liquid.def != null && !types.any { it === state.liquid.def }) { - types.add(state.liquid.def!!) - } - } - } + val program = state.programs.liquid - val program = state.programs.liquid + program.use() + program.transform = it.last() - program.use() - program.transform = it.last() + val builder = program.builder - val builder = program.builder + for (type in types) { + builder.builder.begin() - for (type in types) { - builder.builder.begin() + for (x in 0 until CHUNK_SIZE) { + for (y in 0 until CHUNK_SIZE) { + val state = getCell(x, y) - for (x in 0 until CHUNK_SIZE) { - for (y in 0 until CHUNK_SIZE) { - val state = getCell(x, y) - - if (state.liquid.def === type) { - builder.builder.quad(x.toFloat(), y.toFloat(), x + 1f, y + state.liquid.level) + if (state.liquid.def === type) { + builder.builder.quad(x.toFloat(), y.toFloat(), x + 1f, y + state.liquid.level) + } } } + + program.baselineColor = type.color + + builder.upload() + builder.draw() } - program.baselineColor = type.color - - builder.upload() - builder.draw() + it.pop() } - - it.pop() } } }