fix skylight tracing through neighbours

This commit is contained in:
Bixilon 2022-09-25 17:00:14 +02:00
parent 0901ac07c7
commit 68af0e1f0f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 34 additions and 38 deletions

View File

@ -521,14 +521,13 @@ class Chunk(
}
private inline fun traceSkylightDown(x: Int, z: Int) {
val heightmapIndex = (z shl 4) or x
traceSkylightDown(heightmapIndex)
traceSkylightDown((z shl 4) or x)
}
private fun traceSkylightDown(heightmapIndex: Int): Int {
val maxHeight = skylightHeightmap[heightmapIndex]
// ToDo: only update changed ones
// ToDo: only mark changed ones as updated
for (sectionHeight in highestSection - 1 downTo maxHeight.sectionHeight + 1) {
val section = sections?.get(sectionHeight - lowestSection) ?: continue
section.light.update = true
@ -556,30 +555,27 @@ class Chunk(
val maxHeight = skylightHeightmap[heightmapIndex]
var skylightStart: Int
// ToDo: Don't traceSkylightDown 5x
skylightStart = if (x > 0) {
traceSkylightDown(heightmapIndex - 1)
} else {
neighbours[ChunkNeighbours.EAST].traceSkylightDown((z shl 4) or ProtocolDefinition.SECTION_MAX_X)
}
skylightStart = maxOf(
skylightStart, if (x < ProtocolDefinition.SECTION_MAX_X) {
val skylightStart: Int = maxOf(
if (x > 0) {
traceSkylightDown(heightmapIndex - 1)
} else {
neighbours[ChunkNeighbours.EAST].traceSkylightDown((z shl 4) or ProtocolDefinition.SECTION_MAX_X)
},
if (x < ProtocolDefinition.SECTION_MAX_X) {
traceSkylightDown(heightmapIndex + 1)
} else {
neighbours[ChunkNeighbours.WEST].traceSkylightDown(((z shl 4) or 0))
}
)
skylightStart = maxOf(
skylightStart, if (z > 0) {
},
if (z > 0) {
traceSkylightDown(((z - 1) shl 4) or x)
} else {
neighbours[ChunkNeighbours.SOUTH].skylightHeightmap[(ProtocolDefinition.SECTION_MAX_Z shl 4) or x]
}
)
skylightStart = maxOf(
skylightStart, if (z < ProtocolDefinition.SECTION_MAX_Z) {
},
if (z < ProtocolDefinition.SECTION_MAX_Z) {
traceSkylightDown(((z + 1) shl 4) or x)
} else {
neighbours[ChunkNeighbours.NORTH].traceSkylightDown((0 shl 4) or x)

View File

@ -273,36 +273,36 @@ class SectionLight(
if (y < ProtocolDefinition.SECTION_MAX_Y) {
traceSkylight(x, y + 1, z, nextNeighbourLevel, Directions.UP, totalY + 1, false)
} else {
// ToDo: Bottom light
// ToDo: Trace through bottom light
neighbours[Directions.O_DOWN]?.light?.traceSkylight(x, ProtocolDefinition.SECTION_MAX_Y, z, nextLevel, direction, totalY, false)
}
}
if (direction != Directions.SOUTH && (direction == null || light.propagatesLight(direction, Directions.NORTH))) {
if (z > 0) {
traceSkylight(x, y, z - 1, nextNeighbourLevel, Directions.NORTH, totalY, false)
} else {
neighbours[Directions.O_SOUTH]?.light?.traceSkylight(x, y, ProtocolDefinition.SECTION_MAX_Z, nextNeighbourLevel, Directions.NORTH, totalY, false)
}
}
if (direction != Directions.NORTH && (direction == null || light.propagatesLight(direction, Directions.SOUTH))) {
if (z < ProtocolDefinition.SECTION_MAX_Z) {
traceSkylight(x, y, z + 1, nextNeighbourLevel, Directions.SOUTH, totalY, false)
if (z > 0) {
traceSkylight(x, y, z - 1, nextNeighbourLevel, Directions.SOUTH, totalY, false)
} else {
neighbours[Directions.O_NORTH]?.light?.traceSkylight(x, y, 0, nextNeighbourLevel, Directions.SOUTH, totalY, false)
neighbours[Directions.O_NORTH]?.light?.traceSkylight(x, y, ProtocolDefinition.SECTION_MAX_Z, nextNeighbourLevel, Directions.SOUTH, totalY, false)
}
}
if (direction != Directions.EAST && (direction == null || light.propagatesLight(direction, Directions.WEST))) {
if (x > 0) {
traceSkylight(x - 1, y, z, nextNeighbourLevel, Directions.WEST, totalY, false)
if (direction != Directions.SOUTH && (direction == null || light.propagatesLight(direction, Directions.NORTH))) {
if (z < ProtocolDefinition.SECTION_MAX_Z) {
traceSkylight(x, y, z + 1, nextNeighbourLevel, Directions.NORTH, totalY, false)
} else {
neighbours[Directions.O_EAST]?.light?.traceSkylight(ProtocolDefinition.SECTION_MAX_X, y, z, nextLevel, direction, totalY, false)
neighbours[Directions.O_SOUTH]?.light?.traceSkylight(x, y, 0, nextNeighbourLevel, Directions.NORTH, totalY, false)
}
}
if (direction != Directions.WEST && (direction == null || light.propagatesLight(direction, Directions.EAST))) {
if (x < ProtocolDefinition.SECTION_MAX_X) {
traceSkylight(x + 1, y, z, nextNeighbourLevel, Directions.EAST, totalY, false)
if (x > 0) {
traceSkylight(x - 1, y, z, nextNeighbourLevel, Directions.EAST, totalY, false)
} else {
neighbours[Directions.O_WEST]?.light?.traceSkylight(0, y, z, nextLevel, direction, totalY, false)
neighbours[Directions.O_WEST]?.light?.traceSkylight(ProtocolDefinition.SECTION_MAX_X, y, z, nextLevel, direction, totalY, false)
}
}
if (direction != Directions.EAST && (direction == null || light.propagatesLight(direction, Directions.WEST))) {
if (x < ProtocolDefinition.SECTION_MAX_X) {
traceSkylight(x + 1, y, z, nextNeighbourLevel, Directions.WEST, totalY, false)
} else {
neighbours[Directions.O_EAST]?.light?.traceSkylight(0, y, z, nextLevel, direction, totalY, false)
}
}
}