mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
border light: faster access to first or last section
This commit is contained in:
parent
835f62d1f4
commit
4451df6113
@ -17,6 +17,8 @@ import de.bixilon.minosoft.data.direction.Directions
|
|||||||
import de.bixilon.minosoft.data.world.chunk.Chunk
|
import de.bixilon.minosoft.data.world.chunk.Chunk
|
||||||
import de.bixilon.minosoft.data.world.chunk.ChunkNeighbours
|
import de.bixilon.minosoft.data.world.chunk.ChunkNeighbours
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
|
import de.bixilon.minosoft.util.KUtil.getFirst
|
||||||
|
import de.bixilon.minosoft.util.KUtil.getLast
|
||||||
|
|
||||||
class BorderSectionLight(
|
class BorderSectionLight(
|
||||||
val top: Boolean,
|
val top: Boolean,
|
||||||
@ -47,9 +49,9 @@ class BorderSectionLight(
|
|||||||
private fun updateY() {
|
private fun updateY() {
|
||||||
// we can not further increase the light
|
// we can not further increase the light
|
||||||
if (top) {
|
if (top) {
|
||||||
chunk.sections?.last()?.light?.update = true
|
chunk.sections?.getLast()?.light?.apply { if (!update) update = true }
|
||||||
} else {
|
} else {
|
||||||
chunk.sections?.first()?.light?.update = true
|
chunk.sections?.getFirst()?.light?.apply { if (!update) update = true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,9 +75,9 @@ class BorderSectionLight(
|
|||||||
val neighbourLuminance = nextLuminance - 1
|
val neighbourLuminance = nextLuminance - 1
|
||||||
|
|
||||||
if (top) {
|
if (top) {
|
||||||
chunk.sections?.last()?.light?.traceBlockIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, neighbourLuminance, Directions.DOWN)
|
chunk.sections?.getLast()?.light?.traceBlockIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, neighbourLuminance, Directions.DOWN)
|
||||||
} else {
|
} else {
|
||||||
chunk.sections?.first()?.light?.traceBlockIncrease(x, 0, z, neighbourLuminance, Directions.UP)
|
chunk.sections?.getFirst()?.light?.traceBlockIncrease(x, 0, z, neighbourLuminance, Directions.UP)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (z > 0) {
|
if (z > 0) {
|
||||||
@ -125,9 +127,9 @@ class BorderSectionLight(
|
|||||||
val neighbourLevel = nextLevel - 1
|
val neighbourLevel = nextLevel - 1
|
||||||
|
|
||||||
if (top) {
|
if (top) {
|
||||||
chunk.sections?.last()?.light?.traceSkylightIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, neighbourLevel, Directions.DOWN, chunk.highestSection * ProtocolDefinition.SECTION_HEIGHT_Y + ProtocolDefinition.SECTION_MAX_Y)
|
chunk.sections?.getLast()?.light?.traceSkylightIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, neighbourLevel, Directions.DOWN, chunk.highestSection * ProtocolDefinition.SECTION_HEIGHT_Y + ProtocolDefinition.SECTION_MAX_Y)
|
||||||
} else {
|
} else {
|
||||||
chunk.sections?.first()?.light?.traceSkylightIncrease(x, 0, z, neighbourLevel, Directions.UP, chunk.lowestSection * ProtocolDefinition.SECTION_HEIGHT_Y)
|
chunk.sections?.getFirst()?.light?.traceSkylightIncrease(x, 0, z, neighbourLevel, Directions.UP, chunk.lowestSection * ProtocolDefinition.SECTION_HEIGHT_Y)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (z > 0) {
|
if (z > 0) {
|
||||||
|
@ -314,4 +314,14 @@ object KUtil {
|
|||||||
if (this is CharSequence) return this.length
|
if (this is CharSequence) return this.length
|
||||||
return toString().length
|
return toString().length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("Kutil 1.18")
|
||||||
|
inline fun <T> Array<T>.getFirst(): T {
|
||||||
|
return this[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Kutil 1.18")
|
||||||
|
inline fun <T> Array<T>.getLast(): T {
|
||||||
|
return this[lastIndex]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user