mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 00:47:26 -04:00
particle: cache textures
That speeds up texture retrieving
This commit is contained in:
parent
47ee3d58df
commit
6032ed0bdc
@ -22,6 +22,7 @@ import de.bixilon.minosoft.data.registries.registries.registry.codec.IdentifierC
|
|||||||
import de.bixilon.minosoft.gui.rendering.particle.DefaultParticleFactory
|
import de.bixilon.minosoft.gui.rendering.particle.DefaultParticleFactory
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
import de.bixilon.minosoft.gui.rendering.particle.types.Particle
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
|
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
|
||||||
@ -32,6 +33,7 @@ data class ParticleType(
|
|||||||
val overrideLimiter: Boolean = false,
|
val overrideLimiter: Boolean = false,
|
||||||
val factory: ParticleFactory<out Particle>? = null,
|
val factory: ParticleFactory<out Particle>? = null,
|
||||||
) : RegistryItem() {
|
) : RegistryItem() {
|
||||||
|
var loadedTextures: Array<Texture> = emptyArray()
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return identifier.toString()
|
return identifier.toString()
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.particle
|
package de.bixilon.minosoft.gui.rendering.particle
|
||||||
|
|
||||||
import de.bixilon.kotlinglm.vec3.Vec3
|
import de.bixilon.kotlinglm.vec3.Vec3
|
||||||
|
import de.bixilon.kutil.array.ArrayUtil.cast
|
||||||
import de.bixilon.kutil.latch.AbstractLatch
|
import de.bixilon.kutil.latch.AbstractLatch
|
||||||
import de.bixilon.kutil.observer.DataObserver.Companion.observe
|
import de.bixilon.kutil.observer.DataObserver.Companion.observe
|
||||||
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minosoft
|
||||||
@ -29,6 +30,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.RenderSystem
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.base.layer.OpaqueLayer
|
import de.bixilon.minosoft.gui.rendering.system.base.layer.OpaqueLayer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.layer.TranslucentLayer
|
import de.bixilon.minosoft.gui.rendering.system.base.layer.TranslucentLayer
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.phases.SkipAll
|
import de.bixilon.minosoft.gui.rendering.system.base.phases.SkipAll
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
||||||
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
|
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
|
||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.packets.s2c.play.block.chunk.ChunkUtil.isInViewDistance
|
import de.bixilon.minosoft.protocol.packets.s2c.play.block.chunk.ChunkUtil.isInViewDistance
|
||||||
@ -87,8 +89,9 @@ class ParticleRenderer(
|
|||||||
|
|
||||||
private fun loadTextures() {
|
private fun loadTextures() {
|
||||||
for (particle in connection.registries.particleType) {
|
for (particle in connection.registries.particleType) {
|
||||||
for (file in particle.textures) {
|
val loaded: Array<Texture> = arrayOfNulls<Texture?>(particle.textures.size).cast()
|
||||||
context.textures.static.create(file)
|
for ((index, texture) in particle.textures.withIndex()) {
|
||||||
|
loaded[index] = context.textures.static.create(texture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.file.FileTe
|
|||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
|
|
||||||
abstract class SimpleTextureParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : TextureParticle(connection, position, velocity, data) {
|
abstract class SimpleTextureParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData? = null) : TextureParticle(connection, position, velocity, data) {
|
||||||
override var texture = this.data.type.textures.getOrNull(0)?.let { connection.rendering?.context?.textures?.static?.get(it) }
|
override var texture = this.data.type.loadedTextures.getOrNull(0)
|
||||||
var spriteDisabled = false
|
var spriteDisabled = false
|
||||||
|
|
||||||
|
|
||||||
@ -35,17 +35,17 @@ abstract class SimpleTextureParticle(connection: PlayConnection, position: Vec3d
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// calculate next texture
|
// calculate next texture
|
||||||
val nextTextureResourceLocation = data.type.textures[age / (maxAge / totalTextures + 1)]
|
val next = data.type.loadedTextures[age / (maxAge / totalTextures + 1)]
|
||||||
if (texture?.nullCast<FileTexture>()?.file == nextTextureResourceLocation) {
|
if (texture?.nullCast<FileTexture>()?.file == next) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
texture = connection.rendering?.context?.textures?.static?.get(nextTextureResourceLocation)
|
texture = next
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setRandomSprite() {
|
fun setRandomSprite() {
|
||||||
val textures = data.type.textures
|
val textures = data.type.loadedTextures
|
||||||
if (textures.isEmpty()) return
|
if (textures.isEmpty()) return
|
||||||
texture = connection.rendering?.context?.textures?.static?.get(textures.random())
|
texture = textures.random()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user