mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 01:16:46 -04:00
particle: cache chunk, chunk iterating improvements
This commit is contained in:
parent
6bfab14947
commit
ab6ee0bb16
@ -35,11 +35,13 @@ class WorldIterator(
|
||||
private var chunk: Chunk? = null,
|
||||
) : Iterator<BlockPair> {
|
||||
private var next: BlockPair? = null
|
||||
private var revision = -1
|
||||
|
||||
|
||||
constructor(aabb: AABB, world: World, chunk: Chunk? = null) : this(aabb.positions(), world, chunk)
|
||||
|
||||
private fun update(): Boolean {
|
||||
if (world.chunks.chunks.unsafe.isEmpty()) return false
|
||||
if (!iterator.hasNext()) return false
|
||||
|
||||
var chunk = this.chunk
|
||||
@ -53,7 +55,9 @@ class WorldIterator(
|
||||
chunkPosition.assignChunkPosition(position)
|
||||
|
||||
if (chunk == null) {
|
||||
chunk = world.chunks[chunkPosition] ?: continue // TODO: Don't query same chunk multiple times
|
||||
if (revision == world.chunks.revision) continue // previously found no chunk, can not find it now
|
||||
this.revision = world.chunks.revision
|
||||
chunk = world.chunks[chunkPosition] ?: continue
|
||||
} else if (chunk.chunkPosition != chunkPosition) {
|
||||
offset.x = chunkPosition.x - chunk.chunkPosition.x
|
||||
offset.y = chunkPosition.y - chunk.chunkPosition.y
|
||||
|
@ -71,7 +71,7 @@ open class BlockFeature(
|
||||
}
|
||||
|
||||
override fun draw(mesh: BlockMesh) {
|
||||
renderer.renderer.context.system.reset(faceCulling = false)
|
||||
renderer.renderer.context.system.set(EntityLayer.Translucent.settings)
|
||||
val shader = renderer.renderer.features.block.shader
|
||||
draw(mesh, shader)
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ open class ItemFeature(
|
||||
}
|
||||
|
||||
override fun draw(mesh: BlockMesh) {
|
||||
renderer.renderer.context.system.reset(faceCulling = false)
|
||||
renderer.renderer.context.system.set(EntityLayer.Translucent.settings)
|
||||
val shader = renderer.renderer.features.block.shader
|
||||
draw(mesh, shader)
|
||||
}
|
||||
@ -132,7 +132,7 @@ open class ItemFeature(
|
||||
EXTREME(48.0),
|
||||
;
|
||||
|
||||
val distance = distance * distance
|
||||
val distance = distance * distance * distance
|
||||
|
||||
companion object {
|
||||
|
||||
|
@ -21,6 +21,7 @@ import de.bixilon.minosoft.data.physics.PhysicsEntity
|
||||
import de.bixilon.minosoft.data.registries.blocks.shapes.collision.context.ParticleCollisionContext
|
||||
import de.bixilon.minosoft.data.registries.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.data.registries.shapes.aabb.AABB
|
||||
import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleFactory
|
||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleMesh
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plusAssign
|
||||
@ -52,6 +53,9 @@ abstract class Particle(
|
||||
protected val random = Random()
|
||||
private var lastTickTime = -1L
|
||||
|
||||
private var chunk: Chunk? = null
|
||||
private var chunkRevision = -1
|
||||
|
||||
// ageing
|
||||
var dead = false
|
||||
var age: Int = 0
|
||||
@ -89,6 +93,23 @@ abstract class Particle(
|
||||
aabb = AABB(Vec3d(x, aabb.min.y, z), Vec3d(x + spacing.x, aabb.min.y + spacing.y, z + spacing.z))
|
||||
}
|
||||
|
||||
protected fun getChunk(): Chunk? {
|
||||
val revision = connection.world.chunks.revision
|
||||
var chunk = this.chunk
|
||||
|
||||
if (chunk != null) {
|
||||
if (chunk.chunkPosition == this.chunkPosition) return chunk
|
||||
chunk = chunk.neighbours.trace(chunkPosition - chunk.chunkPosition)
|
||||
}
|
||||
if (chunk == null && revision != this.chunkRevision) {
|
||||
chunk = connection.world.chunks[chunkPosition]
|
||||
this.chunk = chunk
|
||||
this.chunkRevision = revision
|
||||
}
|
||||
|
||||
return chunk
|
||||
}
|
||||
|
||||
|
||||
init {
|
||||
this.velocity += { (random.nextDouble() * 2.0 - 1.0) * MAGIC_VELOCITY_CONSTANT }
|
||||
@ -117,7 +138,7 @@ abstract class Particle(
|
||||
private fun collide(movement: Vec3d): Vec3d {
|
||||
val aabb = aabb + movement
|
||||
val context = ParticleCollisionContext(this)
|
||||
val collisions = connection.world.collectCollisions(context, movement, aabb, null) // TODO: cache chunk
|
||||
val collisions = connection.world.collectCollisions(context, movement, aabb, getChunk())
|
||||
val adjusted = collide(movement, aabb, collisions)
|
||||
if (adjusted.y != movement.y) {
|
||||
onGround = true
|
||||
|
@ -43,7 +43,7 @@ abstract class RenderParticle(connection: PlayConnection, position: Vec3d, veloc
|
||||
var maxSkyLight = 0
|
||||
|
||||
val chunkPosition = position.chunkPosition
|
||||
val chunk = connection.world.chunks[chunkPosition] ?: return maxBlockLight
|
||||
val chunk = getChunk() ?: return maxBlockLight
|
||||
|
||||
val offset = Vec2i.EMPTY
|
||||
val inChunk = Vec3i()
|
||||
|
Loading…
x
Reference in New Issue
Block a user