From 843781cfe6ce752f890a51457d07297b940846f5 Mon Sep 17 00:00:00 2001 From: soywiz Date: Thu, 4 Mar 2021 17:27:25 +0100 Subject: [PATCH] Sync from next --- gradle.properties | 2 +- .../kotlin/com/soywiz/korgw/GameWindow.kt | 17 ++++++++++++++--- .../kotlin/com/soywiz/korui/UiButton.kt | 4 ++-- .../kotlin/com/soywiz/korui/UiComponent.kt | 6 +++--- .../kotlin/com/soywiz/korui/UiContainer.kt | 2 +- .../kotlin/com/soywiz/korui/UiScrollPanel.kt | 4 ++-- .../kotlin/com/soywiz/korui/UiWindow.kt | 6 +++--- .../kotlin/com/soywiz/korgw/awt/AwtExt.kt | 12 ++++++++++++ .../com/soywiz/korgw/awt/BaseAwtGameWindow.kt | 2 +- 9 files changed, 39 insertions(+), 16 deletions(-) diff --git a/gradle.properties b/gradle.properties index c9d7b8e..46dabb8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ easyPluginVersion=0.13.0 group=com.soywiz.korlibs.korgw version=2.0.0-SNAPSHOT -korimVersion=2.0.7 +korimVersion=2.0.8 jnaVersion=5.7.0 # bintray location diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt b/korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt index 937e1c3..5b2d26a 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt @@ -2,6 +2,7 @@ package com.soywiz.korgw import com.soywiz.kds.* import com.soywiz.klock.* +import com.soywiz.klogger.* import com.soywiz.kmem.setBits import com.soywiz.korag.* import com.soywiz.korag.log.* @@ -107,13 +108,19 @@ open class GameWindowCoroutineDispatcher : CoroutineDispatcher(), Delay, Closeab item.continuation?.resume(Unit) item.callback?.run() } - if ((now() - startTime) >= availableTime) break + if ((now() - startTime) >= availableTime) { + informTooMuchCallbacksToHandleInThisFrame() + break + } } while (tasks.isNotEmpty()) { val task = tasks.dequeue() task?.run() - if ((now() - startTime) >= availableTime) break + if ((now() - startTime) >= availableTime) { + informTooMuchCallbacksToHandleInThisFrame() + break + } } } catch (e: Throwable) { println("Error in GameWindowCoroutineDispatcher.executePending:") @@ -121,6 +128,10 @@ open class GameWindowCoroutineDispatcher : CoroutineDispatcher(), Delay, Closeab } } + open fun informTooMuchCallbacksToHandleInThisFrame() { + //Console.warn("Too much callbacks to handle in this frame") + } + override fun close() { executePending(1.seconds) println("GameWindowCoroutineDispatcher.close") @@ -216,7 +227,7 @@ open class GameWindow : EventDispatcher.Mixin(), DialogInterface, Closeable, Cor return 60 } - private val fpsCached by IntTimedCache(100.milliseconds) { computeDisplayRefreshRate() } + private val fpsCached by IntTimedCache(1000.milliseconds) { computeDisplayRefreshRate() } open var fps: Int get() = fpsCached diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiButton.kt b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiButton.kt index b7f6287..07ec413 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiButton.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiButton.kt @@ -5,8 +5,8 @@ import com.soywiz.korio.util.* import com.soywiz.korui.native.* open class UiButton(app: UiApplication, val button: NativeUiFactory.NativeButton = app.factory.createButton()) : UiComponent(app, button) { - var icon by redirect(button::icon) - var text by redirect(button::text) + var icon by button::icon + var text by button::text } inline fun UiContainer.button(text: String = "Button", noinline onClick: (UiButton.(MouseEvent) -> Unit)? = null, block: UiButton.() -> Unit = {}): UiButton = diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiComponent.kt b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiComponent.kt index 4ed9d90..d46893f 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiComponent.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiComponent.kt @@ -37,14 +37,14 @@ open class UiComponent(val app: UiApplication, val component: NativeUiFactory.Na component.visible = value root?.relayout() } - var enabled by redirect(component::enabled) + var enabled by component::enabled open var bounds: RectangleInt get() = component.bounds set(value) { component.bounds = value } - var cursor by redirect(component::cursor) - var focusable by redirect(component::focusable) + var cursor by component::cursor + var focusable by component::focusable open fun copyFrom(that: UiComponent) { this.visible = that.visible diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiContainer.kt b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiContainer.kt index 9930ded..84ce121 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiContainer.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiContainer.kt @@ -12,7 +12,7 @@ open class UiContainer(app: UiApplication, val container: NativeUiFactory.Native private val _children = arrayListOf() val numChildren: Int get() = _children.size val size: Int get() = numChildren - var backgroundColor: RGBA? by redirect(container::backgroundColor) + var backgroundColor: RGBA? by container::backgroundColor var layout: UiLayout? = VerticalUiLayout diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiScrollPanel.kt b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiScrollPanel.kt index 56a88e9..d008d8f 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiScrollPanel.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiScrollPanel.kt @@ -4,8 +4,8 @@ import com.soywiz.korio.util.* import com.soywiz.korui.native.* open class UiScrollPanel(app: UiApplication, val panel: NativeUiFactory.NativeScrollPanel = app.factory.createScrollPanel()) : UiContainer(app, panel) { - var xbar by redirect(panel::xbar) - var ybar by redirect(panel::ybar) + var xbar by panel::xbar + var ybar by panel::ybar } inline fun UiContainer.scrollPanel(xbar: Boolean? = null, ybar: Boolean? = null, block: UiScrollPanel.() -> Unit = {}): UiScrollPanel { diff --git a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiWindow.kt b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiWindow.kt index 82ea9db..f9e5db3 100644 --- a/korgw/src/commonMain/kotlin/com/soywiz/korui/UiWindow.kt +++ b/korgw/src/commonMain/kotlin/com/soywiz/korui/UiWindow.kt @@ -6,7 +6,7 @@ import com.soywiz.korio.util.* import com.soywiz.korui.native.* open class UiWindow(app: UiApplication, val window: NativeUiFactory.NativeWindow = app.factory.createWindow()) : UiContainer(app, window) { - var title by redirect(window::title) - var menu by redirect(window::menu) - val pixelFactory by redirect(window::pixelFactor) + var title by window::title + var menu by window::menu + val pixelFactory by window::pixelFactor } diff --git a/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/AwtExt.kt b/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/AwtExt.kt index 6308743..b8060ac 100644 --- a/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/AwtExt.kt +++ b/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/AwtExt.kt @@ -1,6 +1,9 @@ package com.soywiz.korgw.awt +import com.soywiz.kds.WeakMap +import com.soywiz.kds.getOrPut import com.soywiz.kds.iterators.* +import com.soywiz.klogger.Console import java.awt.* private val ge = GraphicsEnvironment.getLocalGraphicsEnvironment() @@ -15,6 +18,15 @@ fun Window.getScreenDevice(): GraphicsDevice { return ge.defaultScreenDevice } +private val cachedRefreshRates = WeakMap() + +val GraphicsDevice.cachedRefreshRate: Int get() { + return cachedRefreshRates.getOrPut(this) { + Console.info("COMPUTED REFRESH RATE for $it") + it.displayMode.refreshRate + } +} + fun Component.getContainerFrame(): Frame? = getAncestor { it is Frame } as? Frame? fun Component.getAncestor(cond: (Component) -> Boolean): Component? { diff --git a/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/BaseAwtGameWindow.kt b/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/BaseAwtGameWindow.kt index 7a88453..1e6f6d0 100644 --- a/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/BaseAwtGameWindow.kt +++ b/korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/BaseAwtGameWindow.kt @@ -586,6 +586,6 @@ abstract class BaseAwtGameWindow : GameWindow() { override fun computeDisplayRefreshRate(): Int { val window = this.window ?: return 60 - return window.getScreenDevice().displayMode.refreshRate + return window.getScreenDevice().cachedRefreshRate } }