fix: bad cacheing behaviour

This commit is contained in:
minjaesong
2024-04-02 23:23:16 +09:00
parent 94152afcac
commit 9a8c91562e
6 changed files with 21 additions and 10 deletions

View File

@@ -1250,6 +1250,8 @@ public class App implements ApplicationListener {
}
public static void reloadAudioProcessor(int bufferSize) {
printdbg("App", "Reloading audio precessor with buffer size of" + bufferSize);
// copy music tracks
var oldDynamicTracks = audioMixer.getDynamicTracks();
var oldStaticTracks = audioMixer.getTracks();
@@ -1305,6 +1307,8 @@ public class App implements ApplicationListener {
}
}
printdbg("App", "Audio precessor reloaded with buffer size of" + bufferSize);
}
@@ -1986,7 +1990,6 @@ public class App implements ApplicationListener {
public static void playGUIsound(MusicContainer sound) { playGUIsound(sound, 1.0, 0.0f); }
public static void playGUIsoundHigh(MusicContainer sound, double volume, float pan) {
// TODO when a sound is played thru this function, other sound play calls thru playGUIsound are ignored until this sound finishes playing
var it = audioMixer.getFreeGuiTrackNoMatterWhat();
highPrioritySoundPlaying = true;
it.stop();

View File

@@ -210,7 +210,9 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
allocateStreamBuf(track)
}
streamBuf!!.fetchBytes()
if (track.currentTrack == null) throw IllegalStateException("Track ${track.name} is playing but also has null music track")
streamBuf?.fetchBytes() ?: throw NullPointerException("Null StreamBuf for ${track.name}")
}
var samplesL1: FloatArray

View File

@@ -8,11 +8,11 @@ class MusicCache(val trackName: String) : Disposable {
private val cache = HashMap<String, MusicContainer>()
fun getOrPut(music: MusicContainer?): MusicContainer? {
if (music != null && music.toRAM) { // for now only the on-the-RAM tracks are getting cached
println("Cacheing music ${music.name} for track $trackName")
if (music != null && !music.toRAM)
return music
if (music != null && music.toRAM) // for now only the on-the-RAM tracks are getting cached
return cache.getOrPut(music.name) { music.makeCopy() }
}
else return null
return null
}
override fun dispose() {

View File

@@ -44,12 +44,18 @@ class TerrarumAudioMixerTrack(
var currentTrack: MusicContainer? = null
set(value) {
field = musicCache.getOrPut(value)
field = if (value == null)
null
else
musicCache.getOrPut(value)
}
var nextTrack: MusicContainer? = null
set(value) {
field = musicCache.getOrPut(value)
field = if (value == null)
null
else
musicCache.getOrPut(value)
}
var volume: TrackVolume = 1.0

View File

@@ -267,7 +267,7 @@ object PickaxeCore {
private val soundCue = MusicContainer(
"pickaxe_sound_cue",
ModMgr.getFile("basegame", "audio/effects/accessibility/pickaxe_valuable.ogg"),
toRAM = true
toRAM = false
).also {
App.disposables.add(it)
}

View File

@@ -286,7 +286,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
object UIItemAccessibilityUtil {
// TODO have multiple bop instances (num of copies equal to guiTracks), then play the track with its index according to getFreeGuiTrack()
fun playHapticCursorHovered() {
App.playGUIsound(CommonResourcePool.getAs("sound:haptic_bup"), 0.1666666)
App.playGUIsound(CommonResourcePool.getAs("sound:haptic_bup"), 0.3)
}
fun playHapticPushedDown() {
App.playGUIsoundHigh(CommonResourcePool.getAs("sound:haptic_bip"), 0.5)