mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
improve particle render performance
This commit is contained in:
parent
3ab21830d6
commit
f46f702920
@ -125,12 +125,13 @@ class ParticleRenderer(
|
||||
particleQueue.clear()
|
||||
}
|
||||
|
||||
val time = System.currentTimeMillis()
|
||||
for (particle in particles) {
|
||||
if (particle.dead) {
|
||||
toRemove += particle
|
||||
continue
|
||||
}
|
||||
particle.addVertex(transparentParticleMesh, particleMesh)
|
||||
particle.addVertex(transparentParticleMesh, particleMesh, time)
|
||||
}
|
||||
particles -= toRemove
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ abstract class Particle(
|
||||
|
||||
// moving
|
||||
val cameraPosition: Vec3d
|
||||
get() = VecUtil.lerp((System.currentTimeMillis() - lastTickTime) / ProtocolDefinition.TICK_TIMEd, previousPosition, position)
|
||||
get() = getCameraPosition(System.currentTimeMillis())
|
||||
|
||||
final override val velocity: Vec3d = Vec3d(velocity)
|
||||
var previousPosition = position
|
||||
@ -93,6 +93,10 @@ abstract class Particle(
|
||||
spacing = Vec3(0.2)
|
||||
}
|
||||
|
||||
fun getCameraPosition(time: Long): Vec3d {
|
||||
return VecUtil.lerp((time - lastTickTime) / ProtocolDefinition.TICK_TIMEd, previousPosition, position)
|
||||
}
|
||||
|
||||
fun forceMove(delta: Vec3d) {
|
||||
this.previousPosition = Vec3d(position)
|
||||
position += delta
|
||||
@ -186,7 +190,7 @@ abstract class Particle(
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh)
|
||||
abstract fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh, time: Long)
|
||||
|
||||
companion object {
|
||||
private const val MAGIC_VELOCITY_CONSTANT = 0.4
|
||||
|
@ -21,5 +21,5 @@ import glm_.vec3.Vec3d
|
||||
|
||||
abstract class NoRenderParticle(connection: PlayConnection, position: Vec3d, velocity: Vec3d, data: ParticleData?) : Particle(connection, position, velocity, data) {
|
||||
|
||||
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh) = Unit
|
||||
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh, time: Long) = Unit
|
||||
}
|
||||
|
@ -25,13 +25,13 @@ abstract class TextureParticle(connection: PlayConnection, position: Vec3d, velo
|
||||
abstract val texture: AbstractTexture?
|
||||
|
||||
|
||||
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh) {
|
||||
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh, time: Long) {
|
||||
texture?.let {
|
||||
if (it.transparency == TextureTransparencies.TRANSLUCENT || color.alpha != 255) {
|
||||
transparentMesh
|
||||
} else {
|
||||
particleMesh
|
||||
}.addVertex(cameraPosition, scale, it, color)
|
||||
}.addVertex(getCameraPosition(time), scale, it, color)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,13 +25,13 @@ abstract class AdvancedTextureParticle(connection: PlayConnection, position: Vec
|
||||
var minUV: Vec2 = Vec2(0.0f, 0.0f)
|
||||
var maxUV: Vec2 = Vec2(1.0f, 1.0f)
|
||||
|
||||
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh) {
|
||||
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh, time: Long) {
|
||||
texture?.let {
|
||||
if (it.transparency == TextureTransparencies.TRANSLUCENT || color.alpha != 255) {
|
||||
transparentMesh
|
||||
} else {
|
||||
particleMesh
|
||||
}.addVertex(cameraPosition, scale, it, color, minUV, maxUV)
|
||||
}.addVertex(getCameraPosition(time), scale, it, color, minUV, maxUV)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user