wip skylight tracing

This commit is contained in:
Bixilon 2022-09-16 20:43:38 +02:00
parent 8e3c24e834
commit 440c00d29a
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 36 additions and 2 deletions

View File

@ -524,6 +524,7 @@ class Chunk(
maxSection.light.light[index] = (maxSection.light.light[index].toInt() and 0x0F or 0xF0).toByte()
}
maxSection.light.update = true
maxSection.light.traceSkylight(x, maxHeight.inSectionHeight, z, ProtocolDefinition.LIGHT_LEVELS - 1, Directions.UP)
}
}
}

View File

@ -211,7 +211,7 @@ class SectionLight(
}
override operator fun get(index: Int): Byte {
override inline operator fun get(index: Int): Byte {
return light[index]
}
@ -238,8 +238,41 @@ class SectionLight(
}
}
fun traceSkylight(x: Int, y: Int, z: Int, nextLevel: Int) {
fun traceSkylight(x: Int, y: Int, z: Int, nextLevel: Int, direction: Directions) {
val index = getIndex(x, y, z)
val currentLight = this[index].toInt()
val currentSkylight = (currentLight and SKY_LIGHT_MASK) shr 4
if (currentSkylight >= nextLevel) {
return
}
val light = section.blocks[index]?.lightProperties
if (light != null && !light.propagatesSkylight) {
return
}
this.light[index] = ((currentLight and BLOCK_LIGHT_MASK) or (nextLevel shl 4)).toByte()
val nextNeighbourLevel = nextLevel - 1
// ToDo: Neighbours
if (y > 0 && (light == null || light.propagatesSkylight(direction, Directions.DOWN))) {
traceSkylight(x, y - 1, z, nextNeighbourLevel, Directions.DOWN)
}
if (y < ProtocolDefinition.SECTION_MAX_Y && (light == null || light.propagatesSkylight(direction, Directions.UP))) {
traceSkylight(x, y + 1, z, nextNeighbourLevel, Directions.UP)
}
if (z > 0 && (light == null || light.propagatesSkylight(direction, Directions.NORTH))) {
traceSkylight(x, y, z - 1, nextNeighbourLevel, Directions.NORTH)
}
if (z < ProtocolDefinition.SECTION_MAX_Z && (light == null || light.propagatesSkylight(direction, Directions.SOUTH))) {
traceSkylight(x, y, z + 1, nextNeighbourLevel, Directions.SOUTH)
}
if (x > 0 && (light == null || light.propagatesSkylight(direction, Directions.WEST))) {
traceSkylight(x - 1, y, z, nextNeighbourLevel, Directions.WEST)
}
if (x < ProtocolDefinition.SECTION_MAX_X && (light == null || light.propagatesSkylight(direction, Directions.EAST))) {
traceSkylight(x + 1, y, z, nextNeighbourLevel, Directions.EAST)
}
}
companion object {