benchmark section occlusion

This commit is contained in:
Moritz Zwerger 2025-02-06 21:54:12 +01:00
parent b2963ca1bd
commit 2e202bd6fc
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * 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. * 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 { private fun create(): SectionOcclusion {
val blocks = BlockSectionDataProvider::class.java.allocate() val blocks = BlockSectionDataProvider::class.java.allocate()
blocks::occlusion.forceSet(SectionOcclusion(blocks)) val occlusion = SectionOcclusion(blocks)
return blocks.occlusion 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?) { 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 (y in minY..maxY) {
for (z in minZ..maxZ) { for (z in minZ..maxZ) {
for (x in minX..maxX) { for (x in minX..maxX) {
@ -44,11 +46,11 @@ class SectionOcclusionTest {
} }
} }
} }
CALCULATE.setBoolean(this, true)
} }
private val SectionOcclusion.occlusion: BooleanArray private val SectionOcclusion.occlusion: BooleanArray
get() { get() {
CALCULATE.setBoolean(this, true)
recalculate(false) recalculate(false)
return OCCLUSION[this].unsafeCast() return OCCLUSION[this].unsafeCast()
} }
@ -89,5 +91,25 @@ class SectionOcclusionTest {
assertEquals(occlusion.occlusion, BooleanArray(15) { false }) 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 // TODO: Test more possible cases
} }