mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
fluid physics: reduce allocations
This commit is contained in:
parent
6fd062d19d
commit
c0bf5efe7b
@ -24,6 +24,7 @@ import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
|
||||
import de.bixilon.minosoft.data.world.positions.BlockPosition
|
||||
import de.bixilon.minosoft.gui.rendering.models.fluid.FluidModel
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY_INSTANCE
|
||||
import de.bixilon.minosoft.physics.entities.living.LivingEntityPhysics
|
||||
import de.bixilon.minosoft.physics.input.MovementInput
|
||||
import de.bixilon.minosoft.protocol.network.session.play.PlaySession
|
||||
@ -72,7 +73,7 @@ abstract class Fluid(override val identifier: ResourceLocation) : RegistryItem()
|
||||
|
||||
// ToDo: Falling fluid
|
||||
|
||||
if (velocity == Vec3d.EMPTY) {
|
||||
if (velocity == Vec3d.EMPTY_INSTANCE) {
|
||||
return velocity
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
|
||||
import de.bixilon.minosoft.data.world.positions.BlockPosition
|
||||
|
||||
data class BlockPair(
|
||||
val position: BlockPosition,
|
||||
val state: BlockState,
|
||||
val chunk: Chunk,
|
||||
var position: BlockPosition,
|
||||
var state: BlockState,
|
||||
var chunk: Chunk,
|
||||
)
|
||||
|
@ -31,6 +31,7 @@ class WorldIterator(
|
||||
private val world: World,
|
||||
private var chunk: Chunk? = null,
|
||||
) : Iterator<BlockPair> {
|
||||
private var pair: BlockPair? = null
|
||||
private var next: BlockPair? = null
|
||||
private var revision = -1
|
||||
|
||||
@ -61,7 +62,15 @@ class WorldIterator(
|
||||
}
|
||||
|
||||
val state = chunk[position.inChunkPosition] ?: continue
|
||||
this.next = BlockPair(position, state, chunk)
|
||||
|
||||
val pair = pair ?: BlockPair(position, state, chunk)
|
||||
this.pair = pair
|
||||
|
||||
pair.position = position
|
||||
pair.state = state
|
||||
pair.chunk = chunk
|
||||
this.next = pair
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,9 @@ import kotlin.math.abs
|
||||
|
||||
object Vec3dUtil {
|
||||
const val MARGIN = 0.003
|
||||
private val empty = Vec3d()
|
||||
|
||||
val Vec3d.Companion.EMPTY_INSTANCE get() = empty
|
||||
|
||||
val Vec3d.Companion.MIN: Vec3d
|
||||
get() = Vec3d(Double.MIN_VALUE, Double.MIN_VALUE, Double.MIN_VALUE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user