calculate section occlusion on demand

In headless mode occlusion does not matter and chunks that are invisible or occluded also don't matter
This commit is contained in:
Moritz Zwerger 2023-12-07 23:01:46 +01:00
parent 4f68567199
commit c4cd6c4856
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 10 additions and 4 deletions

View File

@ -44,9 +44,8 @@ class ChunkSection(
var neighbours: Array<ChunkSection?>? = null
fun tick(connection: PlayConnection, chunkPosition: Vec2i, sectionHeight: Int, random: Random) {
if (blockEntities.isEmpty) {
return
}
if (blockEntities.isEmpty) return
val offset = Vec3i.of(chunkPosition, sectionHeight)
val position = Vec3i()

View File

@ -26,6 +26,7 @@ class SectionOcclusion(
private val provider: BlockSectionDataProvider,
) {
private var occlusion = EMPTY
private var calculate = false
fun clear(notify: Boolean) {
update(EMPTY, notify)
@ -39,6 +40,8 @@ class SectionOcclusion(
}
fun recalculate(notify: Boolean) {
if (!calculate) return
if (provider.isEmpty) {
clear(notify)
return
@ -180,10 +183,14 @@ class SectionOcclusion(
if (`in` == out) {
return false
}
return occlusion[CubeDirections.getIndex(`in`, out)]
return isOccluded(CubeDirections.getIndex(`in`, out))
}
fun isOccluded(index: Int): Boolean {
if (!calculate) {
calculate = true
recalculate(false)
}
return occlusion[index]
}