particle: disable campfire sprite texture, fix mass ticking if ThreadPool was busy

This commit is contained in:
Bixilon 2021-05-28 18:09:50 +02:00
parent db23cf8047
commit 80985053cf
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 16 additions and 11 deletions

View File

@ -43,16 +43,10 @@ class CampfireSmokeParticle(connection: PlayConnection, particleRenderer: Partic
this.velocity assign Vec3(velocity.x, velocity.y + (random.nextFloat() / 500.0f), velocity.z)
movement = false
spriteDisabled = true
setRandomSprite()
}
override fun tick(deltaTime: Int) {
super.tick(deltaTime)
if (dead) {
return
}
}
override fun realTick() {
super.realTick()
val horizontal = { (random.nextFloat() / 5000.0f * (if (random.nextBoolean()) 1.0f else -1.0f)) }

View File

@ -21,11 +21,12 @@ import glm_.vec3.Vec3
abstract class SimpleTextureParticle(connection: PlayConnection, particleRenderer: ParticleRenderer, position: Vec3, velocity: Vec3, data: ParticleData) : TextureParticle(connection, particleRenderer, position, velocity, data) {
override var texture = particleRenderer.renderWindow.textures.allTextures[data.type.textures.first()]!!
var spriteDisabled = false
private fun checkSpriteTexture() {
val totalTextures = data.type.textures.size
if (totalTextures <= 1) {
if (totalTextures <= 1 || spriteDisabled) {
return
}
// calculate next texture
@ -36,6 +37,10 @@ abstract class SimpleTextureParticle(connection: PlayConnection, particleRendere
texture = particleRenderer.renderWindow.textures.allTextures[nextTextureResourceLocation]!!
}
fun setRandomSprite() {
texture = particleRenderer.renderWindow.textures.allTextures[data.type.textures.random(random)]!!
}
override fun tick(deltaTime: Int) {
super.tick(deltaTime)
if (dead) {

View File

@ -138,7 +138,7 @@ class PlayConnection(
}
TimeWorker.addTask(velocityHandlerTask)
worldTickTask = TimeWorkerTask(ProtocolDefinition.TICK_TIME) {
worldTickTask = TimeWorkerTask(ProtocolDefinition.TICK_TIME, maxDelayTime = ProtocolDefinition.TICK_TIME / 2) {
world.realTick()
}
TimeWorker.addTask(worldTickTask)

View File

@ -36,9 +36,11 @@ class ThreadPool(
state = ThreadPoolStates.STARTED
}
val pendingCount: Int
get() = pending.size
@Synchronized
private fun checkThreads() {
fun wait() {
try {
availableThreads += Thread.currentThread()

View File

@ -23,6 +23,9 @@ object TimeWorker {
if (task.getsExecuted) {
return@execute
}
if (System.currentTimeMillis() - currentTime >= task.maxDelayTime) {
return@execute
}
task.getsExecuted = true
task.runnable.run()
task.lastExecution = currentTime

View File

@ -3,6 +3,7 @@ package de.bixilon.minosoft.util.task.time
data class TimeWorkerTask(
val interval: Int,
val runOnce: Boolean = false,
val maxDelayTime: Int = Int.MAX_VALUE,
val runnable: Runnable,
) {
var getsExecuted: Boolean = false