do audio async, fix packet particles, text flow (chat) caching

This commit is contained in:
Bixilon 2022-02-05 19:16:26 +01:00
parent 8895a29f77
commit 5707631d53
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 24 additions and 20 deletions

View File

@ -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) {

View File

@ -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<ParticleSpawnEvent> {
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)
}
}
}
},

View File

@ -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) {