mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 11:09:20 +01:00
Fix a race when spawning ocelot log particles
This commit is contained in:
parent
69dcca71dc
commit
e3ccfeba9f
@ -13,12 +13,27 @@ import ocelot.desktop.ui.particle.Particle
|
||||
import scala.util.Random
|
||||
|
||||
trait OcelotLogParticleNode extends Node {
|
||||
private var queuedParticles: Int = 0
|
||||
|
||||
eventHandlers += {
|
||||
case BrainEvent(OcelotInterface.LogEvent.CardToUser(_, _)) =>
|
||||
synchronized(queuedParticles += 1)
|
||||
}
|
||||
|
||||
override def update(): Unit = {
|
||||
super.update()
|
||||
spawnParticles()
|
||||
}
|
||||
|
||||
private def spawnParticles(): Unit = synchronized {
|
||||
val system = UiHandler.root.workspaceView.particleSystem
|
||||
if (system.count[LogParticle](Some(this)) < MaxLogParticles) {
|
||||
val toSpawn = queuedParticles min (MaxLogParticles - system.count[LogParticle](Some(this))) max 0
|
||||
|
||||
for (_ <- 0 until toSpawn) {
|
||||
system.add(new LogParticle)
|
||||
}
|
||||
|
||||
queuedParticles = 0
|
||||
}
|
||||
|
||||
private class LogParticle extends Particle(time = -LogParticleGrow, speed = LogParticleMoveSpeed, origin = Some(this)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user