fix light packet reading (in older versions), fix some chunk bugs

This commit is contained in:
Bixilon 2021-11-15 00:48:59 +01:00
parent ee02484494
commit 465e9c4bf0
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 36 additions and 20 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 KiB

View File

@ -51,8 +51,11 @@ class Chunk(
var lightInitialized = false var lightInitialized = false
var neighboursLoaded = false var neighboursLoaded = false
val isLoaded: Boolean
get() = blocksInitialized && biomesInitialized && lightInitialized
val isFullyLoaded: Boolean val isFullyLoaded: Boolean
get() = blocksInitialized && biomesInitialized && lightInitialized && neighboursLoaded get() = isLoaded && neighboursLoaded
operator fun get(sectionHeight: Int): ChunkSection? = sections?.getOrNull(sectionHeight - lowestSection) operator fun get(sectionHeight: Int): ChunkSection? = sections?.getOrNull(sectionHeight - lowestSection)

View File

@ -42,7 +42,7 @@ import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
import de.bixilon.minosoft.util.KUtil.toSynchronizedMap import de.bixilon.minosoft.util.KUtil.toSynchronizedMap
import de.bixilon.minosoft.util.MMath import de.bixilon.minosoft.util.MMath
import de.bixilon.minosoft.util.chunk.ChunkUtil import de.bixilon.minosoft.util.chunk.ChunkUtil
import de.bixilon.minosoft.util.chunk.ChunkUtil.fullyLoaded import de.bixilon.minosoft.util.chunk.ChunkUtil.loaded
import de.bixilon.minosoft.util.collections.SynchronizedMap import de.bixilon.minosoft.util.collections.SynchronizedMap
import glm_.func.common.clamp import glm_.func.common.clamp
import glm_.vec2.Vec2i import glm_.vec2.Vec2i
@ -266,19 +266,21 @@ class World(
return getChunkNeighbours(ChunkUtil.getChunkNeighbourPositions(chunkPosition)) return getChunkNeighbours(ChunkUtil.getChunkNeighbourPositions(chunkPosition))
} }
fun onChunkUpdate(chunkPosition: Vec2i, chunk: Chunk = get(chunkPosition)!!) {
fun onChunkUpdate(chunkPosition: Vec2i, chunk: Chunk = this[chunkPosition]!!) {
if (chunk.neighboursLoaded) {
// return ToDo: Causes some chunks not have neighboursLoaded=true, but they should
}
val neighbourPositions = ChunkUtil.getChunkNeighbourPositions(chunkPosition) val neighbourPositions = ChunkUtil.getChunkNeighbourPositions(chunkPosition)
val neighbours = getChunkNeighbours(neighbourPositions) val neighbours = getChunkNeighbours(neighbourPositions)
if (chunk.neighboursLoaded) { if (neighbours.loaded) {
return
}
if (neighbours.fullyLoaded) {
chunk.neighboursLoaded = true chunk.neighboursLoaded = true
if (cacheBiomeAccessor != null) { if (cacheBiomeAccessor != null) {
chunk.buildBiomeCache() chunk.buildBiomeCache()
} }
} }
for ((index, neighbourPosition) in neighbourPositions.withIndex()) { for (index in 0 until 8) {
val neighbourPosition = neighbourPositions[index]
if (neighbourPosition == chunkPosition) { if (neighbourPosition == chunkPosition) {
continue continue
} }
@ -287,21 +289,22 @@ class World(
if (neighbourChunk.neighboursLoaded) { if (neighbourChunk.neighboursLoaded) {
continue continue
} }
var biomeSourceLoaded = true var neighbourLoaded = true
for (neighbourNeighbourChunk in getChunkNeighbours(neighbourPosition)) { for (neighbourNeighbourChunk in getChunkNeighbours(neighbourPosition)) {
if (neighbourNeighbourChunk?.biomeSource == null) { if ((neighbourNeighbourChunk?.biomeSource == null && neighbourNeighbourChunk?.biomesInitialized != true) || !neighbourNeighbourChunk.blocksInitialized || !neighbourNeighbourChunk.lightInitialized) {
biomeSourceLoaded = false neighbourLoaded = false
break break
} }
} }
if (biomeSourceLoaded) { if (!neighbourLoaded) {
neighbourChunk.neighboursLoaded = true // ToDo: only if fully loaded not just biomes continue
if (cacheBiomeAccessor != null) {
neighbourChunk.buildBiomeCache()
}
connection.fireEvent(ChunkDataChangeEvent(connection, EventInitiators.UNKNOWN, neighbourPosition, neighbourChunk))
} }
neighbourChunk.neighboursLoaded = true
if (cacheBiomeAccessor != null) {
neighbourChunk.buildBiomeCache()
}
connection.fireEvent(ChunkDataChangeEvent(connection, EventInitiators.UNKNOWN, neighbourPosition, neighbourChunk))
} }
} }

View File

@ -271,7 +271,7 @@ class DebugHUDElement(hudRenderer: HUDRenderer) : LayoutedHUDElement<GridLayout>
this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Sky properties ", connection.world.dimension?.skyProperties) } this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Sky properties ", connection.world.dimension?.skyProperties) }
this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Biome ", connection.world.getBiome(blockPosition)) } this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Biome ", connection.world.getBiome(blockPosition)) }
this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { with(connection.world.getLight(blockPosition)) { BaseComponent("Light block=", (this and 0x0F), ", sky=", (this ushr 4)) } } this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { with(connection.world.getLight(blockPosition)) { BaseComponent("Light block=", (this and 0x0F), ", sky=", (this ushr 4)) } }
this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Fully loaded: ", chunk.isFullyLoaded) } this@DebugWorldInfo += AutoTextElement(hudRenderer, 1) { BaseComponent("Fully loaded: ", world[entity.positionInfo.chunkPosition]?.isFullyLoaded) }
lastChunk = chunk lastChunk = chunk
} }

View File

@ -235,6 +235,16 @@ object ChunkUtil {
return true return true
} }
val Array<Chunk?>.loaded: Boolean
get() {
for (neighbour in this) {
if (neighbour?.isLoaded != true) {
return false
}
}
return true
}
fun getChunkNeighbourPositions(chunkPosition: Vec2i): Array<Vec2i> { fun getChunkNeighbourPositions(chunkPosition: Vec2i): Array<Vec2i> {
return arrayOf( return arrayOf(

View File

@ -52,7 +52,7 @@ object LightUtil {
} }
private fun readLightArray(buffer: PlayInByteBuffer, lightMask: BitSet, dimension: DimensionProperties): Triple<Array<ByteArray?>, ByteArray?, ByteArray?> { private fun readLightArray(buffer: PlayInByteBuffer, lightMask: BitSet, dimension: DimensionProperties): Triple<Array<ByteArray?>, ByteArray?, ByteArray?> {
var highestSectionIndex = dimension.highestSection var highestSectionIndex = dimension.highestSection + 1
val lowesSectionIndex = dimension.lowestSection val lowesSectionIndex = dimension.lowestSection
if (buffer.versionId >= ProtocolVersions.V_20W49A) { if (buffer.versionId >= ProtocolVersions.V_20W49A) {
buffer.readVarInt() // section count buffer.readVarInt() // section count