mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-12 22:56:06 +09:00
reloading the engine will copy track states from the old instance, obsoleting audioMixerRenewHooks
This commit is contained in:
@@ -13,7 +13,6 @@ 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;
|
||||
@@ -1060,7 +1059,7 @@ public class App implements ApplicationListener {
|
||||
* Make sure to call App.audioMixerRenewHooks.remove(Object) whenever the class gets disposed of
|
||||
* 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> audioMixerRenewHooks = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Init stuffs which needs GL context
|
||||
@@ -1242,24 +1241,39 @@ public class App implements ApplicationListener {
|
||||
}
|
||||
|
||||
public static void renewAudioProcessor(int bufferSize) {
|
||||
// copy music tracks
|
||||
var dynaicTracks = audioMixer.getDynamicTracks();
|
||||
var staticTracks = audioMixer.getTracks();
|
||||
|
||||
audioManagerThread.interrupt();
|
||||
audioMixer.dispose();
|
||||
|
||||
audioBufferSize = bufferSize;
|
||||
audioMixer = new AudioMixer(audioBufferSize);
|
||||
|
||||
// paste music tracks
|
||||
for (int i = 0; i < audioMixer.getDynamicTracks().length; i++) {
|
||||
var track = audioMixer.getDynamicTracks()[i];
|
||||
dynaicTracks[i].copyStatusFrom(track);
|
||||
}
|
||||
for (int i = 0; i < audioMixer.getTracks().length; i++) {
|
||||
var track = audioMixer.getTracks()[i];
|
||||
staticTracks[i].copyStatusFrom(track);
|
||||
}
|
||||
|
||||
audioManagerThread = new Thread(new AudioManagerRunnable(audioMixer), "TerrarumAudioManager");
|
||||
audioManagerThread.setPriority(MAX_PRIORITY); // higher = more predictable; audio delay is very noticeable so it gets high priority
|
||||
audioManagerThread.start();
|
||||
|
||||
|
||||
for (var it : audioMixerRenewHooks.values()) {
|
||||
/*for (var it : audioMixerRenewHooks.values()) {
|
||||
try {
|
||||
it.invoke();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user