mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
rename Chunk::highestSection, fix benchmark
This commit is contained in:
parent
fd10ad3b58
commit
17e164ddaa
@ -207,7 +207,7 @@ class BlockLightBreakIT {
|
||||
}
|
||||
|
||||
fun bottomPropagation() {
|
||||
val world = ConnectionTestUtil.createConnection(5).world
|
||||
val world = ConnectionTestUtil.createConnection(3).world
|
||||
world.fill(Vec3i(-10, 0, -10), Vec3i(30, 1, 30), StoneTestO.state)
|
||||
world[Vec3i(8, 0, 8)] = TorchTest0.state
|
||||
world[Vec3i(8, 0, 8)] = null
|
||||
@ -223,7 +223,7 @@ class BlockLightBreakIT {
|
||||
}
|
||||
|
||||
fun topPropagation() {
|
||||
val world = ConnectionTestUtil.createConnection(5).world
|
||||
val world = ConnectionTestUtil.createConnection(3).world
|
||||
world.fill(Vec3i(-10, 254, -10), Vec3i(30, 255, 30), StoneTestO.state)
|
||||
world[Vec3i(8, 255, 8)] = TorchTest0.state
|
||||
world[Vec3i(8, 255, 8)] = null
|
||||
|
@ -185,7 +185,7 @@ class BlockLightPlaceIT {
|
||||
}
|
||||
|
||||
fun bottomPropagation() {
|
||||
val world = ConnectionTestUtil.createConnection(5).world
|
||||
val world = ConnectionTestUtil.createConnection(3).world
|
||||
world.fill(Vec3i(-10, 0, -10), Vec3i(30, 1, 30), StoneTestO.state)
|
||||
world[Vec3i(8, 0, 8)] = TorchTest0.state
|
||||
|
||||
@ -200,7 +200,7 @@ class BlockLightPlaceIT {
|
||||
}
|
||||
|
||||
fun topPropagation() {
|
||||
val world = ConnectionTestUtil.createConnection(4).world
|
||||
val world = ConnectionTestUtil.createConnection(3).world
|
||||
world.fill(Vec3i(-10, 254, -10), Vec3i(30, 255, 30), StoneTestO.state)
|
||||
world[Vec3i(8, 255, 8)] = TorchTest0.state
|
||||
|
||||
|
@ -51,8 +51,8 @@ class Chunk(
|
||||
val lock = ThreadLock()
|
||||
val world = connection.world
|
||||
val light = ChunkLight(this)
|
||||
val lowestSection = world.dimension!!.minSection
|
||||
val highestSection = world.dimension!!.maxSection
|
||||
val minSection = world.dimension!!.minSection
|
||||
val maxSection = world.dimension!!.maxSection
|
||||
val cacheBiomes = world.cacheBiomeAccessor != null
|
||||
|
||||
var blocksInitialized = false // All block data was received
|
||||
@ -66,7 +66,7 @@ class Chunk(
|
||||
val isFullyLoaded: Boolean
|
||||
get() = isLoaded && neighbours.complete
|
||||
|
||||
operator fun get(sectionHeight: SectionHeight): ChunkSection? = sections?.getOrNull(sectionHeight - lowestSection)
|
||||
operator fun get(sectionHeight: SectionHeight): ChunkSection? = sections?.getOrNull(sectionHeight - minSection)
|
||||
|
||||
fun unsafeGet(x: Int, y: Int, z: Int): BlockState? {
|
||||
return this[y.sectionHeight]?.blocks?.unsafeGet(x, y.inSectionHeight, z)
|
||||
@ -147,7 +147,7 @@ class Chunk(
|
||||
data.blocks?.let {
|
||||
for ((index, blocks) in it.withIndex()) {
|
||||
blocks ?: continue
|
||||
val section = getOrPut(index + lowestSection) ?: return@let
|
||||
val section = getOrPut(index + minSection) ?: return@let
|
||||
section.blocks = blocks
|
||||
}
|
||||
light.recalculateHeightmap()
|
||||
@ -162,7 +162,7 @@ class Chunk(
|
||||
data.light?.let {
|
||||
for ((index, light) in it.withIndex()) {
|
||||
light ?: continue
|
||||
val section = getOrPut(index + lowestSection) ?: return@let
|
||||
val section = getOrPut(index + minSection) ?: return@let
|
||||
section.light.light = light
|
||||
}
|
||||
}
|
||||
@ -187,7 +187,7 @@ class Chunk(
|
||||
lock.unlock()
|
||||
return null
|
||||
}
|
||||
val sectionIndex = sectionHeight - lowestSection
|
||||
val sectionIndex = sectionHeight - minSection
|
||||
if (sectionIndex < 0 || sectionIndex >= sections.size) {
|
||||
lock.unlock()
|
||||
return null
|
||||
@ -214,7 +214,7 @@ class Chunk(
|
||||
if (sectionIndex > 0) {
|
||||
sections[sectionIndex - 1]?.neighbours?.set(Directions.O_UP, section)
|
||||
}
|
||||
val highestIndex = highestSection - 1
|
||||
val highestIndex = maxSection - 1
|
||||
if (sectionIndex < highestIndex) {
|
||||
sections[sectionIndex + 1]?.neighbours?.set(Directions.O_DOWN, section)
|
||||
}
|
||||
@ -235,7 +235,7 @@ class Chunk(
|
||||
val sections = sections!!
|
||||
for ((index, section) in sections.withIndex()) {
|
||||
section ?: continue
|
||||
section.tick(connection, chunkPosition, index + lowestSection)
|
||||
section.tick(connection, chunkPosition, index + minSection)
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ class Chunk(
|
||||
val neighbours: Array<Chunk> = connection.world.getChunkNeighbours(chunkPosition).unsafeCast()
|
||||
for ((sectionIndex, section) in sections!!.withIndex()) {
|
||||
section ?: continue
|
||||
val sectionHeight = sectionIndex + lowestSection
|
||||
val sectionHeight = sectionIndex + minSection
|
||||
section.buildBiomeCache(chunkPosition, sectionHeight, this, neighbours, cacheBiomeAccessor)
|
||||
}
|
||||
biomesInitialized = true
|
||||
@ -270,7 +270,7 @@ class Chunk(
|
||||
|
||||
private fun updateNeighbours(neighbours: Array<Chunk>, sectionHeight: Int) {
|
||||
for (nextSectionHeight in sectionHeight - 1..sectionHeight + 1) {
|
||||
if (nextSectionHeight < lowestSection || nextSectionHeight > highestSection) {
|
||||
if (nextSectionHeight < minSection || nextSectionHeight > maxSection) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -128,9 +128,9 @@ class BorderSectionLight(
|
||||
val neighbourLevel = nextLevel - 1
|
||||
|
||||
if (top) {
|
||||
chunk.sections?.getLast()?.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.maxSection * ProtocolDefinition.SECTION_HEIGHT_Y + ProtocolDefinition.SECTION_MAX_Y)
|
||||
} else {
|
||||
chunk.sections?.getFirst()?.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.minSection * ProtocolDefinition.SECTION_HEIGHT_Y)
|
||||
}
|
||||
|
||||
if (z > 0) {
|
||||
|
@ -93,7 +93,7 @@ class ChunkLight(private val chunk: Chunk) {
|
||||
private fun fireLightChange(sections: Array<ChunkSection?>, fireSameChunkEvent: Boolean) {
|
||||
val neighbours = chunk.neighbours.get() ?: return
|
||||
for ((index, section) in sections.withIndex()) {
|
||||
fireLightChange(section ?: continue, index + chunk.lowestSection, neighbours, fireSameChunkEvent)
|
||||
fireLightChange(section ?: continue, index + chunk.minSection, neighbours, fireSameChunkEvent)
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,10 +107,10 @@ class ChunkLight(private val chunk: Chunk) {
|
||||
val inSectionHeight = y.inSectionHeight
|
||||
val heightmapIndex = (z shl 4) or x
|
||||
val index = inSectionHeight shl 8 or heightmapIndex
|
||||
if (sectionHeight == chunk.lowestSection - 1) {
|
||||
if (sectionHeight == chunk.minSection - 1) {
|
||||
return bottom[index].toInt()
|
||||
}
|
||||
if (sectionHeight == chunk.highestSection + 1) {
|
||||
if (sectionHeight == chunk.maxSection + 1) {
|
||||
return top[index].toInt() or SectionLight.SKY_LIGHT_MASK // top has always sky=15
|
||||
}
|
||||
var light = chunk[sectionHeight]?.light?.get(index)?.toInt() ?: 0x00
|
||||
@ -181,7 +181,7 @@ class ChunkLight(private val chunk: Chunk) {
|
||||
return
|
||||
}
|
||||
chunk.lock.lock()
|
||||
val maxY = chunk.highestSection * ProtocolDefinition.SECTION_HEIGHT_Y
|
||||
val maxY = chunk.maxSection * ProtocolDefinition.SECTION_HEIGHT_Y
|
||||
|
||||
for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) {
|
||||
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
|
||||
@ -197,7 +197,7 @@ class ChunkLight(private val chunk: Chunk) {
|
||||
|
||||
var y = Int.MIN_VALUE
|
||||
|
||||
sectionLoop@ for (sectionIndex in (startY.sectionHeight - chunk.lowestSection) downTo 0) {
|
||||
sectionLoop@ for (sectionIndex in (startY.sectionHeight - chunk.minSection) downTo 0) {
|
||||
if (sectionIndex >= sections.size) {
|
||||
// starting from above world
|
||||
continue
|
||||
@ -212,7 +212,7 @@ class ChunkLight(private val chunk: Chunk) {
|
||||
// can go through block
|
||||
continue
|
||||
}
|
||||
y = (sectionIndex + chunk.lowestSection) * ProtocolDefinition.SECTION_HEIGHT_Y + sectionY
|
||||
y = (sectionIndex + chunk.minSection) * ProtocolDefinition.SECTION_HEIGHT_Y + sectionY
|
||||
if (!light.skylightEnters) {
|
||||
y++
|
||||
}
|
||||
@ -234,8 +234,8 @@ class ChunkLight(private val chunk: Chunk) {
|
||||
// block is now higher
|
||||
// ToDo: Neighbours
|
||||
val sections = chunk.sections ?: Broken("Sections == null")
|
||||
val maxIndex = previous.sectionHeight - chunk.lowestSection
|
||||
val minIndex = now.sectionHeight - chunk.lowestSection
|
||||
val maxIndex = previous.sectionHeight - chunk.minSection
|
||||
val minIndex = now.sectionHeight - chunk.minSection
|
||||
for (index in maxIndex downTo minIndex) {
|
||||
val section = sections[index] ?: continue
|
||||
section.light.reset()
|
||||
@ -365,8 +365,8 @@ class ChunkLight(private val chunk: Chunk) {
|
||||
chunk.getOrPut(skylightStartSectionHeight - 1)
|
||||
}
|
||||
|
||||
for (sectionHeight in minOf(skylightStartSectionHeight, chunk.highestSection) downTo maxOf(maxHeightSection + 1, chunk.lowestSection)) {
|
||||
val section = chunk.sections?.get(sectionHeight - chunk.lowestSection) ?: continue
|
||||
for (sectionHeight in minOf(skylightStartSectionHeight, chunk.maxSection) downTo maxOf(maxHeightSection + 1, chunk.minSection)) {
|
||||
val section = chunk.sections?.get(sectionHeight - chunk.minSection) ?: continue
|
||||
|
||||
// ToDo: Only update if affected by heightmap change
|
||||
section.light.update = true
|
||||
@ -376,7 +376,7 @@ class ChunkLight(private val chunk: Chunk) {
|
||||
section.light.traceSkylightIncrease(x, y, z, ProtocolDefinition.MAX_LIGHT_LEVEL_I, null, baseY + y, false)
|
||||
}
|
||||
}
|
||||
if (maxHeight.sectionHeight < chunk.lowestSection) {
|
||||
if (maxHeight.sectionHeight < chunk.minSection) {
|
||||
// bottom section
|
||||
bottom.traceSkyIncrease(x, z, ProtocolDefinition.MAX_LIGHT_LEVEL_I)
|
||||
} else {
|
||||
|
@ -66,14 +66,14 @@ class SectionLight(
|
||||
val neighbours = section.neighbours ?: return
|
||||
val chunk = section.chunk
|
||||
if (y - light < 0) {
|
||||
if (section.sectionHeight == chunk?.lowestSection) {
|
||||
if (section.sectionHeight == chunk?.minSection) {
|
||||
chunk.light.bottom.decreaseCheckLevel(x, z, light - y, reset)
|
||||
} else {
|
||||
neighbours[Directions.O_DOWN]?.light?.decreaseCheckLevel(x, z, light - y, reset)
|
||||
}
|
||||
}
|
||||
if (y + light > ProtocolDefinition.SECTION_MAX_Y) {
|
||||
if (section.sectionHeight == chunk?.highestSection) {
|
||||
if (section.sectionHeight == chunk?.maxSection) {
|
||||
chunk.light.top.decreaseCheckLevel(x, z, light - (ProtocolDefinition.SECTION_MAX_Y - y), reset)
|
||||
} else {
|
||||
neighbours[Directions.O_UP]?.light?.decreaseCheckLevel(x, z, light - (ProtocolDefinition.SECTION_MAX_Y - y), reset)
|
||||
@ -159,7 +159,7 @@ class SectionLight(
|
||||
if (target == null || (target != Directions.UP && lightProperties.propagatesLight(Directions.DOWN))) {
|
||||
if (y > 0) {
|
||||
traceBlockIncrease(x, y - 1, z, neighbourLuminance, Directions.DOWN)
|
||||
} else if (section.sectionHeight == chunk.lowestSection) {
|
||||
} else if (section.sectionHeight == chunk.minSection) {
|
||||
chunk.light.bottom.traceBlockIncrease(x, z, neighbourLuminance)
|
||||
} else {
|
||||
(neighbours[Directions.O_DOWN] ?: chunk.getOrPut(section.sectionHeight - 1, false))?.light?.traceBlockIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, neighbourLuminance, Directions.DOWN)
|
||||
@ -168,7 +168,7 @@ class SectionLight(
|
||||
if (target == null || (target != Directions.DOWN && lightProperties.propagatesLight(Directions.UP))) {
|
||||
if (y < ProtocolDefinition.SECTION_MAX_Y) {
|
||||
traceBlockIncrease(x, y + 1, z, neighbourLuminance, Directions.UP)
|
||||
} else if (section.sectionHeight == chunk.highestSection) {
|
||||
} else if (section.sectionHeight == chunk.maxSection) {
|
||||
chunk.light.top.traceBlockIncrease(x, z, neighbourLuminance)
|
||||
} else {
|
||||
(neighbours[Directions.O_UP] ?: chunk.getOrPut(section.sectionHeight + 1, false))?.light?.traceBlockIncrease(x, 0, z, neighbourLuminance, Directions.UP)
|
||||
@ -351,14 +351,14 @@ class SectionLight(
|
||||
if (target != Directions.UP && (target == null || lightProperties.propagatesLight(Directions.DOWN))) {
|
||||
if (y > 0) {
|
||||
traceSkylightIncrease(x, y - 1, z, nextNeighbourLevel, Directions.DOWN, totalY - 1)
|
||||
} else if (section.sectionHeight != chunk.highestSection) {
|
||||
} else if (section.sectionHeight != chunk.maxSection) {
|
||||
(neighbours[Directions.O_DOWN] ?: chunk.getOrPut(section.sectionHeight + 1, false))?.light?.traceSkylightIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, nextNeighbourLevel, Directions.DOWN, totalY - 1)
|
||||
}
|
||||
}
|
||||
if (target != Directions.DOWN && target != null && (lightProperties.propagatesLight(Directions.UP))) {
|
||||
if (y < ProtocolDefinition.SECTION_MAX_Y) {
|
||||
traceSkylightIncrease(x, y + 1, z, nextNeighbourLevel, Directions.UP, totalY + 1)
|
||||
} else if (section.sectionHeight == chunk.lowestSection) {
|
||||
} else if (section.sectionHeight == chunk.minSection) {
|
||||
chunk.light.bottom.traceSkyIncrease(x, z, nextLevel)
|
||||
} else {
|
||||
(neighbours[Directions.O_UP] ?: chunk.getOrPut(section.sectionHeight - 1, false))?.light?.traceSkylightIncrease(x, 0, z, nextNeighbourLevel, Directions.UP, totalY + 1)
|
||||
|
@ -75,7 +75,7 @@ class ChunkNeighbours(val chunk: Chunk) {
|
||||
if (section == null) {
|
||||
continue
|
||||
}
|
||||
val sectionNeighbours = ChunkUtil.getDirectNeighbours(neighbours, chunk, index + chunk.lowestSection)
|
||||
val sectionNeighbours = ChunkUtil.getDirectNeighbours(neighbours, chunk, index + chunk.minSection)
|
||||
section.neighbours = sectionNeighbours
|
||||
}
|
||||
}
|
||||
|
@ -620,7 +620,7 @@ class WorldRenderer(
|
||||
|
||||
// ToDo: Check if chunk is visible (not section, chunk)
|
||||
var queueChanges = 0
|
||||
for (sectionHeight in chunk.lowestSection until chunk.highestSection) {
|
||||
for (sectionHeight in chunk.minSection until chunk.maxSection) {
|
||||
val section = chunk[sectionHeight] ?: continue
|
||||
val queued = internalQueueSection(chunkPosition, sectionHeight, chunk, section, false, neighbours = neighbours)
|
||||
if (queued) {
|
||||
|
@ -61,8 +61,8 @@ class SolidCullSectionPreparer(
|
||||
val random = Random(0L)
|
||||
|
||||
val randomBlockModels = profile.antiMoirePattern
|
||||
val isLowestSection = sectionHeight == chunk.lowestSection
|
||||
val isHighestSection = sectionHeight == chunk.highestSection
|
||||
val isLowestSection = sectionHeight == chunk.minSection
|
||||
val isHighestSection = sectionHeight == chunk.maxSection
|
||||
val blocks = section.blocks
|
||||
val sectionLight = section.light
|
||||
val blockEntities: MutableSet<BlockEntityRenderer<*>> = mutableSetOf()
|
||||
|
@ -34,6 +34,7 @@ import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||
import de.bixilon.minosoft.modding.event.master.EventMaster
|
||||
import de.bixilon.minosoft.protocol.network.connection.Connection
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.forceSet
|
||||
import de.bixilon.minosoft.util.KUtil.minosoft
|
||||
import org.objenesis.ObjenesisStd
|
||||
import org.testng.annotations.Test
|
||||
@ -63,10 +64,10 @@ object ChunkTestingUtil {
|
||||
fun createEmptyChunk(position: ChunkPosition): Chunk {
|
||||
val objenesis = ObjenesisStd()
|
||||
val chunk = objenesis.newInstance(Chunk::class.java)
|
||||
Chunk::highestSection.javaField!!.setValue(chunk, SECTIONS)
|
||||
Chunk::lock.javaField!!.setValue(chunk, ThreadLock())
|
||||
Chunk::chunkPosition.javaField!!.setValue(chunk, position)
|
||||
chunk::chunkPosition.forceSet(position)
|
||||
Chunk::world.javaField!!.setValue(chunk, world)
|
||||
Chunk::maxSection.javaField!!.setValue(chunk, chunk.world.dimension!!.maxSection)
|
||||
Chunk::connection.javaField!!.setValue(chunk, chunk.world.connection)
|
||||
Chunk::light.javaField!!.setValue(chunk, ChunkLight(chunk))
|
||||
Chunk::neighbours.javaField!!.setValue(chunk, ChunkNeighbours(chunk))
|
||||
|
Loading…
x
Reference in New Issue
Block a user