mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-16 00:26:07 +09:00
musicplayer: actively disables playback if jukebox is on
This commit is contained in:
@@ -282,12 +282,19 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
|
||||
|
||||
// method 1.
|
||||
// https://www.desmos.com/calculator/uzbjw10lna
|
||||
val K = 512.0
|
||||
return K.pow(-sqrt(1.0+x.sqr())) * K
|
||||
// val K = 512.0
|
||||
// return K.pow(-sqrt(1.0+x.sqr())) * K
|
||||
|
||||
|
||||
// method 2.
|
||||
// https://www.desmos.com/calculator/3xsac66rsp
|
||||
|
||||
|
||||
// method 3.
|
||||
// comparison with method 1.
|
||||
// https://www.desmos.com/calculator/rbteowef8v
|
||||
val Q = 2.0
|
||||
return 1.0 / cosh(Q * x).sqr()
|
||||
}
|
||||
|
||||
private fun FloatArray.applyVolume(volume: Float) = FloatArray(this.size) { (this[it] * volume) }
|
||||
|
||||
@@ -323,25 +323,22 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
protected var ambState = 0
|
||||
protected var ambFired = false
|
||||
|
||||
private fun stopMusic(song: MusicContainer?, callStopMusicHook: Boolean = true) {
|
||||
if (intermissionLength < Float.POSITIVE_INFINITY) {
|
||||
musicState = STATE_INTERMISSION
|
||||
intermissionAkku = 0f
|
||||
intermissionLength =
|
||||
if (diskJockeyingMode == "intermittent") 30f + 30f * Math.random().toFloat() else 0f // 30s-60s
|
||||
musicFired = false
|
||||
if (callStopMusicHook && musicStopHooks.isNotEmpty()) musicStopHooks.forEach {
|
||||
if (song != null) {
|
||||
it(song)
|
||||
}
|
||||
private fun stopMusic(song: MusicContainer?, callStopMusicHook: Boolean = true, customPauseLen: Float? = null) {
|
||||
musicState = STATE_INTERMISSION
|
||||
intermissionAkku = 0f
|
||||
intermissionLength = customPauseLen ?:
|
||||
if (diskJockeyingMode == "intermittent") 30f + 30f * Math.random().toFloat() else Float.POSITIVE_INFINITY // 30s-60s
|
||||
musicFired = false
|
||||
if (callStopMusicHook && musicStopHooks.isNotEmpty()) musicStopHooks.forEach {
|
||||
if (song != null) {
|
||||
it(song)
|
||||
}
|
||||
printdbg(this, "StopMusic Intermission: $intermissionLength seconds")
|
||||
}
|
||||
// printdbg(this, "StopMusic Intermission: $intermissionLength seconds")
|
||||
}
|
||||
|
||||
fun stopMusic(callStopMusicHook: Boolean = true, pauseLen: Float = Float.POSITIVE_INFINITY) {
|
||||
stopMusic(App.audioMixer.musicTrack.currentTrack, callStopMusicHook)
|
||||
intermissionLength = pauseLen
|
||||
stopMusic(App.audioMixer.musicTrack.currentTrack, callStopMusicHook, pauseLen)
|
||||
// printdbg(this, "StopMusic Intermission2: $intermissionLength seconds")
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.dyn4j.geometry.Vector2
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-11.
|
||||
*/
|
||||
class FixtureJukebox : Electric {
|
||||
class FixtureJukebox : Electric, PlaysMusic {
|
||||
|
||||
constructor() : super(
|
||||
BlockBox(BlockBox.NO_COLLISION, 2, 3),
|
||||
@@ -83,7 +83,7 @@ class FixtureJukebox : Electric {
|
||||
|
||||
// supress the normal background music playback
|
||||
if (musicIsPlaying && !flagDespawn) {
|
||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic()
|
||||
// (INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameactors
|
||||
|
||||
/**
|
||||
* A "marker" interface for fixtures that can play music.
|
||||
*/
|
||||
interface PlaysMusic {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user