mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
resort some loops to y->z->y
This is because the values are indexed in that way and cpu caching improves performance
This commit is contained in:
parent
a7b10aaa49
commit
a278b6813b
@ -33,8 +33,8 @@ abstract class ChunkHeightmap(protected val chunk: Chunk) : Heightmap {
|
||||
chunk.lock.lock()
|
||||
val maxY = (chunk.maxSection + 1) * ProtocolDefinition.SECTION_HEIGHT_Y
|
||||
|
||||
for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) {
|
||||
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
|
||||
for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) {
|
||||
trace(x, maxY, z, false)
|
||||
}
|
||||
}
|
||||
|
@ -127,8 +127,8 @@ class ChunkSkyLight(val light: ChunkLight) {
|
||||
|
||||
private fun floodFill() {
|
||||
val neighbours = this.chunk.neighbours.get() ?: return
|
||||
for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) {
|
||||
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
|
||||
for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) {
|
||||
floodFill(neighbours, x, z)
|
||||
}
|
||||
}
|
||||
|
@ -274,8 +274,8 @@ class SectionLight(
|
||||
}
|
||||
|
||||
private fun propagateX(baseY: Int, neighbours: Array<ChunkSection?>) {
|
||||
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
|
||||
for (y in 0 until ProtocolDefinition.SECTION_HEIGHT_Y) {
|
||||
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
|
||||
val totalY = baseY + y
|
||||
neighbours[Directions.O_WEST]?.light?.get(ProtocolDefinition.SECTION_MAX_Z, y, z)?.toInt()?.let { light ->
|
||||
(light and BLOCK_LIGHT_MASK).let { if (it > 1) traceBlockIncrease(0, y, z, it - 1, Directions.EAST) }
|
||||
|
@ -84,14 +84,17 @@ class SolidCullSectionPreparer(
|
||||
|
||||
val floatOffset = FloatArray(3)
|
||||
|
||||
for (y in blocks.minPosition.y..blocks.maxPosition.y) {
|
||||
val min = blocks.minPosition.array
|
||||
val max = blocks.maxPosition.array
|
||||
|
||||
for (y in min[1]..max[1]) {
|
||||
position.y = offsetY + y
|
||||
floatOffset[1] = (position.y - cameraOffset.y).toFloat()
|
||||
val fastBedrock = y == 0 && isLowestSection && fastBedrock
|
||||
for (x in blocks.minPosition.x..blocks.maxPosition.x) {
|
||||
position.x = offsetX + x
|
||||
floatOffset[0] = (position.x - cameraOffset.x).toFloat()
|
||||
for (z in blocks.minPosition.z..blocks.maxPosition.z) {
|
||||
for (z in min[2]..max[2]) {
|
||||
position.z = offsetZ + z
|
||||
floatOffset[2] = (position.z - cameraOffset.z).toFloat()
|
||||
for (x in min[0]..max[0]) {
|
||||
val baseIndex = (z shl 4) or x
|
||||
val index = (y shl 8) or baseIndex
|
||||
blockState = blocks[index] ?: continue
|
||||
@ -99,8 +102,8 @@ class SolidCullSectionPreparer(
|
||||
continue
|
||||
}
|
||||
light[SELF_LIGHT_INDEX] = sectionLight[index]
|
||||
position.z = offsetZ + z
|
||||
floatOffset[2] = (position.z - cameraOffset.z).toFloat()
|
||||
position.x = offsetX + x
|
||||
floatOffset[0] = (position.x - cameraOffset.x).toFloat()
|
||||
|
||||
val maxHeight = chunk.light.heightmap[baseIndex]
|
||||
if (position.y >= maxHeight) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user