From 2e202bd6fcaf7a03d9d43cbeecc1b7fe2f0db82f Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Thu, 6 Feb 2025 21:54:12 +0100 Subject: [PATCH] benchmark section occlusion --- .../container/block/SectionOcclusionTest.kt | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/container/block/SectionOcclusionTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/container/block/SectionOcclusionTest.kt index 190b19105..1bb3b3ffe 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/container/block/SectionOcclusionTest.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/container/block/SectionOcclusionTest.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020-2023 Moritz Zwerger + * Copyright (C) 2020-2025 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -32,11 +32,13 @@ class SectionOcclusionTest { private fun create(): SectionOcclusion { val blocks = BlockSectionDataProvider::class.java.allocate() - blocks::occlusion.forceSet(SectionOcclusion(blocks)) - return blocks.occlusion + val occlusion = SectionOcclusion(blocks) + blocks::occlusion.forceSet(occlusion) + return occlusion } private operator fun SectionOcclusion.set(minX: Int, minY: Int, minZ: Int, maxX: Int, maxY: Int, maxZ: Int, state: BlockState?) { + CALCULATE.setBoolean(this, false) for (y in minY..maxY) { for (z in minZ..maxZ) { for (x in minX..maxX) { @@ -44,11 +46,11 @@ class SectionOcclusionTest { } } } + CALCULATE.setBoolean(this, true) } private val SectionOcclusion.occlusion: BooleanArray get() { - CALCULATE.setBoolean(this, true) recalculate(false) return OCCLUSION[this].unsafeCast() } @@ -89,5 +91,25 @@ class SectionOcclusionTest { assertEquals(occlusion.occlusion, BooleanArray(15) { false }) } + /* + fun benchmark() { + val occlusion = create() + val stone = StoneTest0.state + val random = Random(12) + for (i in 0 until ProtocolDefinition.BLOCKS_PER_SECTION) { + if (random.nextBoolean()) { + occlusion.provider[i] = stone + } + } + CALCULATE.setBoolean(occlusion, true) + val time = measureTime { + for (i in 0 until 1999_99) { + occlusion.recalculate(false) + } + } + println("Took: ${time.inWholeNanoseconds.formatNanos()}") + } + */ + // TODO: Test more possible cases }