optimize render loop a bit

This commit is contained in:
Moritz Zwerger 2025-03-09 22:45:51 +01:00
parent e37426f2a9
commit 6fca18a475
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 18 additions and 8 deletions

View File

@ -253,6 +253,7 @@ class AABB {
operator fun contains(position: Vec3i): Boolean { operator fun contains(position: Vec3i): Boolean {
return position.x in getRange(min.x, max.x) && position.y in getRange(min.y, max.y) && position.z in getRange(min.z, max.z) return position.x in getRange(min.x, max.x) && position.y in getRange(min.y, max.y) && position.z in getRange(min.z, max.z)
} }
operator fun contains(position: BlockPosition): Boolean { operator fun contains(position: BlockPosition): Boolean {
return position.x in getRange(min.x, max.x) && position.y in getRange(min.y, max.y) && position.z in getRange(min.z, max.z) return position.x in getRange(min.x, max.x) && position.y in getRange(min.y, max.y) && position.z in getRange(min.z, max.z)
} }

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2024 Moritz Zwerger * Copyright (C) 2020-2025 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -62,12 +62,20 @@ class RenderLoop(
if (context.state == RenderingStates.QUITTING || context.session.established || !context.state.active) { if (context.state == RenderingStates.QUITTING || context.session.established || !context.state.active) {
break break
} }
context.renderStats.startFrame() context.renderStats.startFrame()
context.framebuffer.clear() context.framebuffer.clear()
context.system.framebuffer = null context.system.framebuffer = null
context.system.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER) context.system.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER)
context.window.pollEvents()
context.input.draw(deltaFrameTime)
context.camera.draw()
context.system.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER)
context.light.updateAsync() // ToDo: do async context.light.updateAsync() // ToDo: do async
context.light.update() context.light.update()
@ -89,18 +97,19 @@ class RenderLoop(
context.system.reset() // Reset to enable depth mask, etc again context.system.reset() // Reset to enable depth mask, etc again
// handle opengl context tasks, but limit it per frame
context.queue.workTimeLimited(RenderConstants.MAXIMUM_QUEUE_TIME_PER_FRAME)
context.renderStats.endDraw() context.renderStats.endDraw()
context.window.pollEvents()
context.window.swapBuffers() context.window.swapBuffers()
context.window.pollEvents()
context.input.draw(deltaFrameTime) // glClear waits for any unfinished operation, so it might swill wait for the buffer swap and makes frame times really long.
context.camera.draw() context.framebuffer.clear()
context.system.framebuffer = null
context.system.clear(IntegratedBufferTypes.COLOR_BUFFER, IntegratedBufferTypes.DEPTH_BUFFER)
// handle opengl context tasks, but limit it per frame
context.queue.workTimeLimited(RenderConstants.MAXIMUM_QUEUE_TIME_PER_FRAME)
if (context.state == RenderingStates.SLOW && slowRendering) { if (context.state == RenderingStates.SLOW && slowRendering) {
Thread.sleep(100L) Thread.sleep(100L)