mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
optimize physics a bit
This commit is contained in:
parent
5823ac17c7
commit
d939f3f7b1
@ -43,6 +43,7 @@ class EntityRenderInfo(private val entity: Entity) : Drawable, Tickable {
|
||||
|
||||
|
||||
private fun interpolatePosition(delta: Float) {
|
||||
// TODO: Only interpolate if changed
|
||||
position = Vec3Util.interpolateLinear(delta, position0, position1)
|
||||
eyePosition = position + Vec3(0.0f, entity.eyeHeight, 0.0f)
|
||||
cameraAABB = entity.defaultAABB + position
|
||||
|
@ -62,15 +62,17 @@ abstract class Entity(
|
||||
open val clientControlled: Boolean get() = primaryPassenger is LocalPlayerEntity
|
||||
|
||||
open val dimensions = Vec2(type.width, type.height)
|
||||
val defaultAABB: AABB
|
||||
get() {
|
||||
val halfWidth = dimensions.x / 2
|
||||
return AABB(Vec3(-halfWidth, 0.0f, -halfWidth), Vec3(halfWidth, dimensions.y, halfWidth))
|
||||
}
|
||||
open val defaultAABB: AABB = createDefaultAABB()
|
||||
|
||||
open val mountHeightOffset: Double get() = dimensions.y * 0.75
|
||||
open val heightOffset: Double get() = 0.0
|
||||
|
||||
|
||||
|
||||
protected fun createDefaultAABB(): AABB {
|
||||
val halfWidth = dimensions.x / 2
|
||||
return AABB(Vec3(-halfWidth, 0.0f, -halfWidth), Vec3(halfWidth, dimensions.y, halfWidth))
|
||||
}
|
||||
|
||||
open fun getDimensions(pose: Poses): Vec2? {
|
||||
return dimensions
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import de.bixilon.minosoft.data.entities.entities.SynchronizedEntityData
|
||||
import de.bixilon.minosoft.data.entities.entities.player.additional.PlayerAdditional
|
||||
import de.bixilon.minosoft.data.registries.entities.EntityType
|
||||
import de.bixilon.minosoft.data.registries.item.items.dye.DyeableItem
|
||||
import de.bixilon.minosoft.data.registries.shapes.aabb.AABB
|
||||
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.entity.EntityRenderer
|
||||
@ -79,6 +80,16 @@ abstract class PlayerEntity(
|
||||
val score: Int
|
||||
get() = data.get(SCORE_DATA, 0)
|
||||
|
||||
protected var aabbPose = pose
|
||||
override var defaultAABB: AABB = createDefaultAABB()
|
||||
get() {
|
||||
val pose = pose
|
||||
if (aabbPose == pose) return field
|
||||
field = createDefaultAABB()
|
||||
aabbPose = pose
|
||||
return field
|
||||
}
|
||||
|
||||
val skinParts: MutableSet<SkinParts> by observedSet(mutableSetOf())
|
||||
|
||||
|
||||
|
@ -24,6 +24,7 @@ import de.bixilon.minosoft.gui.rendering.util.VecUtil.toVec3d
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.get
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.max
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.min
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
|
||||
abstract class AbstractVoxelShape : Iterable<AABB> {
|
||||
abstract val aabbs: Int
|
||||
@ -109,7 +110,7 @@ abstract class AbstractVoxelShape : Iterable<AABB> {
|
||||
when (data) {
|
||||
is Int -> return this[data]
|
||||
is Collection<*> -> {
|
||||
val aabbs: MutableSet<AABB> = mutableSetOf()
|
||||
val aabbs: MutableSet<AABB> = ObjectOpenHashSet()
|
||||
for (id in data) {
|
||||
aabbs += this[id.toInt()]
|
||||
}
|
||||
@ -123,7 +124,7 @@ abstract class AbstractVoxelShape : Iterable<AABB> {
|
||||
when (data) {
|
||||
is Int -> return VoxelShape(aabbs[data])
|
||||
is Collection<*> -> {
|
||||
val shape: MutableSet<AABB> = mutableSetOf()
|
||||
val shape: MutableSet<AABB> = ObjectOpenHashSet()
|
||||
for (id in data) {
|
||||
shape += aabbs[id.toInt()]
|
||||
}
|
||||
|
@ -31,12 +31,13 @@ import de.bixilon.minosoft.data.world.positions.ChunkPositionUtil.inChunkPositio
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3Util.set
|
||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
|
||||
import de.bixilon.minosoft.physics.entities.EntityPhysics
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
import kotlin.math.abs
|
||||
|
||||
object CollisionMovementPhysics {
|
||||
|
||||
fun World.collectCollisions(context: CollisionContext, movement: Vec3d, aabb: AABB, chunk: Chunk?, predicate: CollisionPredicate? = null): VoxelShape {
|
||||
val shapes: MutableSet<AABB> = hashSetOf()
|
||||
val shapes: MutableSet<AABB> = ObjectOpenHashSet()
|
||||
// TODO: add entity collisions (boat, shulker)
|
||||
// TODO: add world border collision shape
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user