fix crash in block entity ticker, fix wrong displayed available audio source number in f3

This commit is contained in:
Bixilon 2021-09-26 23:46:02 +02:00
parent d3f53e3b8f
commit 88bc4715b5
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 14 additions and 14 deletions

View File

@ -58,7 +58,8 @@ class ChunkSection(
fun realTick(connection: PlayConnection, chunkSectionPosition: Vec3i) {
blockEntities.forEach { entity, inChunkSectionPosition ->
entity.realTick(connection, blocks[inChunkSectionPosition.index]!!, chunkSectionPosition + inChunkSectionPosition)
val block = blocks[inChunkSectionPosition.index] ?: return@forEach // maybe block already got destroyed
entity.realTick(connection, block, chunkSectionPosition + inChunkSectionPosition)
}
}

View File

@ -67,19 +67,9 @@ class AudioPlayer(
private lateinit var listener: SoundListener
private val sources: MutableList<SoundSource> = synchronizedListOf()
val availableSources: Int
get() {
val sources = sources.toSynchronizedList()
var available = 0
var availableSources: Int = 0
private set
for (source in sources) {
if (source.available) {
available++
}
}
return available
}
val sourcesCount: Int
get() = sources.size
@ -207,6 +197,15 @@ class AudioPlayer(
break
}
queue.work()
var availableSources = 0
for (source in sources) {
if (source.available) {
availableSources++
}
}
this.availableSources = availableSources
Thread.sleep(1L)
}
}

View File

@ -73,7 +73,7 @@ class SoundSource {
get() = alGetSourcei(source, AL_SOURCE_STATE) == AL_PLAYING
val available: Boolean
get() = !isPlaying || System.currentTimeMillis() - playTime > (sound?.length ?: 0L) // ToDo: Allow pause
get() = !isPlaying || System.currentTimeMillis() - playTime > (sound?.length ?: 0L) // ToDo: Allow pause
fun play() {
playTime = System.currentTimeMillis()