fix: panning dynamic source sending nan values

This commit is contained in:
minjaesong
2024-01-11 14:42:16 +09:00
parent ecd8f08419
commit df813712ff
17 changed files with 15 additions and 19 deletions

View File

@@ -18,7 +18,6 @@ import net.torvald.tsvm.peripheral.VMProgramRom
*/
class FixtureHomeComputer : FixtureBase {
@Transient override val spawnNeedsFloor = true
// TODO: write serialiser for TSVM && allow mods to have their own serialiser
private val vm = VM(ModMgr.getGdxFile("dwarventech", "bios").path(), 0x200000, TheRealWorld(), arrayOf(

View File

@@ -37,7 +37,7 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
private var breakBomb = false
private val distFalloff = 1024.0
private val distFalloff = 1536.0
private fun printdbg(msg: Any) {
if (true) App.printdbg("AudioAdapter ${track.name}", msg)
@@ -111,10 +111,12 @@ class MixerTrackProcessor(val buffertaille: Int, val rate: Int, val track: Terra
(track.filters[0] as BinoPan).pan = 0f
}
else if (track.trackingTarget is ActorWithBody) {
// FIXME this may cause filter to fill the output buffer with NaNs?
val relativeXpos = relativeXposition(AudioMixer.actorNowPlaying!!, track.trackingTarget as ActorWithBody)
track.volume = track.maxVolume * (1.0 - relativeXpos.absoluteValue.pow(0.5) / distFalloff)
(track.filters[0] as BinoPan).pan = ((2*asin(relativeXpos / distFalloff)) / Math.PI).toFloat()
track.volume = track.maxVolume * (1.0 - (relativeXpos.absoluteValue / distFalloff).pow(0.5)).coerceAtLeast(0.0)
(track.filters[0] as BinoPan).pan =
if (relativeXpos <= -distFalloff) -1f
else if (relativeXpos >= distFalloff) 1f
else ((2*asin(relativeXpos / distFalloff)) / Math.PI).toFloat()
}
}
}

View File

@@ -50,6 +50,7 @@ class BinoPan(var pan: Float, var earDist: Float = 0.18f): TerrarumAudioFilter()
val delayInSamples = (timeDiffMax * FastMath.sin(angle)).absoluteValue
val volMultDbThis = PANNING_CONST * pan.absoluteValue
val volMultFsThis = decibelsToFullscale(volMultDbThis).toFloat()
val volMUltFsOther = 1f / volMultFsThis
if (pan >= 0) {

View File

@@ -339,7 +339,7 @@ class TerrarumMusicGovernor : MusicGovernor() {
fun stopMusic(callStopMusicHook: Boolean = true, pauseLen: Float = Float.POSITIVE_INFINITY) {
stopMusic(AudioMixer.musicTrack.currentTrack, callStopMusicHook)
intermissionLength = pauseLen
printdbg(this, "StopMusic Intermission2: $intermissionLength seconds")
// printdbg(this, "StopMusic Intermission2: $intermissionLength seconds")
}
fun startMusic() {

View File

@@ -138,7 +138,7 @@ open class Electric : FixtureBase {
open class FixtureBase : ActorWithBody, CuedByTerrainChange {
@Transient open val spawnNeedsWall: Boolean = false
@Transient open val spawnNeedsFloor: Boolean = false
@Transient open val spawnNeedsFloor: Boolean = true
/** Real time, in nanoseconds */
@Transient var spawnRequestedTime: Long = 0L

View File

@@ -19,7 +19,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
class FixtureFurnaceAndAnvil : FixtureBase, CraftingStation {
@Transient override val spawnNeedsFloor = true
@Transient override val tags = listOf("metalworking")
constructor() : super(

View File

@@ -9,6 +9,8 @@ import org.dyn4j.geometry.Vector2
class FixtureLogicSignalEmitter : Electric {
@Transient override val spawnNeedsFloor = false
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 1),
nameFun = { Lang["ITEM_LOGIC_SIGNAL_EMITTER"] }

View File

@@ -22,7 +22,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
class FixtureSmelterBasic : FixtureBase, CraftingStation {
@Transient override val spawnNeedsFloor = true
@Transient override val tags = listOf("basicsmelter")
constructor() : super(

View File

@@ -13,7 +13,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
internal class FixtureStorageChest : FixtureBase {
@Transient override val spawnNeedsFloor = true
constructor() : super(
BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1),

View File

@@ -44,6 +44,8 @@ open class FixtureSwingingDoorBase : FixtureBase {
private var tilewiseDistToAxis = tw - twClosed
@Transient override val spawnNeedsWall = true
@Transient override val spawnNeedsFloor = false
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), Cvec(0)))
// the Cvec will be calculated dynamically on Update
@Transient override var shadeBoxList = arrayListOf(Lightbox(Hitbox(TILE_SIZED * tilewiseDistToAxis, 0.0, TILE_SIZED * twClosed, TILE_SIZED * th), Cvec(0)))

View File

@@ -7,7 +7,6 @@ import net.torvald.terrarum.blockproperties.Block
* Created by minjaesong on 2022-07-28.
*/
class FixtureSwingingDoorOak : FixtureSwingingDoorBase {
@Transient override val spawnNeedsWall = true
constructor() : super() {
_construct(
2,
@@ -25,7 +24,6 @@ class FixtureSwingingDoorOak : FixtureSwingingDoorBase {
}
class FixtureSwingingDoorEbony : FixtureSwingingDoorBase {
@Transient override val spawnNeedsWall = true
constructor() : super() {
_construct(
2,
@@ -43,7 +41,6 @@ class FixtureSwingingDoorEbony : FixtureSwingingDoorBase {
}
class FixtureSwingingDoorBirch : FixtureSwingingDoorBase {
@Transient override val spawnNeedsWall = true
constructor() : super() {
_construct(
2,
@@ -61,7 +58,6 @@ class FixtureSwingingDoorBirch : FixtureSwingingDoorBase {
}
class FixtureSwingingDoorRosewood : FixtureSwingingDoorBase {
@Transient override val spawnNeedsWall = true
constructor() : super() {
_construct(
2,

View File

@@ -19,6 +19,7 @@ import kotlin.properties.Delegates
internal class FixtureTapestry : FixtureBase {
@Transient override val spawnNeedsWall = true
@Transient override val spawnNeedsFloor = false
var artName = ""; private set
var artAuthor = ""; private set

View File

@@ -20,7 +20,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
internal class FixtureTikiTorch : FixtureBase {
@Transient override val spawnNeedsFloor = true
private val rndHash1 = (Math.random() * 256).toInt()
private val rndHash2 = (Math.random() * 256).toInt()

View File

@@ -10,7 +10,6 @@ import kotlin.math.roundToInt
*/
class FixtureTypewriter : FixtureBase {
@Transient override val spawnNeedsFloor = true
var typewriterKeymapName = "us_qwerty" // used to control the keyboard input behaviour
private set

View File

@@ -14,6 +14,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
class FixtureWallCalendar : FixtureBase {
@Transient override val spawnNeedsWall = true
@Transient override val spawnNeedsFloor = false
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 1, 1),

View File

@@ -17,7 +17,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
class FixtureWorkbench : FixtureBase, CraftingStation {
@Transient override val spawnNeedsFloor = true
@Transient override val tags = listOf("basiccrafting")
constructor() : super(

View File

@@ -19,8 +19,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
class FixtureWorldPortal : Electric {
@Transient override val spawnNeedsFloor = true
constructor() : super(
BlockBox(BlockBox.NO_COLLISION, 5, 2),
nameFun = { Lang["ITEM_WORLD_PORTAL"] },