From 5707631d53b9c20f63ba95e93479d238aa0d8b2e Mon Sep 17 00:00:00 2001 From: Bixilon Date: Sat, 5 Feb 2022 19:16:26 +0100 Subject: [PATCH] do audio async, fix packet particles, text flow (chat) caching --- .../gui/elements/text/TextFlowElement.kt | 2 +- .../particle/DefaultParticleBehavior.kt | 39 ++++++++++--------- .../gui/rendering/sound/AudioPlayer.kt | 3 +- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextFlowElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextFlowElement.kt index 349d69b02..8dec2facc 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextFlowElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/elements/text/TextFlowElement.kt @@ -53,7 +53,6 @@ open class TextFlowElement( get() = maxSize set(value) = Unit - override var cacheEnabled: Boolean = false // ToDo: Cache private var textSize = Vec2i.EMPTY override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer, options: GUIVertexOptions?): Int { @@ -122,6 +121,7 @@ open class TextFlowElement( _size = Vec2i(maxSize.x, visibleLines.size * Font.TOTAL_CHAR_HEIGHT) background.size = size this.visibleLines = visibleLines + cacheUpToDate = false } fun addMessage(message: ChatComponent) { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/DefaultParticleBehavior.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/DefaultParticleBehavior.kt index e296c97c6..cc266c920 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/particle/DefaultParticleBehavior.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/particle/DefaultParticleBehavior.kt @@ -13,6 +13,7 @@ package de.bixilon.minosoft.gui.rendering.particle +import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.minosoft.gui.rendering.particle.types.norender.ExplosionEmitterParticle import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.explosion.ExplosionParticle import de.bixilon.minosoft.gui.rendering.util.VecUtil.times @@ -45,27 +46,29 @@ object DefaultParticleBehavior { } }, CallbackEventInvoker.of { - if (it.initiator == EventInitiators.SERVER && typesConfig.packet) { - return@of - } - fun spawn(position: Vec3d, velocity: Vec3d) { - val particle = it.data.type.factory?.build(connection, position, velocity, it.data) ?: let { _ -> - Log.log(LogMessageType.RENDERING_GENERAL, LogLevels.WARN) { "Can not spawn particle: ${it.data.type}" } - return + DefaultThreadPool += add@{ + if (it.initiator == EventInitiators.SERVER && !typesConfig.packet) { + return@add } - particleRenderer += particle - } - // ToDo: long distance = always spawn? - if (it.count == 0) { - val velocity = it.offset * it.speed + fun spawn(position: Vec3d, velocity: Vec3d) { + val particle = it.data.type.factory?.build(connection, position, velocity, it.data) ?: let { _ -> + Log.log(LogMessageType.RENDERING_GENERAL, LogLevels.WARN) { "Can not spawn particle: ${it.data.type}" } + return + } + particleRenderer += particle + } + // ToDo: long distance = always spawn? + if (it.count == 0) { + val velocity = it.offset * it.speed - spawn(it.position, Vec3d(velocity)) - } else { - for (i in 0 until it.count) { - val offset = Vec3d(it.offset) * { random.nextGaussian() } - val velocity = Vec3d(it.speed) * { random.nextGaussian() } + spawn(it.position, Vec3d(velocity)) + } else { + for (i in 0 until it.count) { + val offset = Vec3d(it.offset) * { random.nextGaussian() } + val velocity = Vec3d(it.speed) * { random.nextGaussian() } - spawn(it.position + offset, velocity) + spawn(it.position + offset, velocity) + } } } }, diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/sound/AudioPlayer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/sound/AudioPlayer.kt index 8351645a0..49ff13d86 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/sound/AudioPlayer.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/sound/AudioPlayer.kt @@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.sound import de.bixilon.kutil.collections.CollectionUtil.synchronizedListOf import de.bixilon.kutil.collections.CollectionUtil.toSynchronizedList +import de.bixilon.kutil.concurrent.pool.DefaultThreadPool import de.bixilon.kutil.concurrent.queue.Queue import de.bixilon.kutil.latch.CountUpAndDownLatch import de.bixilon.minosoft.config.profile.delegate.watcher.SimpleProfileDelegateWatcher.Companion.profileWatch @@ -125,7 +126,7 @@ class AudioPlayer( if (!initialized) { return } - playSound(soundManager[sound] ?: return, position, volume, pitch) + DefaultThreadPool += add@{ playSound(soundManager[sound] ?: return@add, position, volume, pitch) } } override fun play2DSound(sound: ResourceLocation, volume: Float, pitch: Float) {