mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
only recalculate frustum when position changes (performance)
This commit is contained in:
parent
b7aa711581
commit
fa5d41f7e0
@ -24,9 +24,9 @@ import glm_.vec4.Vec4
|
|||||||
|
|
||||||
class GUIMeshCache(
|
class GUIMeshCache(
|
||||||
val matrix: Mat4,
|
val matrix: Mat4,
|
||||||
initialCahceSize: Int = 1000,
|
initialCacheSize: Int = 1000,
|
||||||
) : GUIVertexConsumer {
|
) : GUIVertexConsumer {
|
||||||
val data: ArrayFloatList = ArrayFloatList(initialCahceSize)
|
val data: ArrayFloatList = ArrayFloatList(initialCacheSize)
|
||||||
|
|
||||||
override fun addVertex(position: Vec2t<*>, z: Int, texture: AbstractTexture, uv: Vec2, tint: RGBColor) {
|
override fun addVertex(position: Vec2t<*>, z: Int, texture: AbstractTexture, uv: Vec2, tint: RGBColor) {
|
||||||
val outPosition = matrix * Vec4(position.x.toFloat(), position.y.toFloat(), 1.0f, 1.0f)
|
val outPosition = matrix * Vec4(position.x.toFloat(), position.y.toFloat(), 1.0f, 1.0f)
|
||||||
|
@ -100,6 +100,11 @@ class Camera(
|
|||||||
var viewProjectionMatrix = projectionMatrix * viewMatrix
|
var viewProjectionMatrix = projectionMatrix * viewMatrix
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
|
||||||
|
var previousPosition = Vec3d(connection.player.position)
|
||||||
|
var previousRotation = connection.player.rotation.copy()
|
||||||
|
var previousZoom = zoom
|
||||||
|
|
||||||
private var lastDropPacketSent = -1L
|
private var lastDropPacketSent = -1L
|
||||||
|
|
||||||
val frustum: Frustum = Frustum(this)
|
val frustum: Frustum = Frustum(this)
|
||||||
@ -265,7 +270,14 @@ class Camera(
|
|||||||
connection.fireEvent(FrustumChangeEvent(renderWindow, frustum))
|
connection.fireEvent(FrustumChangeEvent(renderWindow, frustum))
|
||||||
connection.fireEvent(CameraPositionChangeEvent(renderWindow, connection.player.eyePosition))
|
connection.fireEvent(CameraPositionChangeEvent(renderWindow, connection.player.eyePosition))
|
||||||
|
|
||||||
// recalculate sky color for current biome
|
previousPosition = Vec3d(connection.player.position)
|
||||||
|
previousRotation = connection.player.rotation.copy()
|
||||||
|
previousZoom = zoom
|
||||||
|
|
||||||
|
setSkyColor()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setSkyColor() {
|
||||||
renderWindow[SkyRenderer.Companion]?.let { skyRenderer ->
|
renderWindow[SkyRenderer.Companion]?.let { skyRenderer ->
|
||||||
skyRenderer.baseColor = connection.world.getBiome(connection.player.positionInfo.blockPosition)?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR
|
skyRenderer.baseColor = connection.world.getBiome(connection.player.positionInfo.blockPosition)?.skyColor ?: RenderConstants.DEFAULT_SKY_COLOR
|
||||||
|
|
||||||
@ -330,8 +342,12 @@ class Camera(
|
|||||||
} else {
|
} else {
|
||||||
0.0f
|
0.0f
|
||||||
}
|
}
|
||||||
// ToDo: Only update if changed
|
|
||||||
|
if (previousPosition != connection.player.position || previousRotation != connection.player.rotation || zoom != previousZoom) {
|
||||||
onPositionChange()
|
onPositionChange()
|
||||||
|
} else {
|
||||||
|
setSkyColor()
|
||||||
|
}
|
||||||
|
|
||||||
val eyePosition = connection.player.eyePosition
|
val eyePosition = connection.player.eyePosition
|
||||||
val cameraFront = cameraFront
|
val cameraFront = cameraFront
|
||||||
|
Loading…
x
Reference in New Issue
Block a user