only poll rendering if enabled

This commit is contained in:
Bixilon 2022-05-10 23:33:00 +02:00
parent 305e0fcb75
commit 68ff96739d
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 8 additions and 4 deletions

View File

@ -18,7 +18,6 @@ import de.bixilon.minosoft.gui.eros.dialog.ErosErrorReport.Companion.report
import de.bixilon.minosoft.gui.rendering.modding.events.WindowCloseEvent
import de.bixilon.minosoft.gui.rendering.sound.AudioPlayer
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.terminal.RunConfiguration
import de.bixilon.minosoft.util.RenderPolling
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
@ -34,7 +33,7 @@ class Rendering(private val connection: PlayConnection) {
Log.log(LogMessageType.RENDERING_GENERAL, LogLevels.INFO) { "Hello LWJGL ${Version.getVersion()}!" }
latch.inc()
this.latch = latch
if (RunConfiguration.OPEN_Gl_ON_FIRST_THREAD) {
if (RenderPolling.ENABLED) {
RenderPolling.rendering = this
RenderPolling.RENDERING_LATCH.dec()
return
@ -45,7 +44,7 @@ class Rendering(private val connection: PlayConnection) {
fun start() {
val latch = this.latch ?: throw IllegalStateException("Rendering not initialized yet!")
startAudioPlayerThread(latch)
if (RunConfiguration.OPEN_Gl_ON_FIRST_THREAD) {
if (RenderPolling.ENABLED) {
startRenderWindow(latch)
} else {
startRenderWindowThread(latch)

View File

@ -16,16 +16,21 @@ package de.bixilon.minosoft.util
import de.bixilon.kutil.latch.CountUpAndDownLatch
import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.gui.rendering.Rendering
import de.bixilon.minosoft.terminal.RunConfiguration
object RenderPolling {
val RENDERING_LATCH = CountUpAndDownLatch(Int.MAX_VALUE shr 1)
var rendering: Rendering? = null
val ENABLED = RunConfiguration.OPEN_Gl_ON_FIRST_THREAD
/**
* Polls rendering (if opengl context is forced on the main thread)
* Eventually polls rendering (if opengl context is forced on the main thread)
*/
internal fun pollRendering() {
if (!ENABLED) {
return
}
check(Thread.currentThread() == Minosoft.MAIN_THREAD) { "Current thread is not the main thread!" }
while (true) {
RENDERING_LATCH.waitForChange()