mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 04:24:05 +09:00
fix: bad cacheing behaviour
This commit is contained in:
@@ -1250,6 +1250,8 @@ public class App implements ApplicationListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadAudioProcessor(int bufferSize) {
|
public static void reloadAudioProcessor(int bufferSize) {
|
||||||
|
printdbg("App", "Reloading audio precessor with buffer size of" + bufferSize);
|
||||||
|
|
||||||
// copy music tracks
|
// copy music tracks
|
||||||
var oldDynamicTracks = audioMixer.getDynamicTracks();
|
var oldDynamicTracks = audioMixer.getDynamicTracks();
|
||||||
var oldStaticTracks = audioMixer.getTracks();
|
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 playGUIsound(MusicContainer sound) { playGUIsound(sound, 1.0, 0.0f); }
|
||||||
|
|
||||||
public static void playGUIsoundHigh(MusicContainer sound, double volume, float pan) {
|
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();
|
var it = audioMixer.getFreeGuiTrackNoMatterWhat();
|
||||||
highPrioritySoundPlaying = true;
|
highPrioritySoundPlaying = true;
|
||||||
it.stop();
|
it.stop();
|
||||||
|
|||||||
@@ -210,7 +210,9 @@ class MixerTrackProcessor(bufferSize: Int, val rate: Int, val track: TerrarumAud
|
|||||||
allocateStreamBuf(track)
|
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
|
var samplesL1: FloatArray
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ class MusicCache(val trackName: String) : Disposable {
|
|||||||
private val cache = HashMap<String, MusicContainer>()
|
private val cache = HashMap<String, MusicContainer>()
|
||||||
|
|
||||||
fun getOrPut(music: MusicContainer?): MusicContainer? {
|
fun getOrPut(music: MusicContainer?): MusicContainer? {
|
||||||
if (music != null && music.toRAM) { // for now only the on-the-RAM tracks are getting cached
|
if (music != null && !music.toRAM)
|
||||||
println("Cacheing music ${music.name} for track $trackName")
|
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() }
|
return cache.getOrPut(music.name) { music.makeCopy() }
|
||||||
}
|
return null
|
||||||
else return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
|
|||||||
@@ -44,12 +44,18 @@ class TerrarumAudioMixerTrack(
|
|||||||
|
|
||||||
var currentTrack: MusicContainer? = null
|
var currentTrack: MusicContainer? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = musicCache.getOrPut(value)
|
field = if (value == null)
|
||||||
|
null
|
||||||
|
else
|
||||||
|
musicCache.getOrPut(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
var nextTrack: MusicContainer? = null
|
var nextTrack: MusicContainer? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = musicCache.getOrPut(value)
|
field = if (value == null)
|
||||||
|
null
|
||||||
|
else
|
||||||
|
musicCache.getOrPut(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
var volume: TrackVolume = 1.0
|
var volume: TrackVolume = 1.0
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ object PickaxeCore {
|
|||||||
private val soundCue = MusicContainer(
|
private val soundCue = MusicContainer(
|
||||||
"pickaxe_sound_cue",
|
"pickaxe_sound_cue",
|
||||||
ModMgr.getFile("basegame", "audio/effects/accessibility/pickaxe_valuable.ogg"),
|
ModMgr.getFile("basegame", "audio/effects/accessibility/pickaxe_valuable.ogg"),
|
||||||
toRAM = true
|
toRAM = false
|
||||||
).also {
|
).also {
|
||||||
App.disposables.add(it)
|
App.disposables.add(it)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
|
|||||||
object UIItemAccessibilityUtil {
|
object UIItemAccessibilityUtil {
|
||||||
// TODO have multiple bop instances (num of copies equal to guiTracks), then play the track with its index according to getFreeGuiTrack()
|
// TODO have multiple bop instances (num of copies equal to guiTracks), then play the track with its index according to getFreeGuiTrack()
|
||||||
fun playHapticCursorHovered() {
|
fun playHapticCursorHovered() {
|
||||||
App.playGUIsound(CommonResourcePool.getAs("sound:haptic_bup"), 0.1666666)
|
App.playGUIsound(CommonResourcePool.getAs("sound:haptic_bup"), 0.3)
|
||||||
}
|
}
|
||||||
fun playHapticPushedDown() {
|
fun playHapticPushedDown() {
|
||||||
App.playGUIsoundHigh(CommonResourcePool.getAs("sound:haptic_bip"), 0.5)
|
App.playGUIsoundHigh(CommonResourcePool.getAs("sound:haptic_bip"), 0.5)
|
||||||
|
|||||||
Reference in New Issue
Block a user