mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
rendering: don't update screen when not focused
This commit is contained in:
parent
28f9c508a8
commit
7e7059e35a
@ -14,6 +14,7 @@ import org.lwjgl.*
|
|||||||
import org.lwjgl.glfw.Callbacks
|
import org.lwjgl.glfw.Callbacks
|
||||||
import org.lwjgl.glfw.GLFW.*
|
import org.lwjgl.glfw.GLFW.*
|
||||||
import org.lwjgl.glfw.GLFWErrorCallback
|
import org.lwjgl.glfw.GLFWErrorCallback
|
||||||
|
import org.lwjgl.glfw.GLFWWindowFocusCallback
|
||||||
import org.lwjgl.glfw.GLFWWindowSizeCallback
|
import org.lwjgl.glfw.GLFWWindowSizeCallback
|
||||||
import org.lwjgl.opengl.*
|
import org.lwjgl.opengl.*
|
||||||
import org.lwjgl.opengl.GL11.*
|
import org.lwjgl.opengl.GL11.*
|
||||||
@ -33,6 +34,8 @@ class RenderWindow(private val connection: Connection, val rendering: Rendering)
|
|||||||
lateinit var camera: Camera
|
lateinit var camera: Camera
|
||||||
private val latch = CountUpAndDownLatch(1)
|
private val latch = CountUpAndDownLatch(1)
|
||||||
|
|
||||||
|
private var renderingPaused = false
|
||||||
|
|
||||||
// all renderers
|
// all renderers
|
||||||
val chunkRenderer: ChunkRenderer = ChunkRenderer(connection, connection.player.world, this)
|
val chunkRenderer: ChunkRenderer = ChunkRenderer(connection, connection.player.world, this)
|
||||||
val hudRenderer: HUDRenderer = HUDRenderer(connection, this)
|
val hudRenderer: HUDRenderer = HUDRenderer(connection, this)
|
||||||
@ -149,6 +152,12 @@ class RenderWindow(private val connection: Connection, val rendering: Rendering)
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
glfwSetWindowFocusCallback(windowId, object : GLFWWindowFocusCallback() {
|
||||||
|
override fun invoke(window: Long, focused: Boolean) {
|
||||||
|
renderingPaused = !focused
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
hudRenderer.screenChangeResizeCallback(screenWidth, screenHeight)
|
hudRenderer.screenChangeResizeCallback(screenWidth, screenHeight)
|
||||||
|
|
||||||
@ -166,9 +175,12 @@ class RenderWindow(private val connection: Connection, val rendering: Rendering)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun startRenderLoop() {
|
fun startRenderLoop() {
|
||||||
var lastPositionChangeTime = 0.0
|
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(windowId)) {
|
while (!glfwWindowShouldClose(windowId)) {
|
||||||
|
if (renderingPaused) {
|
||||||
|
glfwSwapBuffers(windowId)
|
||||||
|
glfwPollEvents()
|
||||||
|
continue
|
||||||
|
}
|
||||||
renderStats.startFrame()
|
renderStats.startFrame()
|
||||||
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) // clear the framebuffer
|
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) // clear the framebuffer
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user