fluid renderer: use unsafe get to calculate corners height

Improves the performance
This commit is contained in:
Bixilon 2022-05-11 18:21:19 +02:00
parent f313efe214
commit 410b06432e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 4 additions and 6 deletions

View File

@ -73,6 +73,8 @@ class Chunk(
operator fun get(position: Vec3i): BlockState? = get(position.x, position.y, position.z)
fun unsafeGet(position: Vec3i): BlockState? = unsafeGet(position.x, position.y, position.z)
fun set(x: Int, y: Int, z: Int, blockState: BlockState?, blockEntity: BlockEntity? = null) {
val section = getOrPut(y.sectionHeight) ?: return
section.blocks[x, y.inSectionHeight, z] = blockState

View File

@ -61,11 +61,7 @@ class FluidCullSectionPreparer(
// ToDo: Should this be combined with the solid renderer (but we'd need to render faces twice, because of cullface)
override fun prepareFluid(chunkPosition: Vec2i, sectionHeight: Int, chunk: Chunk, section: ChunkSection, neighbours: Array<ChunkSection?>, neighbourChunks: Array<Chunk>, mesh: WorldMesh) {
val isLowestSection = sectionHeight == chunk.lowestSection
val isHighestSection = sectionHeight == chunk.highestSection
val blocks = section.blocks
val sectionLight = section.light
section.acquire()
neighbours.acquire()
@ -284,11 +280,11 @@ class FluidCullSectionPreparer(
continue
}
val inChunkPosition = blockPosition.inChunkPosition
if (fluid.matches(lastChunk[inChunkPosition + Directions.UP])) {
if (fluid.matches(lastChunk.unsafeGet(inChunkPosition + Directions.UP))) {
return 1.0f
}
val blockState = lastChunk[inChunkPosition]
val blockState = lastChunk.unsafeGet(inChunkPosition)
if (blockState == null) {
count++
continue