section occlusion: don't trace inner regions

They are not needed and thrown away anyways. This makes performance better, because when the section is full, we only need to start 1536 blocks tracing and not all 4096
This commit is contained in:
Moritz Zwerger 2025-03-09 15:23:08 +01:00
parent 8b5e27a47f
commit 58a36aa454
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 15 additions and 6 deletions

View File

@ -77,6 +77,7 @@ class SectionOcclusion(
return false return false
} }
private fun trace(regions: ShortArray, position: InSectionPosition) = trace(regions, position, position.index.toShort())
private fun trace(regions: ShortArray, position: InSectionPosition, region: Short) { private fun trace(regions: ShortArray, position: InSectionPosition, region: Short) {
if (regions.setIfUnset(position, region)) return if (regions.setIfUnset(position, region)) return
@ -92,11 +93,18 @@ class SectionOcclusion(
// mark regions and check direct neighbours // mark regions and check direct neighbours
Arrays.fill(array, EMPTY_REGION) Arrays.fill(array, EMPTY_REGION)
// TODO: Only start flood filling from sides (don't trace potential irrelevant regions in the middle) // TODO: Keep track of direction and never go into negative again (we can't change the direction of the look; it can not reflect here)
// TODO: Keep track of direction and never go into negative again (we can't change the direction of the look; it can not refelct here)
for (index in 0 until ProtocolDefinition.BLOCKS_PER_SECTION) {
trace(array, InSectionPosition(index), index.toShort()) for (index in 0 until 256) {
trace(array, InSectionPosition((index shr 0) and 0x0F, 0x00, (index shr 4) and 0x0F))
trace(array, InSectionPosition((index shr 0) and 0x0F, 0x0F, (index shr 4) and 0x0F))
trace(array, InSectionPosition((index shr 0) and 0x0F, (index shr 4) and 0x0F, 0x00))
trace(array, InSectionPosition((index shr 0) and 0x0F, (index shr 4) and 0x0F, 0x0F))
trace(array, InSectionPosition(0x00, (index shr 4) and 0x0F, (index shr 0) and 0x0F))
trace(array, InSectionPosition(0x0F, (index shr 4) and 0x0F, (index shr 0) and 0x0F))
} }
return array return array

View File

@ -30,8 +30,6 @@ value class SVec3(val raw: Int) {
assertVec(z, -MAX_Z, MAX_Z) assertVec(z, -MAX_Z, MAX_Z)
} }
constructor(vector: DirectionVector) : this(vector.x, vector.y, vector.z)
inline val x: Int get() = (((raw ushr SHIFT_X) and MASK_X) shl (Int.SIZE_BITS - BITS_X)) shr (Int.SIZE_BITS - BITS_X) inline val x: Int get() = (((raw ushr SHIFT_X) and MASK_X) shl (Int.SIZE_BITS - BITS_X)) shr (Int.SIZE_BITS - BITS_X)
inline val y: Int get() = (((raw ushr SHIFT_Y) and MASK_Y) shl (Int.SIZE_BITS - BITS_Y)) shr (Int.SIZE_BITS - BITS_Y) inline val y: Int get() = (((raw ushr SHIFT_Y) and MASK_Y) shl (Int.SIZE_BITS - BITS_Y)) shr (Int.SIZE_BITS - BITS_Y)
@ -131,5 +129,8 @@ value class SVec3(val raw: Int) {
val EMPTY = SVec3(0, 0, 0) val EMPTY = SVec3(0, 0, 0)
operator fun invoke(vector: DirectionVector) = SVec3(vector.x, vector.y, vector.z)
} }
} }