mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 02:45:13 -04:00
entity render info: don't force interpolation every frame/tick
This commit is contained in:
parent
e7eee27513
commit
fbd4ae8cfe
@ -20,37 +20,56 @@ import de.bixilon.minosoft.data.entities.entities.Entity
|
|||||||
import de.bixilon.minosoft.data.registries.shapes.aabb.AABB
|
import de.bixilon.minosoft.data.registries.shapes.aabb.AABB
|
||||||
import de.bixilon.minosoft.gui.rendering.renderer.drawable.Drawable
|
import de.bixilon.minosoft.gui.rendering.renderer.drawable.Drawable
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.blockPosition
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.EMPTY
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.addedY
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
|
|
||||||
class EntityRenderInfo(private val entity: Entity) : Drawable, Tickable {
|
class EntityRenderInfo(private val entity: Entity) : Drawable, Tickable {
|
||||||
private var position0 = Vec3d(entity.physics.position)
|
private var position0 = Vec3d.EMPTY
|
||||||
private var position1 = position0
|
private var position1 = Vec3d(entity.physics.position)
|
||||||
|
private var defaultAABB = entity.defaultAABB
|
||||||
|
|
||||||
var position: Vec3d = position0
|
var position: Vec3d = position1
|
||||||
private set
|
private set
|
||||||
var eyePosition: Vec3d = position
|
var eyePosition: Vec3d = position
|
||||||
private set
|
private set
|
||||||
var cameraAABB: AABB = AABB.EMPTY
|
var cameraAABB: AABB = AABB.EMPTY
|
||||||
private set
|
private set
|
||||||
var eyeBlockPosition = position1.blockPosition
|
|
||||||
private set
|
|
||||||
|
|
||||||
private var rotation0 = entity.physics.rotation
|
private var rotation0 = EntityRotation.EMPTY
|
||||||
private var rotation1 = rotation0
|
private var rotation1 = entity.physics.rotation
|
||||||
var rotation: EntityRotation = rotation0
|
var rotation: EntityRotation = rotation1
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
|
||||||
private fun interpolatePosition(delta: Float) {
|
private fun interpolatePosition(delta: Float) {
|
||||||
// TODO: Only interpolate if changed
|
val position1 = this.position1
|
||||||
|
|
||||||
|
if (position == position1) {
|
||||||
|
interpolateAABB(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
position = Vec3dUtil.interpolateLinear(delta.toDouble(), position0, position1)
|
position = Vec3dUtil.interpolateLinear(delta.toDouble(), position0, position1)
|
||||||
eyePosition = position + Vec3d(0.0, entity.eyeHeight.toDouble(), 0.0)
|
eyePosition = position.addedY(entity.eyeHeight.toDouble())
|
||||||
cameraAABB = entity.defaultAABB + position
|
|
||||||
eyeBlockPosition = position1.blockPosition
|
interpolateAABB(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun interpolateAABB(force: Boolean) {
|
||||||
|
val defaultAABB = entity.defaultAABB
|
||||||
|
if (!force && this.defaultAABB == defaultAABB) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cameraAABB = defaultAABB + position
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun interpolateRotation(delta: Float) {
|
private fun interpolateRotation(delta: Float) {
|
||||||
|
val rotation1 = this.rotation1
|
||||||
|
if (rotation == rotation1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val rotation0 = this.rotation0
|
||||||
rotation = EntityRotation(interpolateLinear(delta, rotation0.yaw, rotation1.yaw), interpolateLinear(delta, rotation0.pitch, rotation1.pitch))
|
rotation = EntityRotation(interpolateLinear(delta, rotation0.yaw, rotation1.yaw), interpolateLinear(delta, rotation0.pitch, rotation1.pitch))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,11 +79,24 @@ class EntityRenderInfo(private val entity: Entity) : Drawable, Tickable {
|
|||||||
interpolateRotation(delta)
|
interpolateRotation(delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tick() {
|
private fun tickPosition() {
|
||||||
|
val entityPosition = entity.physics.position
|
||||||
|
if (position0 == entityPosition && position1 == entityPosition) return
|
||||||
|
|
||||||
position0 = position1
|
position0 = position1
|
||||||
position1 = Vec3d(entity.physics.position)
|
position1 = entityPosition
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun tickRotation() {
|
||||||
|
val entityRotation = entity.physics.rotation
|
||||||
|
if (rotation0 == entityRotation && rotation1 == entityRotation) return
|
||||||
|
|
||||||
rotation0 = rotation1
|
rotation0 = rotation1
|
||||||
rotation1 = entity.physics.rotation
|
rotation1 = entityRotation
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun tick() {
|
||||||
|
tickPosition()
|
||||||
|
tickRotation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
|
|||||||
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
|
||||||
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||||
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.blockPosition
|
||||||
import de.bixilon.minosoft.gui.rendering.world.WorldRenderer
|
import de.bixilon.minosoft.gui.rendering.world.WorldRenderer
|
||||||
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
|
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
|
||||||
import de.bixilon.minosoft.properties.MinosoftProperties
|
import de.bixilon.minosoft.properties.MinosoftProperties
|
||||||
@ -291,7 +292,7 @@ class DebugHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Layouted
|
|||||||
|
|
||||||
this@DebugWorldInfo += AutoTextElement(guiRenderer, 1) { BaseComponent("Sky properties ", entity.connection.world.dimension.effects) }
|
this@DebugWorldInfo += AutoTextElement(guiRenderer, 1) { BaseComponent("Sky properties ", entity.connection.world.dimension.effects) }
|
||||||
this@DebugWorldInfo += AutoTextElement(guiRenderer, 1) { BaseComponent("Biome ", biome) }
|
this@DebugWorldInfo += AutoTextElement(guiRenderer, 1) { BaseComponent("Biome ", biome) }
|
||||||
this@DebugWorldInfo += AutoTextElement(guiRenderer, 1) { with(entity.connection.world.getLight(entity.renderInfo.eyeBlockPosition)) { BaseComponent("Light block=", (this and SectionLight.BLOCK_LIGHT_MASK), ", sky=", ((this and SectionLight.SKY_LIGHT_MASK) shr 4)) } }
|
this@DebugWorldInfo += AutoTextElement(guiRenderer, 1) { with(entity.connection.world.getLight(entity.renderInfo.eyePosition.blockPosition)) { BaseComponent("Light block=", (this and SectionLight.BLOCK_LIGHT_MASK), ", sky=", ((this and SectionLight.SKY_LIGHT_MASK) shr 4)) } }
|
||||||
this@DebugWorldInfo += AutoTextElement(guiRenderer, 1) { BaseComponent("Fully loaded: ", chunk.neighbours.complete) }
|
this@DebugWorldInfo += AutoTextElement(guiRenderer, 1) { BaseComponent("Fully loaded: ", chunk.neighbours.complete) }
|
||||||
|
|
||||||
lastChunk.value = chunk
|
lastChunk.value = chunk
|
||||||
|
@ -150,10 +150,16 @@ object Vec3dUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Vec3d.addY(y: Double): Vec3d {
|
fun Vec3d.addedY(y: Double): Vec3d {
|
||||||
val res = Vec3d(this)
|
val res = Vec3d(this)
|
||||||
res.y += y
|
res.y += y
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Vec3d.assign(other: Vec3d) {
|
||||||
|
this.x = other.x
|
||||||
|
this.y = other.y
|
||||||
|
this.z = other.z
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import de.bixilon.minosoft.data.world.positions.ChunkPositionUtil.sectionHeight
|
|||||||
import de.bixilon.minosoft.data.world.positions.InChunkPosition
|
import de.bixilon.minosoft.data.world.positions.InChunkPosition
|
||||||
import de.bixilon.minosoft.data.world.positions.InChunkSectionPosition
|
import de.bixilon.minosoft.data.world.positions.InChunkSectionPosition
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.addY
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.addedY
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.blockPosition
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3dUtil.blockPosition
|
||||||
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.EMPTY
|
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.EMPTY
|
||||||
import de.bixilon.minosoft.physics.entities.EntityPhysics
|
import de.bixilon.minosoft.physics.entities.EntityPhysics
|
||||||
@ -54,7 +54,7 @@ class EntityPositionInfo(
|
|||||||
val blockPosition = position.blockPosition
|
val blockPosition = position.blockPosition
|
||||||
val chunkPosition = blockPosition.chunkPosition
|
val chunkPosition = blockPosition.chunkPosition
|
||||||
val sectionHeight = blockPosition.sectionHeight
|
val sectionHeight = blockPosition.sectionHeight
|
||||||
val eyePosition = position.addY(physics.entity.eyeHeight.toDouble()).blockPosition
|
val eyePosition = position.addedY(physics.entity.eyeHeight.toDouble()).blockPosition
|
||||||
val inChunkPosition = blockPosition.inChunkPosition
|
val inChunkPosition = blockPosition.inChunkPosition
|
||||||
val inSectionPosition = blockPosition.inChunkSectionPosition
|
val inSectionPosition = blockPosition.inChunkSectionPosition
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user