fix light benchmark

This commit is contained in:
Moritz Zwerger 2023-07-29 00:45:11 +02:00
parent 9e08ec7079
commit 732394c5fe
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 5 additions and 4 deletions

View File

@ -22,6 +22,7 @@ import de.bixilon.minosoft.data.registries.blocks.light.OpaqueProperty
import de.bixilon.minosoft.data.registries.blocks.settings.BlockSettings import de.bixilon.minosoft.data.registries.blocks.settings.BlockSettings
import de.bixilon.minosoft.data.registries.blocks.state.AdvancedBlockState import de.bixilon.minosoft.data.registries.blocks.state.AdvancedBlockState
import de.bixilon.minosoft.data.registries.blocks.state.BlockState import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.registries.blocks.state.manager.SimpleStateManager
import de.bixilon.minosoft.data.registries.blocks.types.Block import de.bixilon.minosoft.data.registries.blocks.types.Block
import de.bixilon.minosoft.data.registries.blocks.types.TestBlock import de.bixilon.minosoft.data.registries.blocks.types.TestBlock
import de.bixilon.minosoft.data.registries.dimension.DimensionProperties import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
@ -109,8 +110,7 @@ object ChunkTestingUtil {
fun createBlock(name: String, luminance: Int, lightProperties: LightProperties): Block { fun createBlock(name: String, luminance: Int, lightProperties: LightProperties): Block {
val block = TestBlock(minosoft(name), BlockSettings()) val block = TestBlock(minosoft(name), BlockSettings())
val state = AdvancedBlockState(block, properties = emptyMap(), collisionShape = AbstractVoxelShape.EMPTY, outlineShape = AbstractVoxelShape.EMPTY, luminance = luminance, lightProperties = lightProperties, solidRenderer = true) val state = AdvancedBlockState(block, properties = emptyMap(), collisionShape = AbstractVoxelShape.EMPTY, outlineShape = AbstractVoxelShape.EMPTY, luminance = luminance, lightProperties = lightProperties, solidRenderer = true)
block::states.javaField!!.forceSet(block, setOf(state)) block::states.forceSet(SimpleStateManager(state))
block.states::default.javaField!!.forceSet(block, state)
return block return block
} }

View File

@ -79,9 +79,10 @@ internal class LightBenchmark {
for (index in 0 until 256) { for (index in 0 until 256) {
highest.unsafeSet(index or (0x0F shl 8), solid) highest.unsafeSet(index or (0x0F shl 8), solid)
} }
var totalPlace = 0L var totalPlace = 0L
var totalBreak = 0L var totalBreak = 0L
val benchmark = BenchmarkUtil.benchmark(10000) { val benchmark = BenchmarkUtil.benchmark(100000) {
totalBreak += measureNanoTime { chunk[7, 255, 7] = null } totalBreak += measureNanoTime { chunk[7, 255, 7] = null }
totalPlace += measureNanoTime { chunk[7, 255, 7] = solid } totalPlace += measureNanoTime { chunk[7, 255, 7] = solid }
} }

View File

@ -372,7 +372,7 @@ class SectionLight(
(neighbours[Directions.O_DOWN] ?: chunk.getOrPut(section.sectionHeight - 1, false))?.light?.traceSkyLightIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, nextNeighbourLevel, Directions.DOWN, totalY - 1) (neighbours[Directions.O_DOWN] ?: chunk.getOrPut(section.sectionHeight - 1, false))?.light?.traceSkyLightIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, nextNeighbourLevel, Directions.DOWN, totalY - 1)
} }
} }
if (target != Directions.DOWN && target != null && (lightProperties.propagatesLight(Directions.UP))) { if (target != Directions.DOWN && (target != null || lightProperties.propagatesLight(Directions.UP))) {
if (y < ProtocolDefinition.SECTION_MAX_Y) { if (y < ProtocolDefinition.SECTION_MAX_Y) {
traceSkyLightIncrease(x, y + 1, z, nextNeighbourLevel, Directions.UP, totalY + 1) traceSkyLightIncrease(x, y + 1, z, nextNeighbourLevel, Directions.UP, totalY + 1)
} else if (section.sectionHeight < chunk.maxSection) { } else if (section.sectionHeight < chunk.maxSection) {