mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
heightmap: use section height
index is prune to errors and not very natural
This commit is contained in:
parent
dc43b0c266
commit
d2d45008b0
@ -43,17 +43,11 @@ abstract class ChunkHeightmap(protected val chunk: Chunk) : Heightmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun trace(position: InChunkPosition, notify: Boolean) {
|
private fun trace(position: InChunkPosition, notify: Boolean) {
|
||||||
val sections = chunk.sections
|
|
||||||
|
|
||||||
var y = Int.MIN_VALUE
|
var y = Int.MIN_VALUE
|
||||||
val index = position.xz
|
val index = position.xz
|
||||||
|
|
||||||
sectionLoop@ for (sectionIndex in (position.y.sectionHeight - chunk.minSection) downTo 0) {
|
sectionLoop@ for (sectionHeight in position.y.sectionHeight downTo chunk.minSection) {
|
||||||
if (sectionIndex >= sections.size) {
|
val section = chunk[sectionHeight] ?: continue
|
||||||
// starting from above world
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
val section = sections[sectionIndex] ?: continue
|
|
||||||
if (section.blocks.isEmpty) continue
|
if (section.blocks.isEmpty) continue
|
||||||
|
|
||||||
val min = section.blocks.minPosition
|
val min = section.blocks.minPosition
|
||||||
@ -63,11 +57,11 @@ abstract class ChunkHeightmap(protected val chunk: Chunk) : Heightmap {
|
|||||||
|
|
||||||
|
|
||||||
for (sectionY in max.y downTo min.y) {
|
for (sectionY in max.y downTo min.y) {
|
||||||
val state = section.blocks[InSectionPosition((sectionY shl 8) or index)] ?: continue
|
val state = section.blocks[InSectionPosition(index).with(y = sectionY)] ?: continue
|
||||||
val pass = passes(state)
|
val pass = passes(state)
|
||||||
if (pass == HeightmapPass.PASSES) continue
|
if (pass == HeightmapPass.PASSES) continue
|
||||||
|
|
||||||
y = (sectionIndex + chunk.minSection) * ProtocolDefinition.SECTION_HEIGHT_Y + sectionY
|
y = sectionHeight * ProtocolDefinition.SECTION_HEIGHT_Y + sectionY
|
||||||
if (pass == HeightmapPass.ABOVE) y++
|
if (pass == HeightmapPass.ABOVE) y++
|
||||||
|
|
||||||
break@sectionLoop
|
break@sectionLoop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user