mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 11:04:05 +09:00
ambient audio stuffs
This commit is contained in:
@@ -12,6 +12,7 @@ import net.torvald.terrarum.Terrarum.getPlayerSaveFiledesc
|
||||
import net.torvald.terrarum.Terrarum.getWorldSaveFiledesc
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.dsp.Gain
|
||||
import net.torvald.terrarum.blockproperties.BlockPropUtil
|
||||
import net.torvald.terrarum.blockstats.MinimapComposer
|
||||
import net.torvald.terrarum.blockstats.TileSurvey
|
||||
@@ -312,6 +313,16 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
MaterialCodex[prop.material].sondrefl
|
||||
}
|
||||
)
|
||||
|
||||
TileSurvey.submitProposal(
|
||||
TileSurvey.SurveyProposal(
|
||||
"basegame.Ingame.openness", 73, 73, 2, 4
|
||||
) { world, x, y ->
|
||||
val tileProp = BlockCodex[world.getTileFromTerrain(x, y)]
|
||||
val wallProp = BlockCodex[world.getTileFromWall(x, y)]
|
||||
(!tileProp.isSolid && !wallProp.isSolid).toInt().toFloat()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
data class NewGameParams(
|
||||
@@ -904,6 +915,10 @@ open class TerrarumIngame(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
App.audioMixer.convolveBusOpen.volume = (1.0 - ratio1).pow(0.75)
|
||||
App.audioMixer.convolveBusCave.volume = 0.0
|
||||
}
|
||||
val openness = (TileSurvey.getRatio("basegame.Ingame.openness") ?: 0.0).times(1.74).coerceIn(0.0, 1.0)
|
||||
(App.audioMixer.ambientTrack.filters[3] as Gain).gain = openness.pow(2.0 / 3.0).toFloat()
|
||||
|
||||
|
||||
|
||||
actorNowPlaying?.let { if (WORLD_UPDATE_TIMER % 4 == 1) updateWorldGenerator(actorNowPlaying!!) }
|
||||
|
||||
|
||||
@@ -269,22 +269,22 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
}
|
||||
|
||||
private val ambients: List<MusicContainer> =
|
||||
File(App.customAmbientDir).listFiles()?.mapNotNull {
|
||||
ModMgr.getFilesFromEveryMod("audio/ambient/").flatMap { it.second.listFiles()?.toList() ?: emptyList() }.mapNotNull {
|
||||
printdbg(this, "Ambient: ${it.absolutePath}")
|
||||
try {
|
||||
MusicContainer(
|
||||
it.nameWithoutExtension.replace('_', ' ').split(" ").map { it.capitalize() }.joinToString(" "),
|
||||
it,
|
||||
Gdx.audio.newMusic(Gdx.files.absolute(it.absolutePath))
|
||||
Gdx.audio.newMusic(Gdx.files.absolute(it.absolutePath)).also {
|
||||
it.isLooping = true
|
||||
}
|
||||
) { stopAmbient() }
|
||||
}
|
||||
catch (e: GdxRuntimeException) {
|
||||
e.printStackTrace()
|
||||
null
|
||||
}
|
||||
} ?: emptyList() // TODO test code
|
||||
|
||||
private var ambientsBin: ArrayList<Int> = ArrayList(ambients.indices.toList().shuffled())
|
||||
}
|
||||
|
||||
private val musicStartHooks = ArrayList<(MusicContainer) -> Unit>()
|
||||
private val musicStopHooks = ArrayList<(MusicContainer) -> Unit>()
|
||||
@@ -367,30 +367,19 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
}
|
||||
}
|
||||
|
||||
// MixerTrackProcessor will call this function externally to make gapless playback work
|
||||
fun pullNextAmbientTrack(): MusicContainer {
|
||||
// prevent same song to play twice in row (for the most time)
|
||||
if (ambientsBin.isEmpty()) {
|
||||
ambientsBin = ArrayList(ambients.indices.toList().shuffled())
|
||||
}
|
||||
return ambients[ambientsBin.removeAt(0)]
|
||||
}
|
||||
|
||||
private fun stopAmbient() {
|
||||
ambState = STATE_INTERMISSION
|
||||
intermissionAkku = 0f
|
||||
intermissionLength = 30f + 30f * Math.random().toFloat() // 30s-60s
|
||||
ambFired = false
|
||||
printdbg(this, "stopAmbient Intermission: $intermissionLength seconds")
|
||||
App.audioMixer.ambientTrack.nextTrack = currentAmbientTrack
|
||||
}
|
||||
|
||||
private fun startAmbient(song: MusicContainer) {
|
||||
currentAmbientTrack = song
|
||||
App.audioMixer.startAmb(song)
|
||||
printdbg(this, "startAmbient Now playing: $song")
|
||||
// INGAME.sendNotification("Now Playing $EMDASH ${song.name}")
|
||||
ambState = STATE_PLAYING
|
||||
}
|
||||
|
||||
private lateinit var currentAmbientTrack: MusicContainer
|
||||
|
||||
override fun update(ingame: IngameInstance, delta: Float) {
|
||||
// start the song queueing if there is one to play
|
||||
@@ -422,7 +411,17 @@ class TerrarumMusicGovernor : MusicGovernor() {
|
||||
STATE_FIREPLAY -> {
|
||||
if (!ambFired) {
|
||||
ambFired = true
|
||||
startAmbient(pullNextAmbientTrack())
|
||||
|
||||
val season = ingame.world.worldTime.ecologicalSeason
|
||||
val seasonName = when (season) {
|
||||
in 0f..2f -> "autumn"
|
||||
in 2f..3f -> "summer"
|
||||
in 3f..5f -> "autumn"
|
||||
else -> "winter"
|
||||
}
|
||||
val track = ambients.filter { it.name.lowercase().startsWith(seasonName) }.random()
|
||||
|
||||
startAmbient(track)
|
||||
}
|
||||
}
|
||||
STATE_PLAYING -> {
|
||||
|
||||
@@ -266,6 +266,11 @@ class TitleScreen(batch: FlippingSpriteBatch) : IngameInstance(batch) {
|
||||
App.bogoflops = maxOf(App.bogoflops, bogoflops)
|
||||
|
||||
|
||||
App.audioMixer.ambientTrack.let {
|
||||
it.stop()
|
||||
it.currentTrack = null
|
||||
it.nextTrack = null
|
||||
}
|
||||
App.audioMixer.reset()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user