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