From df31204dfeb189124b751ae27bd3feba50e1d557 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Mon, 18 Dec 2023 17:20:33 +0100 Subject: [PATCH] particle renderer: remove translucent shader Its the same shader --- .../particle/ParticleRendererTest.kt | 2 +- .../rendering/particle/ParticleRenderer.kt | 11 +++------ .../gui/rendering/particle/ParticleTicker.kt | 24 +------------------ 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/particle/ParticleRendererTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/particle/ParticleRendererTest.kt index 518e84de3..b7d5355e7 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/particle/ParticleRendererTest.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/particle/ParticleRendererTest.kt @@ -124,7 +124,7 @@ class ParticleRendererTest { } - // TODO: queue, maxAmount, auto ticking + // TODO: auto ticking (task registering) private class TestParticle(connection: PlayConnection) : Particle(connection, Vec3d.EMPTY, Vec3d.EMPTY, DATA) { var vertices = 0 diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleRenderer.kt index f2b30d0ce..8a34a438d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleRenderer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleRenderer.kt @@ -43,7 +43,6 @@ class ParticleRenderer( override val renderSystem: RenderSystem = context.system private val profile = connection.profiles.particle private val shader = renderSystem.createShader(minosoft("particle")) { ParticleShader(it) } - private val translucentShader = renderSystem.createShader(minosoft("particle")) { ParticleShader(it) } // There is no opaque mesh because it is simply not needed (every particle has transparency) var mesh = ParticleMesh(context, BufferedArrayFloatList(profile.maxAmount * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX)) @@ -81,7 +80,7 @@ class ParticleRenderer( override fun registerLayers() { layers.register(OpaqueLayer, shader, this::drawTransparent) - layers.register(TranslucentLayer, translucentShader, this::drawTranslucent) + layers.register(TranslucentLayer, shader, this::drawTranslucent) } private fun loadTextures() { @@ -107,7 +106,6 @@ class ParticleRenderer( override fun postInit(latch: AbstractLatch) { shader.load() - translucentShader.load() ticker.init() connection.world.particle = this @@ -125,21 +123,18 @@ class ParticleRenderer( queue += particle } - private fun updateShaders() { + private fun updateShader() { val matrix = context.camera.matrixHandler.viewProjectionMatrix val cameraRight = Vec3(matrix[0][0], matrix[1][0], matrix[2][0]) val cameraUp = Vec3(matrix[0][1], matrix[1][1], matrix[2][1]) shader.cameraRight = cameraRight shader.cameraUp = cameraUp - - translucentShader.cameraRight = cameraRight - translucentShader.cameraUp = cameraUp } override fun prePrepareDraw() { if (matrixUpdate) { - updateShaders() + updateShader() matrixUpdate = false } mesh.unload() diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleTicker.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleTicker.kt index 879ab5357..2c56da5fa 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleTicker.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/ParticleTicker.kt @@ -14,15 +14,12 @@ package de.bixilon.minosoft.gui.rendering.particle import de.bixilon.kutil.concurrent.schedule.RepeatedTask -import de.bixilon.kutil.concurrent.schedule.TaskScheduler import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll -import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.kutil.time.TimeUtil.millis import de.bixilon.minosoft.data.world.positions.ChunkPosition import de.bixilon.minosoft.gui.rendering.particle.types.Particle import de.bixilon.minosoft.protocol.network.connection.play.PlayConnectionStates import de.bixilon.minosoft.protocol.packets.s2c.play.block.chunk.ChunkUtil.isInViewDistance -import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition class ParticleTicker(val renderer: ParticleRenderer) { private val particles = renderer.particles @@ -85,27 +82,8 @@ class ParticleTicker(val renderer: ParticleRenderer) { particles.lock.unlock() } - private fun unregister() { - val task = this.task ?: return - TaskScheduler -= task - this.task = null - } - - private fun register() { - if (this.task != null) unregister() - val task = RepeatedTask(ProtocolDefinition.TICK_TIME, maxDelay = ProtocolDefinition.TICK_TIME / 2) { tick(false) } - this.task = task - TaskScheduler += task - } - - fun init() { - context.connection::state.observe(this) { - unregister() - if (it == PlayConnectionStates.PLAYING) { - register() - } - } + context.connection.ticker += { tick(false) } } companion object {