Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Sync from next
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Mar 4, 2021
1 parent cb0e22e commit 843781c
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions korgw/src/commonMain/kotlin/com/soywiz/korgw/GameWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -107,20 +108,30 @@ 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:")
e.printStackTrace()
}
}

open fun informTooMuchCallbacksToHandleInThisFrame() {
//Console.warn("Too much callbacks to handle in this frame")
}

override fun close() {
executePending(1.seconds)
println("GameWindowCoroutineDispatcher.close")
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions korgw/src/commonMain/kotlin/com/soywiz/korui/UiButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions korgw/src/commonMain/kotlin/com/soywiz/korui/UiComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open class UiContainer(app: UiApplication, val container: NativeUiFactory.Native
private val _children = arrayListOf<UiComponent>()
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

Expand Down
4 changes: 2 additions & 2 deletions korgw/src/commonMain/kotlin/com/soywiz/korui/UiScrollPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions korgw/src/commonMain/kotlin/com/soywiz/korui/UiWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions korgw/src/jvmMain/kotlin/com/soywiz/korgw/awt/AwtExt.kt
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -15,6 +18,15 @@ fun Window.getScreenDevice(): GraphicsDevice {
return ge.defaultScreenDevice
}

private val cachedRefreshRates = WeakMap<GraphicsDevice, Int>()

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? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 843781c

Please sign in to comment.