mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
block changing: minimal performance improvements
This commit is contained in:
parent
9b1ae46aeb
commit
11f207fc54
@ -34,7 +34,7 @@ open class BlockState(
|
|||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (other is ResourceLocation) return other == block.identifier
|
if (other is ResourceLocation) return other == block.identifier
|
||||||
if (other is BlockState) return other.block == block
|
if (other is BlockState) return other.block == block && other.luminance == luminance
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ open class PropertyBlockState(
|
|||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (other is ResourceLocation) return other == block.identifier
|
if (other is ResourceLocation) return other == block.identifier
|
||||||
if (other is PropertyBlockState) return other.block == this.block && other.properties == this.properties
|
if (other is PropertyBlockState) return other.block == block && other.luminance == luminance && other.properties == this.properties
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -142,27 +142,34 @@ class Chunk(
|
|||||||
if (updates.isEmpty()) return
|
if (updates.isEmpty()) return
|
||||||
if (updates.size == 1) return apply(updates.first())
|
if (updates.size == 1) return apply(updates.first())
|
||||||
|
|
||||||
lock.lock()
|
|
||||||
val executed: MutableSet<ChunkLocalBlockUpdate.LocalUpdate> = hashSetOf()
|
val executed: MutableSet<ChunkLocalBlockUpdate.LocalUpdate> = hashSetOf()
|
||||||
val sections: MutableSet<ChunkSection> = hashSetOf()
|
val sections: MutableSet<ChunkSection> = hashSetOf()
|
||||||
|
|
||||||
|
lock.lock()
|
||||||
for (update in updates) {
|
for (update in updates) {
|
||||||
val section = getOrPut(update.position.y.sectionHeight, lock = false) ?: continue
|
val sectionHeight = update.position.y.sectionHeight
|
||||||
|
var section = this[sectionHeight]
|
||||||
|
if (update.state == null && section == null) continue
|
||||||
|
|
||||||
|
section = getOrPut(sectionHeight, lock = false) ?: continue
|
||||||
val previous = section.blocks.noOcclusionSet(update.position.x, update.position.y.inSectionHeight, update.position.z, update.state)
|
val previous = section.blocks.noOcclusionSet(update.position.x, update.position.y.inSectionHeight, update.position.z, update.state)
|
||||||
if (previous == update.state) continue
|
if (previous == update.state) continue
|
||||||
getOrPutBlockEntity(update.position)
|
getOrPutBlockEntity(update.position)
|
||||||
executed += update
|
executed += update
|
||||||
sections += section
|
sections += section
|
||||||
}
|
}
|
||||||
if (executed.isNotEmpty()) {
|
|
||||||
for (section in sections) {
|
if (executed.isEmpty()) {
|
||||||
section.blocks.occlusion.recalculate(true)
|
return lock.unlock()
|
||||||
}
|
}
|
||||||
light.recalculateHeightmap()
|
light.recalculateHeightmap()
|
||||||
light.recalculate()
|
light.recalculate()
|
||||||
|
|
||||||
|
for (section in sections) {
|
||||||
|
section.blocks.occlusion.recalculate(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
lock.unlock()
|
lock.unlock()
|
||||||
if (executed.isEmpty()) return
|
|
||||||
|
|
||||||
ChunkLocalBlockUpdate(chunkPosition, this, executed).fire(connection)
|
ChunkLocalBlockUpdate(chunkPosition, this, executed).fire(connection)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user