world: improve locking when retrieving neighbours

This commit is contained in:
Bixilon 2022-10-24 18:16:11 +02:00
parent 73d6f3a481
commit 7a07d7a143
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -357,9 +357,11 @@ class World(
*/
fun getChunkNeighbours(neighbourPositions: Array<ChunkPosition>): Array<Chunk?> {
val chunks: Array<Chunk?> = arrayOfNulls(neighbourPositions.size)
this.chunks.lock.acquire()
for ((index, neighbourPosition) in neighbourPositions.withIndex()) {
chunks[index] = this[neighbourPosition] ?: continue
chunks[index] = this.chunks.unsafe[neighbourPosition] ?: continue
}
this.chunks.lock.release()
return chunks
}