mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24: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
|
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) {
|
private fun playSound(sound: Sound, position: Vec3? = null, volume: Float = 1.0f, pitch: Float = 1.0f) {
|
||||||
if (!profile.enabled) {
|
if (!profile.enabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
position?.let {
|
position?.let { if (!shouldPlay(sound, position)) return }
|
||||||
val distance = (this.listener.position - it).length()
|
|
||||||
if (distance >= sound.attenuationDistance) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
queue += add@{
|
queue += add@{
|
||||||
sound.load(connection.assetsManager)
|
sound.load(connection.assetsManager)
|
||||||
|
position?.let { if (!shouldPlay(sound, position)) return@add }
|
||||||
val source = getAvailableSource()
|
val source = getAvailableSource()
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
Log.log(LogMessageType.AUDIO, LogLevels.WARN) { "No source available: $sound" }
|
Log.log(LogMessageType.AUDIO, LogLevels.WARN) { "No source available: $sound" }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user