gui: tick async

This commit is contained in:
Bixilon 2022-08-15 11:04:36 +02:00
parent 00c7097b02
commit 0cc758c864
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4

View File

@ -27,21 +27,28 @@ interface GUIElementDrawer {
fun drawElements(elements: Collection<GUIElement>) { fun drawElements(elements: Collection<GUIElement>) {
val time = TimeUtil.millis val time = TimeUtil.millis
val tickLatch = CountUpAndDownLatch(1)
if (time - lastTickTime > ProtocolDefinition.TICK_TIME) { if (time - lastTickTime > ProtocolDefinition.TICK_TIME) {
for (element in elements) { for (element in elements) {
if (!element.enabled) { if (!element.enabled) {
continue continue
} }
tickLatch.inc()
DefaultThreadPool += {
element.tick() element.tick()
if (element is Pollable) { if (element is Pollable) {
if (element.poll()) { if (element.poll()) {
element.apply() element.apply()
} }
} }
tickLatch.dec()
}
} }
lastTickTime = time lastTickTime = time
} }
tickLatch.dec()
tickLatch.await()
val latch = CountUpAndDownLatch(1) val latch = CountUpAndDownLatch(1)
for (element in elements) { for (element in elements) {