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()
|
particleQueue.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val time = System.currentTimeMillis()
|
||||||
for (particle in particles) {
|
for (particle in particles) {
|
||||||
if (particle.dead) {
|
if (particle.dead) {
|
||||||
toRemove += particle
|
toRemove += particle
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
particle.addVertex(transparentParticleMesh, particleMesh)
|
particle.addVertex(transparentParticleMesh, particleMesh, time)
|
||||||
}
|
}
|
||||||
particles -= toRemove
|
particles -= toRemove
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ abstract class Particle(
|
|||||||
|
|
||||||
// moving
|
// moving
|
||||||
val cameraPosition: Vec3d
|
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)
|
final override val velocity: Vec3d = Vec3d(velocity)
|
||||||
var previousPosition = position
|
var previousPosition = position
|
||||||
@ -93,6 +93,10 @@ abstract class Particle(
|
|||||||
spacing = Vec3(0.2)
|
spacing = Vec3(0.2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getCameraPosition(time: Long): Vec3d {
|
||||||
|
return VecUtil.lerp((time - lastTickTime) / ProtocolDefinition.TICK_TIMEd, previousPosition, position)
|
||||||
|
}
|
||||||
|
|
||||||
fun forceMove(delta: Vec3d) {
|
fun forceMove(delta: Vec3d) {
|
||||||
this.previousPosition = Vec3d(position)
|
this.previousPosition = Vec3d(position)
|
||||||
position += delta
|
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 {
|
companion object {
|
||||||
private const val MAGIC_VELOCITY_CONSTANT = 0.4
|
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) {
|
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?
|
abstract val texture: AbstractTexture?
|
||||||
|
|
||||||
|
|
||||||
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh) {
|
override fun addVertex(transparentMesh: ParticleMesh, particleMesh: ParticleMesh, time: Long) {
|
||||||
texture?.let {
|
texture?.let {
|
||||||
if (it.transparency == TextureTransparencies.TRANSLUCENT || color.alpha != 255) {
|
if (it.transparency == TextureTransparencies.TRANSLUCENT || color.alpha != 255) {
|
||||||
transparentMesh
|
transparentMesh
|
||||||
} else {
|
} else {
|
||||||
particleMesh
|
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 minUV: Vec2 = Vec2(0.0f, 0.0f)
|
||||||
var maxUV: Vec2 = Vec2(1.0f, 1.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 {
|
texture?.let {
|
||||||
if (it.transparency == TextureTransparencies.TRANSLUCENT || color.alpha != 255) {
|
if (it.transparency == TextureTransparencies.TRANSLUCENT || color.alpha != 255) {
|
||||||
transparentMesh
|
transparentMesh
|
||||||
} else {
|
} else {
|
||||||
particleMesh
|
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