mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 22:14:05 +09:00
fix: bad cacheing behaviour
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user