mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
top and bottom light
This commit is contained in:
parent
3cda1d88a1
commit
14bac6d1fd
@ -50,8 +50,8 @@ class Chunk(
|
||||
var biomeSource: BiomeSource? = null,
|
||||
) : Iterable<ChunkSection?>, BiomeAccessor {
|
||||
private val world = connection.world
|
||||
var bottomLight = BorderSectionLight(false)
|
||||
var topLight = BorderSectionLight(true)
|
||||
var bottomLight = BorderSectionLight(false, this)
|
||||
var topLight = BorderSectionLight(true, this)
|
||||
val lowestSection = world.dimension!!.minSection
|
||||
val highestSection = world.dimension!!.maxSection
|
||||
val cacheBiomes = world.cacheBiomeAccessor != null
|
||||
@ -246,7 +246,7 @@ class Chunk(
|
||||
|
||||
var section = sections[sectionIndex]
|
||||
if (section == null) {
|
||||
section = ChunkSection(sectionHeight, BlockSectionDataProvider(occlusionUpdateCallback = world.occlusionUpdateCallback))
|
||||
section = ChunkSection(sectionHeight, BlockSectionDataProvider(occlusionUpdateCallback = world.occlusionUpdateCallback), chunk = this)
|
||||
val cacheBiomeAccessor = world.cacheBiomeAccessor
|
||||
val neighbours = this.neighbours
|
||||
if (neighbours != null) {
|
||||
|
@ -34,6 +34,7 @@ class ChunkSection(
|
||||
var blocks: BlockSectionDataProvider,
|
||||
var biomes: SectionDataProvider<Biome> = SectionDataProvider(checkSize = false),
|
||||
var blockEntities: SectionDataProvider<BlockEntity?> = SectionDataProvider(checkSize = false),
|
||||
var chunk: Chunk? = null,
|
||||
) {
|
||||
var light = SectionLight(this)
|
||||
var neighbours: Array<ChunkSection?>? = null
|
||||
@ -86,7 +87,7 @@ class ChunkSection(
|
||||
val z = blockOffset.z
|
||||
val biomes: Array<Biome?> = arrayOfNulls(ProtocolDefinition.BLOCKS_PER_SECTION)
|
||||
for (index in 0 until ProtocolDefinition.BLOCKS_PER_SECTION) {
|
||||
biomes[index] = biomeAccessor.getBiome(x + (index and 0x0F), y + ((index shr 8) and 0x0F), z + ((index shr 4) and 0x0F), chunkPositionX, chunkPositionZ, chunk, neighbours) //!!
|
||||
biomes[index] = biomeAccessor.getBiome(x + (index and 0x0F), y + ((index shr 8) and 0x0F), z + ((index shr 4) and 0x0F), chunkPositionX, chunkPositionZ, chunk, neighbours)
|
||||
}
|
||||
this.biomes.setData(biomes.unsafeCast())
|
||||
}
|
||||
|
@ -13,10 +13,13 @@
|
||||
|
||||
package de.bixilon.minosoft.data.world.chunk.light
|
||||
|
||||
import de.bixilon.minosoft.data.world.chunk.Chunk
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
|
||||
@Deprecated("Not yet implemented")
|
||||
class BorderSectionLight(val top: Boolean) : AbstractSectionLight() {
|
||||
class BorderSectionLight(
|
||||
val top: Boolean,
|
||||
val chunk: Chunk,
|
||||
) : AbstractSectionLight() {
|
||||
val light = ByteArray(ProtocolDefinition.SECTION_WIDTH_X * ProtocolDefinition.SECTION_WIDTH_Z)
|
||||
|
||||
override fun get(x: Int, y: Int, z: Int): Byte {
|
||||
@ -39,6 +42,59 @@ class BorderSectionLight(val top: Boolean) : AbstractSectionLight() {
|
||||
return z shl 4 or x
|
||||
}
|
||||
|
||||
internal fun traceIncrease(x: Int, z: Int, nextLuminance: Int) {
|
||||
val index = z shl 4 or x
|
||||
val currentLight = light[index].toInt() and 0x0F
|
||||
if (currentLight >= nextLuminance) {
|
||||
// light is already higher, no need to trace
|
||||
return
|
||||
}
|
||||
this.light[index] = ((this.light[index].toInt() and 0xF0) or nextLuminance).toByte()
|
||||
|
||||
if (!update) {
|
||||
update = true
|
||||
}
|
||||
|
||||
|
||||
if (nextLuminance == 1) {
|
||||
// we can not further increase the light
|
||||
return
|
||||
}
|
||||
val neighbourLuminance = nextLuminance - 1
|
||||
|
||||
if (top) {
|
||||
chunk.sections?.last()?.light?.traceIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, neighbourLuminance)
|
||||
} else {
|
||||
chunk.sections?.first()?.light?.traceIncrease(x, 0, z, neighbourLuminance)
|
||||
}
|
||||
|
||||
if (z > 0) {
|
||||
traceIncrease(x, z - 1, neighbourLuminance)
|
||||
} else {
|
||||
val neighbour = chunk.neighbours?.get(3)
|
||||
(if (top) neighbour?.topLight else neighbour?.bottomLight)?.traceIncrease(x, ProtocolDefinition.SECTION_MAX_Z, neighbourLuminance)
|
||||
}
|
||||
if (z < ProtocolDefinition.SECTION_MAX_Y) {
|
||||
traceIncrease(x, z + 1, neighbourLuminance)
|
||||
} else {
|
||||
val neighbour = chunk.neighbours?.get(4)
|
||||
(if (top) neighbour?.topLight else neighbour?.bottomLight)?.traceIncrease(x, 0, neighbourLuminance)
|
||||
}
|
||||
|
||||
if (x > 0) {
|
||||
traceIncrease(x - 1, z, neighbourLuminance)
|
||||
} else {
|
||||
val neighbour = chunk.neighbours?.get(1)
|
||||
(if (top) neighbour?.topLight else neighbour?.bottomLight)?.traceIncrease(ProtocolDefinition.SECTION_MAX_X, z, neighbourLuminance)
|
||||
}
|
||||
if (x < ProtocolDefinition.SECTION_MAX_X) {
|
||||
traceIncrease(x + 1, z, neighbourLuminance)
|
||||
} else {
|
||||
val neighbour = chunk.neighbours?.get(6)
|
||||
(if (top) neighbour?.topLight else neighbour?.bottomLight)?.traceIncrease(0, z, neighbourLuminance)
|
||||
}
|
||||
}
|
||||
|
||||
fun update(array: ByteArray) {
|
||||
// ToDo: Save light from server
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ class SectionLight(
|
||||
}
|
||||
|
||||
private fun decreaseCheckX(z: Int, light: Int) {
|
||||
recalculate()
|
||||
|
||||
val neighbours = section.neighbours ?: return
|
||||
|
||||
@ -85,7 +84,7 @@ class SectionLight(
|
||||
}
|
||||
}
|
||||
|
||||
private fun traceIncrease(x: Int, y: Int, z: Int, nextLuminance: Int) {
|
||||
fun traceIncrease(x: Int, y: Int, z: Int, nextLuminance: Int) {
|
||||
val index = getIndex(x, y, z)
|
||||
val block = section.blocks.unsafeGet(index)
|
||||
val blockLuminance = block?.luminance ?: 0
|
||||
@ -121,11 +120,15 @@ class SectionLight(
|
||||
|
||||
if (y > 0) {
|
||||
traceIncrease(x, y - 1, z, neighbourLuminance)
|
||||
} else if (section.sectionHeight == section.chunk?.lowestSection) {
|
||||
section.chunk?.bottomLight?.traceIncrease(x, z, neighbourLuminance)
|
||||
} else {
|
||||
neighbours[Directions.O_DOWN]?.light?.traceIncrease(x, ProtocolDefinition.SECTION_MAX_Y, z, neighbourLuminance)
|
||||
}
|
||||
if (y < ProtocolDefinition.SECTION_MAX_Y) {
|
||||
traceIncrease(x, y + 1, z, neighbourLuminance)
|
||||
} else if (section.sectionHeight == section.chunk?.highestSection) {
|
||||
section.chunk?.topLight?.traceIncrease(x, z, neighbourLuminance)
|
||||
} else {
|
||||
neighbours[Directions.O_UP]?.light?.traceIncrease(x, 0, z, neighbourLuminance)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user