mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 18:34:56 -04:00
audio: check after queue again if sound can be skipped
This should avoid more "No source available" errors
This commit is contained in:
parent
610494473d
commit
d4f065b356
@ -180,18 +180,24 @@ class AudioPlayer(
|
||||
return source
|
||||
}
|
||||
|
||||
private fun shouldPlay(sound: Sound, position: Vec3?): Boolean {
|
||||
if (position == null) return true
|
||||
val distance = (this.listener.position - position).length2()
|
||||
if (distance >= sound.attenuationDistance * sound.attenuationDistance) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun playSound(sound: Sound, position: Vec3? = null, volume: Float = 1.0f, pitch: Float = 1.0f) {
|
||||
if (!profile.enabled) {
|
||||
return
|
||||
}
|
||||
position?.let {
|
||||
val distance = (this.listener.position - it).length()
|
||||
if (distance >= sound.attenuationDistance) {
|
||||
return
|
||||
}
|
||||
}
|
||||
position?.let { if (!shouldPlay(sound, position)) return }
|
||||
queue += add@{
|
||||
sound.load(connection.assetsManager)
|
||||
position?.let { if (!shouldPlay(sound, position)) return@add }
|
||||
val source = getAvailableSource()
|
||||
if (source == null) {
|
||||
Log.log(LogMessageType.AUDIO, LogLevels.WARN) { "No source available: $sound" }
|
||||
|
Loading…
x
Reference in New Issue
Block a user