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