mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
audio engine: resize buffer without restarting the game
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;
|
||||
@@ -1055,6 +1056,12 @@ public class App implements ApplicationListener {
|
||||
public static AudioMixer audioMixer;
|
||||
public static int audioBufferSize;
|
||||
|
||||
/**
|
||||
* 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<>();
|
||||
|
||||
/**
|
||||
* Init stuffs which needs GL context
|
||||
*/
|
||||
@@ -1243,6 +1250,16 @@ public class App implements ApplicationListener {
|
||||
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()) {
|
||||
try {
|
||||
it.invoke();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user