mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -04:00
move chunk neighbour tracing to chunk neighbours
This commit is contained in:
parent
fa3e45043d
commit
fbf95e4f8d
@ -73,7 +73,7 @@ object WorldTestUtil {
|
||||
if (chunk == null) {
|
||||
chunk = this.chunks[chunkPosition] ?: continue
|
||||
} else if (chunk.chunkPosition != chunkPosition) {
|
||||
chunk = chunk.traceChunk(chunkPosition - chunk.chunkPosition) ?: continue
|
||||
chunk = chunk.neighbours.trace(chunkPosition - chunk.chunkPosition) ?: continue
|
||||
}
|
||||
for (y in start.y..end.y) {
|
||||
val section = chunk.getOrPut(y.sectionHeight) ?: continue
|
||||
@ -96,7 +96,7 @@ object WorldTestUtil {
|
||||
for (z in (start.z shr 4)..(end.z shr 4)) {
|
||||
val chunkPosition = Vec2i(x, z)
|
||||
chunk = if (chunk != null) {
|
||||
chunk.traceChunk(chunkPosition - chunk.chunkPosition) ?: continue
|
||||
chunk.neighbours.trace(chunkPosition - chunk.chunkPosition) ?: continue
|
||||
} else {
|
||||
this.chunks[chunkPosition] ?: continue
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class TargetHandler(
|
||||
if (chunk == null) {
|
||||
chunk = camera.connection.world.chunks[chunkPosition] ?: break
|
||||
} else if (chunk.chunkPosition != chunkPosition) {
|
||||
chunk = chunk.traceChunk(chunkPosition - chunk.chunkPosition) ?: break
|
||||
chunk = chunk.neighbours.trace(chunkPosition - chunk.chunkPosition) ?: break
|
||||
}
|
||||
val state = chunk[blockPosition.inChunkPosition] ?: continue
|
||||
if (state.block is FluidBlock) {
|
||||
|
@ -54,7 +54,7 @@ abstract class Fluid(override val identifier: ResourceLocation) : RegistryItem()
|
||||
|
||||
val offset = blockPosition.inChunkPosition
|
||||
for (direction in Directions.SIDES) {
|
||||
val neighbour = chunk.traceBlock(offset + direction) ?: continue
|
||||
val neighbour = chunk.neighbours.traceBlock(offset + direction) ?: continue
|
||||
if (!this.matches(neighbour)) {
|
||||
continue
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ class World(
|
||||
chunkDelta.x = (origin.x - position.x) shr 4
|
||||
chunkDelta.y = (origin.z - position.z) shr 4
|
||||
|
||||
val state = chunk.traceBlock(position.x and 0x0F, position.y, position.z and 0x0F, chunkDelta) ?: return
|
||||
val state = chunk.neighbours.traceBlock(position.x and 0x0F, position.y, position.z and 0x0F, chunkDelta) ?: return
|
||||
if (state.block !is RandomDisplayTickable) return
|
||||
if (!state.block.hasRandomTicks(connection, state, position)) return
|
||||
|
||||
|
@ -15,7 +15,6 @@ package de.bixilon.minosoft.data.world.chunk.chunk
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.concurrent.lock.thread.ThreadLock
|
||||
import de.bixilon.kutil.exception.Broken
|
||||
import de.bixilon.kutil.math.simple.IntMath.clamp
|
||||
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
||||
import de.bixilon.minosoft.data.direction.Directions
|
||||
@ -31,15 +30,12 @@ import de.bixilon.minosoft.data.world.chunk.neighbours.ChunkNeighbours
|
||||
import de.bixilon.minosoft.data.world.chunk.update.block.ChunkLocalBlockUpdate
|
||||
import de.bixilon.minosoft.data.world.chunk.update.block.SingleBlockUpdate
|
||||
import de.bixilon.minosoft.data.world.positions.ChunkPosition
|
||||
import de.bixilon.minosoft.data.world.positions.ChunkPositionUtil.chunkPosition
|
||||
import de.bixilon.minosoft.data.world.positions.InChunkPosition
|
||||
import de.bixilon.minosoft.data.world.positions.SectionHeight
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inSectionHeight
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.sectionHeight
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.inChunkPosition
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.chunk.ChunkUtil
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@ -65,10 +61,6 @@ class Chunk(
|
||||
light.heightmap.recalculate()
|
||||
}
|
||||
|
||||
@Deprecated("neighbours.complete", ReplaceWith("neighbours.complete"))
|
||||
val isFullyLoaded: Boolean
|
||||
get() = neighbours.complete
|
||||
|
||||
operator fun get(sectionHeight: SectionHeight): ChunkSection? = sections.getOrNull(sectionHeight - minSection)
|
||||
|
||||
operator fun get(x: Int, y: Int, z: Int): BlockState? {
|
||||
@ -203,7 +195,7 @@ class Chunk(
|
||||
if (neighbours != null) {
|
||||
for (neighbour in neighbours) {
|
||||
val neighbourNeighbours = neighbour.neighbours.get() ?: continue
|
||||
neighbour.updateNeighbours(neighbourNeighbours, sectionHeight)
|
||||
neighbour.neighbours.update(neighbourNeighbours, sectionHeight)
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,67 +227,6 @@ class Chunk(
|
||||
}
|
||||
return biomeSource.getBiome(x and 0x0F, y, z and 0x0F)
|
||||
}
|
||||
|
||||
@Deprecated("")
|
||||
private fun updateNeighbours(neighbours: Array<Chunk>, sectionHeight: Int) {
|
||||
for (nextSectionHeight in sectionHeight - 1..sectionHeight + 1) {
|
||||
if (nextSectionHeight < minSection || nextSectionHeight > maxSection) {
|
||||
continue
|
||||
}
|
||||
|
||||
val section = this[nextSectionHeight] ?: continue
|
||||
val sectionNeighbours = ChunkUtil.getDirectNeighbours(neighbours, this, nextSectionHeight)
|
||||
section.neighbours = sectionNeighbours
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("neighbours")
|
||||
fun traceBlock(offset: Vec3i, origin: Vec3i, blockPosition: Vec3i = origin + offset): BlockState? {
|
||||
val chunkDelta = (origin - blockPosition).chunkPosition
|
||||
|
||||
return traceBlock(blockPosition.x and 0x0F, blockPosition.y, blockPosition.z and 0x0F, chunkDelta)
|
||||
}
|
||||
|
||||
@Deprecated("neighbours")
|
||||
fun traceBlock(offset: Vec3i): BlockState? {
|
||||
return traceBlock(offset.inChunkPosition, offset.chunkPosition)
|
||||
}
|
||||
|
||||
@Deprecated("neighbours")
|
||||
fun traceChunk(offset: Vec2i): Chunk? {
|
||||
if (offset.x == 0 && offset.y == 0) {
|
||||
return this
|
||||
}
|
||||
|
||||
if (offset.x > 0) {
|
||||
offset.x--
|
||||
return neighbours[6]?.traceChunk(offset)
|
||||
}
|
||||
if (offset.x < 0) {
|
||||
offset.x++
|
||||
return neighbours[1]?.traceChunk(offset)
|
||||
}
|
||||
if (offset.y > 0) {
|
||||
offset.y--
|
||||
return neighbours[4]?.traceChunk(offset)
|
||||
}
|
||||
if (offset.y < 0) {
|
||||
offset.y++
|
||||
return neighbours[3]?.traceChunk(offset)
|
||||
}
|
||||
|
||||
Broken("Can not get chunk from offset: $offset")
|
||||
}
|
||||
|
||||
@Deprecated("neighbours")
|
||||
private fun traceBlock(inChunkPosition: Vec3i, chunkOffset: Vec2i): BlockState? {
|
||||
return traceChunk(chunkOffset)?.get(inChunkPosition)
|
||||
}
|
||||
|
||||
@Deprecated("neighbours")
|
||||
fun traceBlock(x: Int, y: Int, z: Int, chunkOffset: Vec2i): BlockState? {
|
||||
return traceChunk(chunkOffset)?.get(x, y, z)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,12 +14,16 @@
|
||||
package de.bixilon.minosoft.data.world.chunk.neighbours
|
||||
|
||||
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.kutil.exception.Broken
|
||||
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
|
||||
import de.bixilon.minosoft.data.world.biome.accessor.NoiseBiomeAccessor
|
||||
import de.bixilon.minosoft.data.world.chunk.ChunkSection
|
||||
import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
|
||||
import de.bixilon.minosoft.data.world.positions.ChunkPositionUtil.chunkPosition
|
||||
import de.bixilon.minosoft.data.world.positions.SectionHeight
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.inChunkPosition
|
||||
import de.bixilon.minosoft.util.chunk.ChunkUtil
|
||||
|
||||
class ChunkNeighbours(val chunk: Chunk) : Iterable<Chunk?> {
|
||||
@ -100,6 +104,68 @@ class ChunkNeighbours(val chunk: Chunk) : Iterable<Chunk?> {
|
||||
return neighbours.iterator()
|
||||
}
|
||||
|
||||
|
||||
fun update(neighbours: Array<Chunk>, sectionHeight: Int) {
|
||||
for (nextSectionHeight in sectionHeight - 1..sectionHeight + 1) {
|
||||
if (nextSectionHeight < chunk.minSection || nextSectionHeight > chunk.maxSection) {
|
||||
continue
|
||||
}
|
||||
|
||||
val section = chunk[nextSectionHeight] ?: continue
|
||||
val sectionNeighbours = ChunkUtil.getDirectNeighbours(neighbours, chunk, nextSectionHeight)
|
||||
section.neighbours = sectionNeighbours
|
||||
}
|
||||
}
|
||||
|
||||
fun trace(offset: Vec2i): Chunk? {
|
||||
if (offset.x == 0 && offset.y == 0) {
|
||||
return chunk
|
||||
}
|
||||
|
||||
val chunk = when {
|
||||
offset.x > 0 -> {
|
||||
offset.x--
|
||||
this[6]
|
||||
}
|
||||
|
||||
offset.x < 0 -> {
|
||||
offset.x++
|
||||
this[1]
|
||||
}
|
||||
|
||||
offset.y < 0 -> {
|
||||
offset.y--
|
||||
this[4]
|
||||
}
|
||||
|
||||
offset.y > 0 -> {
|
||||
offset.y++
|
||||
this[3]
|
||||
}
|
||||
|
||||
else -> Broken("Can not get chunk from offset: $offset")
|
||||
}
|
||||
return chunk?.neighbours?.trace(offset)
|
||||
}
|
||||
|
||||
fun traceBlock(offset: Vec3i, origin: Vec3i, blockPosition: Vec3i = origin + offset): BlockState? {
|
||||
val chunkDelta = (origin - blockPosition).chunkPosition
|
||||
|
||||
return traceBlock(blockPosition.x and 0x0F, blockPosition.y, blockPosition.z and 0x0F, chunkDelta)
|
||||
}
|
||||
|
||||
fun traceBlock(offset: Vec3i): BlockState? {
|
||||
return traceBlock(offset.inChunkPosition, offset.chunkPosition)
|
||||
}
|
||||
|
||||
private fun traceBlock(inChunkPosition: Vec3i, chunkOffset: Vec2i): BlockState? {
|
||||
return trace(chunkOffset)?.get(inChunkPosition)
|
||||
}
|
||||
|
||||
fun traceBlock(x: Int, y: Int, z: Int, chunkOffset: Vec2i): BlockState? {
|
||||
return trace(chunkOffset)?.get(x, y, z)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val COUNT = 8
|
||||
const val NORTH = 3
|
||||
|
@ -57,7 +57,7 @@ class WorldIterator(
|
||||
} else if (chunk.chunkPosition != chunkPosition) {
|
||||
offset.x = chunkPosition.x - chunk.chunkPosition.x
|
||||
offset.y = chunkPosition.y - chunk.chunkPosition.y
|
||||
chunk = chunk.traceChunk(offset) ?: continue
|
||||
chunk = chunk.neighbours.trace(offset) ?: continue
|
||||
}
|
||||
if (this.chunk !== chunk) {
|
||||
this.chunk = chunk
|
||||
|
@ -55,7 +55,7 @@ abstract class RenderParticle(connection: PlayConnection, position: Vec3d, veloc
|
||||
inChunk.y = position.y
|
||||
inChunk.z = position.z and 0x0F
|
||||
|
||||
val light = chunk.traceChunk(offset)?.light?.get(inChunk) ?: SectionLight.SKY_LIGHT_MASK
|
||||
val light = chunk.neighbours.trace(offset)?.light?.get(inChunk) ?: SectionLight.SKY_LIGHT_MASK
|
||||
if (light and SectionLight.BLOCK_LIGHT_MASK > maxBlockLight) {
|
||||
maxBlockLight = light and SectionLight.BLOCK_LIGHT_MASK
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ class SkyboxRenderer(
|
||||
val x = offset.x + xOffset
|
||||
val y = offset.y + yOffset
|
||||
val z = offset.z + zOffset
|
||||
val neighbour = chunk.traceChunk(Vec2i(x shr 4, z shr 4)) ?: continue
|
||||
val neighbour = chunk.neighbours.trace(Vec2i(x shr 4, z shr 4)) ?: continue
|
||||
val biome = neighbour.getBiome(x and 0x0F, y, z and 0x0F) ?: continue
|
||||
|
||||
count++
|
||||
|
@ -63,7 +63,7 @@ class EntityPositionInfo(
|
||||
val chunks = physics.entity.connection.world.chunks
|
||||
val revision = chunks.revision
|
||||
|
||||
var chunk = if (previous.revision == revision) previous.chunk?.traceChunk(chunkPosition - previous.chunkPosition) else null
|
||||
var chunk = if (previous.revision == revision) previous.chunk?.neighbours?.trace(chunkPosition - previous.chunkPosition) else null
|
||||
|
||||
if (chunk == null) {
|
||||
chunk = chunks[chunkPosition]
|
||||
|
@ -72,7 +72,7 @@ class ExplosionS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
||||
} else if (chunk.chunkPosition != chunkPosition) {
|
||||
chunkOffset.x = chunkPosition.x - chunk.chunkPosition.x
|
||||
chunkOffset.y = chunkPosition.y - chunk.chunkPosition.y
|
||||
chunk = chunk.traceChunk(chunkOffset) ?: continue
|
||||
chunk = chunk.neighbours.trace(chunkOffset) ?: continue
|
||||
}
|
||||
|
||||
val inChunkPosition = total.inChunkPosition
|
||||
|
Loading…
x
Reference in New Issue
Block a user