minor test performance improvements

- ChunkHeightmap is now only calculated if dimension has light (aka. only in light tests)
- occlusion culling and light is just updated when dimension has light (world filling)
- ...
This commit is contained in:
Moritz Zwerger 2023-07-29 18:33:26 +02:00
parent bd549a1355
commit 9ec4eb8278
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 9 additions and 8 deletions

View File

@ -91,6 +91,8 @@ object WorldTestUtil {
} }
} }
if (!dimension.light && !dimension.skyLight) return // no need for occlusion when light is ignored
if (superUnsafe) { if (superUnsafe) {
for (x in (start.x shr 4)..(end.x shr 4)) { for (x in (start.x shr 4)..(end.x shr 4)) {
for (z in (start.z shr 4)..(end.z shr 4)) { for (z in (start.z shr 4)..(end.z shr 4)) {
@ -107,9 +109,7 @@ object WorldTestUtil {
} }
} }
} }
if (dimension.light || dimension.skyLight) { recalculateLight(heightmap = true) // yah, might break the result, don't use fill if you want to test light
recalculateLight(heightmap = true) // yah, might break the result, don't use fill if you want to test light
}
} }
private val DATA = SectionDataProvider::class.java.getDeclaredField("data").apply { isAccessible = true } private val DATA = SectionDataProvider::class.java.getDeclaredField("data").apply { isAccessible = true }

View File

@ -34,7 +34,7 @@ abstract class ChunkHeightmap(protected val chunk: Chunk) : Heightmap {
val maxY = (chunk.maxSection + 1) * ProtocolDefinition.SECTION_HEIGHT_Y val maxY = (chunk.maxSection + 1) * ProtocolDefinition.SECTION_HEIGHT_Y
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) { for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) { for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) {
trace(x, maxY, z, false) trace(x, maxY, z, false)
} }
} }

View File

@ -18,6 +18,6 @@ import de.bixilon.minosoft.data.registries.dimension.DimensionProperties
object ChunkLightUtil { object ChunkLightUtil {
fun DimensionProperties.hasSkyLight(): Boolean { fun DimensionProperties.hasSkyLight(): Boolean {
return this.skyLight || this.effects.skyLight return this.light && this.skyLight
} }
} }

View File

@ -128,7 +128,7 @@ class ChunkSkyLight(val light: ChunkLight) {
private fun floodFill() { private fun floodFill() {
val neighbours = this.chunk.neighbours.get() ?: return val neighbours = this.chunk.neighbours.get() ?: return
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) { for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) { for (x in 0 until ProtocolDefinition.SECTION_WIDTH_X) {
floodFill(neighbours, x, z) floodFill(neighbours, x, z)
} }
} }

View File

@ -275,7 +275,7 @@ class SectionLight(
private fun propagateX(baseY: Int, neighbours: Array<ChunkSection?>) { private fun propagateX(baseY: Int, neighbours: Array<ChunkSection?>) {
for (y in 0 until ProtocolDefinition.SECTION_HEIGHT_Y) { for (y in 0 until ProtocolDefinition.SECTION_HEIGHT_Y) {
for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) { for (z in 0 until ProtocolDefinition.SECTION_WIDTH_Z) {
val totalY = baseY + y val totalY = baseY + y
neighbours[Directions.O_WEST]?.light?.get(ProtocolDefinition.SECTION_MAX_Z, y, z)?.toInt()?.let { light -> 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) } (light and BLOCK_LIGHT_MASK).let { if (it > 1) traceBlockIncrease(0, y, z, it - 1, Directions.EAST) }

View File

@ -135,7 +135,8 @@ class ChunkManager(val world: World, chunkCapacity: Int = 0, prototypeCapacity:
size.onCreate(chunk.chunkPosition) size.onCreate(chunk.chunkPosition)
world.view.updateServerDistance() world.view.updateServerDistance()
val updates = hashSetOf<AbstractWorldUpdate>(ChunkCreateUpdate(chunk.chunkPosition, chunk)) val updates = HashSet<AbstractWorldUpdate>(9, 1.0f)
updates += ChunkCreateUpdate(chunk.chunkPosition, chunk)
for (index in 0 until ChunkNeighbours.COUNT) { for (index in 0 until ChunkNeighbours.COUNT) {
val offset = ChunkNeighbours.OFFSETS[index] val offset = ChunkNeighbours.OFFSETS[index]