From 9e08ec70797d428d120403e7c8bdf55dd25c1e87 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Sat, 29 Jul 2023 00:34:05 +0200 Subject: [PATCH] fix some sky light neighbour tracing bugs --- build.gradle.kts | 2 +- .../chunk/light/place/SkyLightPlaceIT.kt | 2 ++ .../data/world/chunk/light/ChunkSkyLight.kt | 28 +++++++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 97eda7c0b..d7937a3cb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -222,7 +222,7 @@ testing { options { val options = this as TestNGOptions options.preserveOrder = true - options.excludeGroups("input", "font", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "physics", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "world_renderer", "rendering") + // options.excludeGroups("input", "font", "command", "registry", "biome", "version", "fluid", "world", "raycasting", "pixlyzer", "item", "physics", "packet", "container", "item_stack", "signature", "private_key", "interaction", "item_digging", "world_renderer", "rendering") } } } diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/place/SkyLightPlaceIT.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/place/SkyLightPlaceIT.kt index 212e9ef5d..ca11130e7 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/place/SkyLightPlaceIT.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/place/SkyLightPlaceIT.kt @@ -73,6 +73,8 @@ class SkyLightPlaceIT { fun belowBlock3() { val world = createConnection(3, light = true).world world.fill(7, 10, 7, 9, 10, 9, StoneTest0.state, false) + // world.chunks[0,0]!!.light.reset() + // world.chunks[0,0]!!.light.sky.calculate() world.assertLight(8, 9, 8, 0xD0) } diff --git a/src/main/java/de/bixilon/minosoft/data/world/chunk/light/ChunkSkyLight.kt b/src/main/java/de/bixilon/minosoft/data/world/chunk/light/ChunkSkyLight.kt index 8f1b219e5..f1c4f506f 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/chunk/light/ChunkSkyLight.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/chunk/light/ChunkSkyLight.kt @@ -34,17 +34,17 @@ class ChunkSkyLight(val light: ChunkLight) { floodFill() } - private fun traceSection(sectionHeight: SectionHeight, x: Int, topY: Int, bottomY: Int, z: Int, source: Directions) { + private fun traceSection(sectionHeight: SectionHeight, x: Int, topY: Int, bottomY: Int, z: Int, target: Directions) { val section = chunk.getOrPut(sectionHeight) ?: return val baseY = sectionHeight * ProtocolDefinition.SECTION_HEIGHT_Y for (y in topY downTo bottomY) { - section.light.traceSkyLightIncrease(x, y, z, NEIGHBOUR_TRACE_LEVEL, source, baseY + y, false) + section.light.traceSkyLightIncrease(x, y, z, NEIGHBOUR_TRACE_LEVEL, target, baseY + y, false) } section.light.update = true } - private fun trace(x: Int, topY: Int, bottomY: Int, z: Int, source: Directions) { + private fun trace(x: Int, topY: Int, bottomY: Int, z: Int, target: Directions) { if (topY == Int.MIN_VALUE) return // no blocks are set in that column, no need to trace. all levels are MAX if (bottomY > topY) return // started position is higher than at this, no need to trace @@ -57,16 +57,16 @@ class ChunkSkyLight(val light: ChunkLight) { // top section if (sections > 1) { - traceSection(topSection, x, topY.inSectionHeight, 0, z, source) + traceSection(topSection, x, topY.inSectionHeight, 0, z, target) } // middle sections for (sectionHeight in (topSection - 1) downTo maxOf(chunk.minSection, bottomSection) + 1) { - traceSection(sectionHeight, x, ProtocolDefinition.SECTION_MAX_Y, 0, z, source) + traceSection(sectionHeight, x, ProtocolDefinition.SECTION_MAX_Y, 0, z, target) } // lowest section - traceSection(if (bottomY == Int.MIN_VALUE) chunk.minSection else bottomSection, x, if (topSection == bottomSection) topY.inSectionHeight else ProtocolDefinition.SECTION_MAX_Y, if (bottomY == Int.MIN_VALUE) 0 else bottomY.inSectionHeight, z, source) + traceSection(if (bottomY == Int.MIN_VALUE) chunk.minSection else bottomSection, x, if (topSection == bottomSection) topY.inSectionHeight else ProtocolDefinition.SECTION_MAX_Y, if (bottomY == Int.MIN_VALUE) 0 else bottomY.inSectionHeight, z, target) if (bottomY == Int.MIN_VALUE) { chunk.light.bottom.traceSkyIncrease(x, z, NEIGHBOUR_TRACE_LEVEL) @@ -91,31 +91,31 @@ class ChunkSkyLight(val light: ChunkLight) { traceDown(x, maxHeight, z) if (x > 0) { - trace(x - 1, light.heightmap[heightmapIndex - 1], maxHeight, z, Directions.EAST) + trace(x - 1, light.heightmap[heightmapIndex - 1], maxHeight, z, Directions.WEST) } else { val neighbour = neighbours[ChunkNeighbours.WEST].light - neighbour.sky.trace(ProtocolDefinition.SECTION_MAX_X, neighbour.heightmap[(z shl 4) or ProtocolDefinition.SECTION_MAX_X], maxHeight, z, Directions.EAST) + neighbour.sky.trace(ProtocolDefinition.SECTION_MAX_X, neighbour.heightmap[(z shl 4) or ProtocolDefinition.SECTION_MAX_X], maxHeight, z, Directions.WEST) } if (x < ProtocolDefinition.SECTION_MAX_X) { - trace(x + 1, light.heightmap[heightmapIndex + 1], maxHeight, z, Directions.WEST) + trace(x + 1, light.heightmap[heightmapIndex + 1], maxHeight, z, Directions.EAST) } else { val neighbour = neighbours[ChunkNeighbours.EAST].light - neighbour.sky.trace(0, neighbour.heightmap[(z shl 4) or 0], maxHeight, z, Directions.WEST) + neighbour.sky.trace(0, neighbour.heightmap[(z shl 4) or 0], maxHeight, z, Directions.EAST) } if (z > 0) { - trace(x, light.heightmap[((z - 1) shl 4) or x], maxHeight, z - 1, Directions.SOUTH) + trace(x, light.heightmap[((z - 1) shl 4) or x], maxHeight, z - 1, Directions.NORTH) } else { val neighbour = neighbours[ChunkNeighbours.NORTH].light - neighbour.sky.trace(x, neighbour.heightmap[(ProtocolDefinition.SECTION_MAX_Z shl 4) or x], maxHeight, ProtocolDefinition.SECTION_MAX_Z, Directions.SOUTH) + neighbour.sky.trace(x, neighbour.heightmap[(ProtocolDefinition.SECTION_MAX_Z shl 4) or x], maxHeight, ProtocolDefinition.SECTION_MAX_Z, Directions.NORTH) } if (z < ProtocolDefinition.SECTION_MAX_Z) { - trace(x, light.heightmap[((z + 1) shl 4) or x], maxHeight, z + 1, Directions.NORTH) + trace(x, light.heightmap[((z + 1) shl 4) or x], maxHeight, z + 1, Directions.SOUTH) } else { val neighbour = neighbours[ChunkNeighbours.SOUTH].light - neighbour.sky.trace(x, neighbour.heightmap[(0 shl 4) or x], maxHeight, 0, Directions.NORTH) + neighbour.sky.trace(x, neighbour.heightmap[(0 shl 4) or x], maxHeight, 0, Directions.SOUTH) } }