mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fix: actors having stale musictrack reference after the audioengine reloading
This commit is contained in:
@@ -13,6 +13,7 @@ import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.badlogic.gdx.utils.JsonValue;
|
||||
import com.github.strikerx3.jxinput.XInputDevice;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.text.Charsets;
|
||||
import net.torvald.getcpuname.GetCpuName;
|
||||
import net.torvald.terrarum.audio.AudioMixer;
|
||||
@@ -1063,9 +1064,10 @@ public class App implements ApplicationListener {
|
||||
|
||||
/**
|
||||
* Make sure to call App.audioMixerRenewHooks.remove(Object) whenever the class gets disposed of
|
||||
* <p>
|
||||
* Key: the class that calls the hook, value: the actual operation (function)
|
||||
*/
|
||||
//public static HashMap<Object, Function0> audioMixerRenewHooks = new HashMap<>();
|
||||
public static HashMap<Object, Function0> audioMixerReloadHooks = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Init stuffs which needs GL context
|
||||
@@ -1248,8 +1250,8 @@ public class App implements ApplicationListener {
|
||||
|
||||
public static void reloadAudioProcessor(int bufferSize) {
|
||||
// copy music tracks
|
||||
var dynaicTracks = audioMixer.getDynamicTracks();
|
||||
var staticTracks = audioMixer.getTracks();
|
||||
var oldDynamicTracks = audioMixer.getDynamicTracks();
|
||||
var oldStaticTracks = audioMixer.getTracks();
|
||||
|
||||
audioManagerThread.interrupt();
|
||||
audioMixer.dispose();
|
||||
@@ -1260,11 +1262,32 @@ public class App implements ApplicationListener {
|
||||
// paste music tracks
|
||||
for (int i = 0; i < audioMixer.getDynamicTracks().length; i++) {
|
||||
var track = audioMixer.getDynamicTracks()[i];
|
||||
dynaicTracks[i].copyStatusFrom(track);
|
||||
oldDynamicTracks[i].copyStatusTo(track);
|
||||
|
||||
var ingame = Terrarum.INSTANCE.getIngame();
|
||||
if (ingame != null) {
|
||||
// update track references for the actors
|
||||
for (var actor : ingame.getActorContainerActive()) {
|
||||
var tracks = actor.getMusicTracks();
|
||||
for (var trackMusic : tracks.keySet()) {
|
||||
if (tracks.get(trackMusic).equals(oldDynamicTracks[i])) {
|
||||
tracks.put(trackMusic, track);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (var actor : ingame.getActorContainerInactive()) {
|
||||
var tracks = actor.getMusicTracks();
|
||||
for (var trackMusic : tracks.keySet()) {
|
||||
if (tracks.get(trackMusic).equals(oldDynamicTracks[i])) {
|
||||
tracks.put(trackMusic, track);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < audioMixer.getTracks().length; i++) {
|
||||
var track = audioMixer.getTracks()[i];
|
||||
staticTracks[i].copyStatusFrom(track);
|
||||
oldStaticTracks[i].copyStatusTo(track);
|
||||
}
|
||||
|
||||
audioManagerThread = new Thread(new AudioManagerRunnable(audioMixer), "TerrarumAudioManager");
|
||||
@@ -1272,14 +1295,14 @@ public class App implements ApplicationListener {
|
||||
audioManagerThread.start();
|
||||
|
||||
|
||||
/*for (var it : audioMixerRenewHooks.values()) {
|
||||
for (var it : audioMixerReloadHooks.values()) {
|
||||
try {
|
||||
it.invoke();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class TerrarumAudioMixerTrack(
|
||||
var playStartedTime = 0L; internal set
|
||||
|
||||
|
||||
fun copyStatusFrom(other: TerrarumAudioMixerTrack) {
|
||||
fun copyStatusTo(other: TerrarumAudioMixerTrack) {
|
||||
other.pullNextTrack = this.pullNextTrack
|
||||
other.currentTrack = this.currentTrack
|
||||
other.nextTrack = this.nextTrack
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||
import net.torvald.terrarum.audio.AudioMixer.Companion.DEFAULT_FADEOUT_LEN
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack
|
||||
import net.torvald.terrarum.audio.dsp.Convolv
|
||||
import net.torvald.terrarum.audio.dsp.LoFi
|
||||
import net.torvald.terrarum.audio.dsp.NullFilter
|
||||
@@ -90,7 +91,9 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
}
|
||||
|
||||
|
||||
// App.audioMixerRenewHooks[this] = { stopGracefully() }
|
||||
App.audioMixerReloadHooks[this] = {
|
||||
loadConvolver(musicTracks[musicNowPlaying])
|
||||
}
|
||||
}
|
||||
|
||||
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TILE_SIZED * 2, TILE_SIZED * 3), Cvec(0.44f, 0.41f, 0.40f, 0.2f)))
|
||||
@@ -141,13 +144,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
discCurrentlyPlaying = index
|
||||
|
||||
App.audioMixer.requestFadeOut(App.audioMixer.musicTrack, DEFAULT_FADEOUT_LEN / 2f) {
|
||||
startAudio(musicNowPlaying!!) {
|
||||
it.filters[filterIndex] = Phono(
|
||||
"basegame",
|
||||
"audio/convolution/Soundwoofer - large_speaker_Marshall JVM 205C SM57 A 0 0 1.bin",
|
||||
0f, 5f / 16f
|
||||
)
|
||||
}
|
||||
startAudio(musicNowPlaying!!) { loadConvolver(it) }
|
||||
}
|
||||
|
||||
|
||||
@@ -167,6 +164,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
fun stopGracefully() {
|
||||
stopDiscPlayback()
|
||||
(INGAME.musicGovernor as TerrarumMusicGovernor).stopMusic(this, pauseLen = (INGAME.musicGovernor as TerrarumMusicGovernor).getRandomMusicInterval())
|
||||
|
||||
}
|
||||
|
||||
override fun drawBody(frameDelta: Float, batch: SpriteBatch) {
|
||||
@@ -214,6 +212,14 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
playMech.currentFrame = 0
|
||||
}
|
||||
|
||||
private fun loadConvolver(it: TerrarumAudioMixerTrack?) {
|
||||
it?.filters?.set(filterIndex, Phono(
|
||||
"basegame",
|
||||
"audio/convolution/Soundwoofer - large_speaker_Marshall JVM 205C SM57 A 0 0 1.bin",
|
||||
0f, 5f / 16f
|
||||
))
|
||||
}
|
||||
|
||||
private fun unloadConvolver(music: MusicContainer?) {
|
||||
if (music != null) {
|
||||
musicTracks[music]?.let {
|
||||
@@ -232,7 +238,7 @@ class FixtureJukebox : Electric, PlaysMusic {
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
// App.audioMixerRenewHooks.remove(this)
|
||||
App.audioMixerReloadHooks.remove(this)
|
||||
super.dispose()
|
||||
// testMusic.gdxMusic.dispose()
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App.*
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.SAMPLING_RATE
|
||||
import net.torvald.terrarum.audio.decibelsToFullscale
|
||||
import net.torvald.terrarum.audio.dsp.Lowpass
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
@@ -393,19 +395,29 @@ class UIInventoryFull(
|
||||
App.audioMixer.requestFadeOut(App.audioMixer.fadeBus, 0.25, decibelsToFullscale(-3.0))
|
||||
}
|
||||
|
||||
private var shouldIFadeIn: Boolean? = null
|
||||
|
||||
override fun doClosing(delta: Float) {
|
||||
super.doClosing(delta)
|
||||
transitionPanel.uis.forEach { it.opacity = FastMath.pow(opacity, 0.5f) }
|
||||
INGAME.resume()
|
||||
INGAME.setTooltipMessage(null)
|
||||
|
||||
App.audioMixer.requestLowpassOut(0.25)
|
||||
App.audioMixer.requestFadeIn(App.audioMixer.fadeBus, 0.25, 1.0)
|
||||
if (shouldIFadeIn == null) {
|
||||
shouldIFadeIn = (App.audioMixer.fadeBus.getFilter<Lowpass>().cutoff < SAMPLING_RATE / 2)
|
||||
}
|
||||
|
||||
if (shouldIFadeIn == true) {
|
||||
App.audioMixer.requestLowpassOut(0.25)
|
||||
App.audioMixer.requestFadeIn(App.audioMixer.fadeBus, 0.25, 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun endOpening(delta: Float) {
|
||||
super.endOpening(delta)
|
||||
transitionPanel.uis.forEach { it.opacity = FastMath.pow(opacity, 0.5f) }
|
||||
|
||||
shouldIFadeIn = null
|
||||
}
|
||||
|
||||
override fun endClosing(delta: Float) {
|
||||
@@ -417,6 +429,8 @@ class UIInventoryFull(
|
||||
tooltipShowing.clear()
|
||||
|
||||
// printdbg(this, "Clearing out tooltipShowing")
|
||||
|
||||
shouldIFadeIn = null
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack
|
||||
import net.torvald.terrarum.audio.TerrarumAudioMixerTrack.Companion.SAMPLING_RATE
|
||||
import net.torvald.terrarum.audio.dsp.Lowpass
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
|
||||
@@ -53,10 +56,17 @@ class UISoundControlPanel(remoCon: UIRemoCon?) : UICanvas() {
|
||||
}
|
||||
|
||||
override fun renderUI(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
|
||||
// undo sound fadeout/muting when this panel is opened
|
||||
if (handler.openCloseCounter == 0f && App.audioMixer.fadeBus.getFilter<Lowpass>().cutoff < SAMPLING_RATE / 2) {
|
||||
App.audioMixer.requestLowpassOut(0.25)
|
||||
App.audioMixer.requestFadeIn(App.audioMixer.fadeBus, 0.25, 1.0)
|
||||
}
|
||||
|
||||
ControlPanelCommon.render("basegame.soundcontrolpanel", width, batch)
|
||||
uiItems.forEach { it.render(frameDelta, batch, camera) }
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user