fix: explosion cuts off randomly

This commit is contained in:
minjaesong
2024-02-17 00:30:04 +09:00
parent ffd470f2b4
commit 9caf9ab2fa
12 changed files with 110 additions and 41 deletions

View File

@@ -54,14 +54,14 @@ object ExplosionManager {
Thread {
while (true) {
try {
val job = runners.first { !it.executed }
val executor = Executors.newSingleThreadExecutor()
executor.submit(job.runner).get(500L, TimeUnit.MILLISECONDS)
executor.shutdownNow()
job.executed = true
runners.toList().firstOrNull { !it.executed }?.let { job ->
val executor = Executors.newSingleThreadExecutor()
executor.submit(job.runner).get(500L, TimeUnit.MILLISECONDS)
executor.shutdownNow()
job.executed = true
}
}
catch (_: TimeoutException) { }
catch (_: NoSuchElementException) { }
Thread.sleep(50L)
}

View File

@@ -38,10 +38,36 @@ open class ActorPrimedBomb(
) {
this.flagDespawn()
}
@Transient private val fuseSound = MusicContainer(
"fuse", ModMgr.getFile("basegame", "audio/effects/explosion/fuse.ogg")
) {
this.flagDespawn()
}
@Transient private val fuseSoundCont = MusicContainer(
"fuse_continue", ModMgr.getFile("basegame", "audio/effects/explosion/fuse_continue.ogg")
) {
this.flagDespawn()
}
private var fuseSoundStatus = 0 // this value must be stored into the savegame
@Transient private var fuseSoundFired = false
override val stopMusicOnDespawn: Boolean
get() = this.isVisible
override fun updateImpl(delta: Float) {
super.updateImpl(delta)
if (!fuseSoundFired && fuse > 0f) {
fuseSoundFired = true
if (fuseSoundStatus == 0) {
startAudio(fuseSound, 2.0)
fuseSoundStatus = 1
}
else
startAudio(fuseSoundCont, 2.0)
}
fuse -= delta
if (fuse <= 0f && !explosionCalled) {
@@ -57,6 +83,7 @@ open class ActorPrimedBomb(
) {
physProp.usePhysics = false
this.isVisible = false // or play explosion anim
stopAudio(fuseSound)
startAudio(boomSound, 10.0)
}
}
@@ -65,6 +92,8 @@ open class ActorPrimedBomb(
override fun dispose() {
super.dispose()
boomSound.dispose()
fuseSound.dispose()
fuseSoundCont.dispose()
}
}