From cea55b610af6cc7c00b5e70eac7fdd4fb177b070 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 4 May 2022 14:54:10 +0200 Subject: [PATCH] improve performance of solid block culling --- .../minosoft/data/registries/blocks/BlockState.kt | 4 +++- .../models/baked/block/BakedBlockStateModel.kt | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/BlockState.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/BlockState.kt index bbda27352..b9daff0ec 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/BlockState.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/BlockState.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2020 Moritz Zwerger, Lukas Eisenhauer + * Copyright (C) 2020-2022 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. * @@ -42,6 +42,7 @@ data class BlockState( val fallSoundEvent: ResourceLocation?, val soundEventVolume: Float = 1.0f, val soundEventPitch: Float = 1.0f, + val isSolid: Boolean, ) { var blockModel: BakedBlockModel? = null @@ -146,6 +147,7 @@ data class BlockState( fallSoundEvent = data["fall_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] }, soundEventVolume = data["sound_type_volume"]?.toFloat() ?: 1.0f, soundEventPitch = data["sound_type_pitch"]?.toFloat() ?: 1.0f, + isSolid = data["solid_render"]?.toBoolean() ?: true, // ToDo: This should normally be false, but pixlyzers default value is true. Might break if the data is missing ) } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/block/BakedBlockStateModel.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/block/BakedBlockStateModel.kt index 9a12cf8a0..2fffa5043 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/block/BakedBlockStateModel.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/models/baked/block/BakedBlockStateModel.kt @@ -48,6 +48,9 @@ class BakedBlockStateModel( for ((index, faces) in faces.withIndex()) { val direction = Directions.VALUES[index] val neighbour = neighbours[index] + if (blockState.isSolid && neighbour?.isSolid == true) { + continue + } val neighboursModel = neighbour?.blockModel var neighbourProperties: Array? = null if (neighboursModel != null) { @@ -55,8 +58,13 @@ class BakedBlockStateModel( neighbourProperties = neighboursModel.getTouchingFaceProperties(random, direction.inverted) } for (face in faces) { - if (face.touching && neighbourProperties != null && neighbourProperties.isNotEmpty() && neighbourProperties.canCull(face, neighbour != null && blockState.block.canCull(blockState, neighbour))) { - continue + if (face.touching) { + if (neighbour?.isSolid == true) { + continue + } + if (neighbourProperties != null && neighbourProperties.isNotEmpty() && neighbourProperties.canCull(face, neighbour != null && blockState.block.canCull(blockState, neighbour))) { + continue + } } tint = tints?.getOrNull(face.tintIndex) ?: -1 currentLight = (face.cullFace?.let { light[it.ordinal] } ?: light[SolidCullSectionPreparer.SELF_LIGHT_INDEX]).toInt()