mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
varying amplitude for throwing sound
This commit is contained in:
@@ -139,8 +139,8 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
||||
val actorContainerActive = SortedArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
val actorContainerInactive = SortedArrayList<Actor>(ACTORCONTAINER_INITIAL_SIZE)
|
||||
|
||||
val actorAdditionQueue = ArrayList<Pair<Actor, Throwable>>()
|
||||
val actorRemovalQueue = ArrayList<Pair<Actor, Throwable>>()
|
||||
val actorAdditionQueue = ArrayList<Triple<Actor, Throwable, (Actor) -> Unit>>() // actor, stacktrace object, onSpawn
|
||||
val actorRemovalQueue = ArrayList<Triple<Actor, Throwable, (Actor) -> Unit>>() // actor, stacktrace object, onDespawn
|
||||
|
||||
/**
|
||||
* ## BIG NOTE: Calculated actor distance is the **Euclidean distance SQUARED**
|
||||
@@ -357,7 +357,12 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
||||
*/
|
||||
open fun queueActorRemoval(actor: Actor?) {
|
||||
if (actor == null) return
|
||||
actorRemovalQueue.add(actor to StackTraceRecorder())
|
||||
actorRemovalQueue.add(Triple(actor, StackTraceRecorder(), {}))
|
||||
}
|
||||
|
||||
open fun queueActorRemoval(actor: Actor?, onDespawn: (Actor) -> Unit) {
|
||||
if (actor == null) return
|
||||
actorRemovalQueue.add(Triple(actor, StackTraceRecorder(), onDespawn))
|
||||
}
|
||||
|
||||
protected open fun forceRemoveActor(actor: Actor, caller: Throwable = StackTraceRecorder()) {
|
||||
@@ -386,11 +391,16 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
||||
* If the actor is null, this function will do nothing.
|
||||
*/
|
||||
open fun queueActorAddition(actor: Actor?) {
|
||||
// printdbg(this, "New actor $actor")
|
||||
if (actor == null) return
|
||||
actorAdditionQueue.add(actor to StackTraceRecorder())
|
||||
actorAdditionQueue.add(Triple(actor, StackTraceRecorder(), {}))
|
||||
}
|
||||
|
||||
open fun queueActorAddition(actor: Actor?, onSpawn: (Actor) -> Unit) {
|
||||
if (actor == null) return
|
||||
actorAdditionQueue.add(Triple(actor, StackTraceRecorder(), onSpawn))
|
||||
}
|
||||
|
||||
|
||||
fun isActive(ID: Int): Boolean =
|
||||
if (actorContainerActive.size == 0)
|
||||
false
|
||||
|
||||
@@ -913,7 +913,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
// process actor addition requests
|
||||
val addCueCpy = actorAdditionQueue.toList()
|
||||
addCueCpy.forEach { forceAddActor(it.first, it.second) }
|
||||
addCueCpy.forEach {
|
||||
forceAddActor(it.first, it.second)
|
||||
it.third(it.first)
|
||||
}
|
||||
actorAdditionQueue.removeAll(addCueCpy)
|
||||
// determine whether the inactive actor should be activated
|
||||
wakeDormantActors()
|
||||
@@ -923,7 +926,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
killOrKnockdownActors()
|
||||
// process actor removal requests
|
||||
val remCueCpy = actorRemovalQueue.toList()
|
||||
remCueCpy.forEach { forceRemoveActor(it.first, it.second) }
|
||||
remCueCpy.forEach {
|
||||
forceRemoveActor(it.first, it.second)
|
||||
it.third(it.first)
|
||||
}
|
||||
actorRemovalQueue.removeAll(remCueCpy)
|
||||
// update particles
|
||||
particlesContainer.toList().forEach { if (!it.flagDespawn) particlesActive++; it.update(delta) }
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.torvald.terrarum.gameactors.Lightbox
|
||||
import net.torvald.terrarum.gameactors.PhysProperties
|
||||
import net.torvald.terrarum.modulebasegame.ExplosionManager
|
||||
import kotlin.math.log10
|
||||
import kotlin.math.pow
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-07-12.
|
||||
@@ -20,10 +21,11 @@ open class ActorLobbed(throwPitch: Float) : ActorWithBody() {
|
||||
|
||||
protected constructor() : this(1f)
|
||||
|
||||
@Transient private val pitch = throwPitch.coerceIn(0.5f, 2f)
|
||||
@Transient private val whooshSound = MusicContainer(
|
||||
"throw_low_short", ModMgr.getFile("basegame", "audio/effects/throwing/throw_low_short.wav"),
|
||||
toRAM = true,
|
||||
samplingRateOverride = 48000f * throwPitch.coerceIn(0.5f, 2f)
|
||||
samplingRateOverride = 48000f * pitch
|
||||
)
|
||||
|
||||
init {
|
||||
@@ -38,7 +40,8 @@ open class ActorLobbed(throwPitch: Float) : ActorWithBody() {
|
||||
super.updateImpl(delta)
|
||||
if (!soundFired) {
|
||||
soundFired = true
|
||||
startAudio(whooshSound, 1.0)
|
||||
val amp = 1.65 * (pitch - 0.495)
|
||||
startAudio(whooshSound, amp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user