This commit is contained in:
kornerr committed 2026-11-18 23:07:29 +03:00
1 parent 98100e8f41
commit 0b17911989
19 files changed
+55 -47

No files matched your search

+9 -8
View File
@@ -1,7 +1,6 @@
package org.opengamestudio
import android.opengl.GLSurfaceView
import java.util.concurrent.FutureTask
fun renderDeinit(vm: RenderVM) {
val view = vm.glView!!
@@ -12,14 +11,16 @@ fun renderDeinit(vm: RenderVM) {
}
fun renderInit(vm: RenderVM) {
val view = vm.glView!!
val task = FutureTask {
raybriLoadExtensions()
raybriInit()
raybriLoadExtensions()
raybriInit()
}
fun renderPrepareGL(vm: RenderVM) {
vm.glView!!.queueEvent {
renderInit(vm)
vm.didPrepareGL = true
renderStartTimer(vm)
}
view.queueEvent(task)
// Complete initialization before Dialect publishes didPrepareGL
task.get()
}
fun renderResetUISize(vm: RenderVM) {
+6
View File
@@ -23,6 +23,12 @@ func renderInit(_ vm: RenderVM) {
raybriInit()
}
func renderPrepareGL(_ vm: RenderVM) {
renderInit(vm)
vm.didPrepareGL = true
renderStartTimer(vm)
}
func renderResetUISize(_ vm: RenderVM) {
renderSet(F.uiSize, renderUISize(vm.glView))
}
@@ -16,6 +16,12 @@ func renderInit(_ vm: RenderVM) {
raybriInit()
}
func renderPrepareGL(_ vm: RenderVM) {
renderInit(vm)
vm.didPrepareGL = true
renderStartTimer(vm)
}
func renderStartTimer(_ vm: RenderVM) {
// GTK's frame clock schedules repaints on the GTK main thread
vm.tickCallback = gtk_widget_add_tick_callback(vm.glView.widgetPointer, { _, _, _ in
+6
View File
@@ -20,6 +20,12 @@ func renderInit(_ vm: RenderVM) {
raybriInit()
}
func renderPrepareGL(_ vm: RenderVM) {
renderInit(vm)
vm.didPrepareGL = true
renderStartTimer(vm)
}
func renderResetUISize(_ vm: RenderVM) {
renderSet(F.uiSize, renderUISize(vm.glView))
}
@@ -22,6 +22,12 @@ func renderInit(_ vm: RenderVM) {
raybriInit()
}
func renderPrepareGL(_ vm: RenderVM) {
renderInit(vm)
vm.didPrepareGL = true
renderStartTimer(vm)
}
func renderStartTimer(_ vm: RenderVM) {
// WinUI's composition event drives frames on the UI thread
vm.frameCallback = CompositionTarget.rendering.addHandler { [weak vm] _, _ in
+1 -1
View File
@@ -29,7 +29,7 @@ Add game state and transitions to `HCMContext` and `HCMComponent` first. Preserv
The Android target follows `hello-selection/ver-android`. The app's `dialect.yml` generates Kotlin for Android and Swift for macOS and iOS. `GLSurfaceView` receives touch input and runs the same tile drawing sequence through the JNI Raybri bridge. Kotlin files in `components/hcm/android` mirror the game helpers and display the stats and Restart button in Compose.
Touch input, Restart, delayed HCM updates and both Dialect controllers run on the main UI thread. Surface callbacks post their state notifications to that thread. `renderInit` and `renderDeinit` queue native graphics work on the GL thread, where `onDrawFrame` also draws. `renderInit` waits for its GL task to finish before returning, so Dialect's following assignment publishes `RenderVM.didPrepareGL` only after initialization completes. The volatile VM flag gates drawing and is reset on surface creation and deinitialization. RenderVM publishes changing drawing fields through volatile references, and each frame captures the arrays it uses, allowing UI updates to appear in a later frame. The view measures its UI size on the main thread and publishes that size for drawing too.
Touch input, Restart, delayed HCM updates and both Dialect controllers run on the main UI thread. Surface callbacks post their state notifications to that thread. The single `didPrepareGL` oneliner calls `renderPrepareGL`. On Android that effect queues all three steps on GL: `renderInit`, setting `RenderVM.didPrepareGL`, and `renderStartTimer`. This preserves their order without blocking main. Swift performs the same three steps synchronously. `renderDeinit` queues cleanup on GL, where `onDrawFrame` also draws. The VM flag is read and written on GL, gates drawing, and is reset on surface creation and deinitialization. RenderVM publishes changing drawing fields through volatile references, and each frame captures the arrays it uses, allowing UI updates to appear in a later frame. The view measures its UI size on the main thread and publishes that size for drawing too.
From the app directory, start Ollama with `qwen2.5-coder:7b` available, then generate and build with the Android SDK and JDK configured.
+2 -1
View File
@@ -2526,7 +2526,8 @@ func convQueuePrompt(
_ queue: [String],
_ id: Int
) -> String {
let src = CONV_PREFIX_SWIFT + String(id) + "\n" + queue[id]
// Keep the queue index separate from the numbered conversion examples
let src = CONV_PREFIX_SWIFT + "0\n" + queue[id]
return CONV_PROMPT_PREFIX + src + CONV_PROMPT_SUFFIX
}
+1 -3
View File
@@ -242,9 +242,7 @@ RenderComponent:
oneliners:
- cameraPosition: RenderVM.shared!.cameraPosition = c.cameraPosition
- cameraZoom: RenderVM.shared!.cameraZoom = c.cameraZoom
- didPrepareGL: renderInit(RenderVM.shared!)
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
- didPrepareGL: renderStartTimer(RenderVM.shared!)
- didPrepareGL: renderPrepareGL(RenderVM.shared!)
- hiddenItemIds: RenderVM.shared!.hiddenItemIds = c.hiddenItemIds
- itemColors: RenderVM.shared!.itemColors = c.itemColors
- itemPositions: RenderVM.shared!.itemPositions = c.itemPositions
@@ -1090,18 +1090,16 @@ fun renderRegisterEffects(ctrl: DialectController) {
registerOneliners(ctrl, arrayOf(
F.cameraPosition, { c: RenderContext -> RenderVM.shared!!.cameraPosition = c.cameraPosition },
F.cameraZoom, { c: RenderContext -> RenderVM.shared!!.cameraZoom = c.cameraZoom },
F.didPrepareGL, { c: RenderContext -> renderInit(RenderVM.shared!!) },
F.didPrepareGL, { c: RenderContext -> RenderVM.shared!!.didPrepareGL = true },
F.didPrepareGL, { c: RenderContext -> renderStartTimer(RenderVM.shared!!) },
F.didPrepareGL, { c: RenderContext -> renderPrepareGL(RenderVM.shared!!) },
F.hiddenItemIds, { c: RenderContext -> RenderVM.shared!!.hiddenItemIds = c.hiddenItemIds },
F.itemColors, { c: RenderContext -> RenderVM.shared!!.itemColors = c.itemColors },
F.itemPositions, { c: RenderContext -> RenderVM.shared!!.itemPositions = c.itemPositions },
F.items, { c: RenderContext -> RenderVM.shared!!.items = c.items },
F.matchedItemIds, { c: RenderContext -> RenderVM.shared!!.matchedItemIds = c.matchedItemIds },
F.matchedItemIds, { c: RenderContext -> RenderVM.shared!!.matchedItemIds = c.matchedItemIds },
F.pointerDownPos, { c: RenderContext -> hcmSet(F.pointerDownPos, c.pointerDownPos) },
F.pixelSize, { c: RenderContext -> RenderVM.shared!!.pixelSize = c.pixelSize },
F.pixelSize, { c: RenderContext -> RenderVM.shared!!.pixelSize = c.pixelSize },
F.pixelSize, { c: RenderContext -> renderResetUISize(RenderVM.shared!!) },
F.selectionPair, { c: RenderContext -> RenderVM.shared!!.selectionPair = c.selectionPair },
F.selectionPair, { c: RenderContext -> RenderVM.shared!!.selectionPair = c.selectionPair },
F.uiSize, { c: RenderContext -> hcmSet(F.uiSize, c.uiSize) },
F.willDeinit, { c: RenderContext -> renderDeinit(RenderVM.shared!!) },
F.willRecreateSurface, { c: RenderContext -> renderRecreateSurface(RenderVM.shared!!) },
@@ -6,7 +6,7 @@ object RenderVM {
var androidContext: Context? = null
var cameraPosition = arrayOf<Float>()
var cameraZoom = 0f
@Volatile var didPrepareGL = false
var didPrepareGL = false
var glView: RenderGLView? = null
@Volatile var hiddenItemIds = arrayOf<Int>()
@Volatile var itemColors = arrayOf<HCMItemColor>()
@@ -1110,9 +1110,7 @@ func renderRegisterEffects(_ ctrl: DialectController) {
let _: RenderContext? = registerOneliners(ctrl, [
F.cameraPosition, { (c: RenderContext) in RenderVM.shared!.cameraPosition = c.cameraPosition },
F.cameraZoom, { (c: RenderContext) in RenderVM.shared!.cameraZoom = c.cameraZoom },
F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) },
F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true },
F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
F.didPrepareGL, { (c: RenderContext) in renderPrepareGL(RenderVM.shared!) },
F.hiddenItemIds, { (c: RenderContext) in RenderVM.shared!.hiddenItemIds = c.hiddenItemIds },
F.itemColors, { (c: RenderContext) in RenderVM.shared!.itemColors = c.itemColors },
F.itemPositions, { (c: RenderContext) in RenderVM.shared!.itemPositions = c.itemPositions },
+1 -3
View File
@@ -55,9 +55,7 @@ RenderContext:
RenderComponent:
type: component
oneliners:
- didPrepareGL: renderInit(RenderVM.shared!)
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
- didPrepareGL: renderStartTimer(RenderVM.shared!)
- didPrepareGL: renderPrepareGL(RenderVM.shared!)
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
- willDeinit: renderDeinit(RenderVM.shared!)
- willRecreateSurface: renderRecreateSurface(RenderVM.shared!)
@@ -516,10 +516,8 @@ fun hrbRegisterEffects(ctrl: DialectController) {
fun renderRegisterEffects(ctrl: DialectController) {
registerOneliners(ctrl, arrayOf(
F.didPrepareGL, { c: RenderContext -> renderInit(RenderVM.shared!!) },
F.didPrepareGL, { c: RenderContext -> RenderVM.shared!!.didPrepareGL = true },
F.didPrepareGL, { c: RenderContext -> renderStartTimer(RenderVM.shared!!) },
F.pixelSize, { c: RenderContext -> RenderVM.shared!!.pixelSize = c.pixelSize },
F.didPrepareGL, { c: RenderContext -> renderPrepareGL(RenderVM.shared!!) },
F.pixelSize, { c: RenderContext -> RenderVM.shared!!.pixelSize = c.pixelSize },
F.willDeinit, { c: RenderContext -> renderDeinit(RenderVM.shared!!) },
F.willRecreateSurface, { c: RenderContext -> renderRecreateSurface(RenderVM.shared!!) },
@@ -4,7 +4,7 @@ import android.content.Context
object RenderVM {
var androidContext: Context? = null
@Volatile var didPrepareGL = false
var didPrepareGL = false
var glView: RenderGLView? = null
@Volatile var pixelSize = arrayOf<Int>()
+1 -3
View File
@@ -509,9 +509,7 @@ func hrbRegisterEffects(_ ctrl: DialectController) {
func renderRegisterEffects(_ ctrl: DialectController) {
let _: RenderContext? = registerOneliners(ctrl, [
F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) },
F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true },
F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
F.didPrepareGL, { (c: RenderContext) in renderPrepareGL(RenderVM.shared!) },
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) },
F.willRecreateSurface, { (c: RenderContext) in renderRecreateSurface(RenderVM.shared!) },
+1 -3
View File
@@ -99,9 +99,7 @@ RenderComponent:
oneliners:
- cameraPosition: RenderVM.shared!.cameraPosition = c.cameraPosition
- cameraZoom: RenderVM.shared!.cameraZoom = c.cameraZoom
- didPrepareGL: renderInit(RenderVM.shared!)
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
- didPrepareGL: renderStartTimer(RenderVM.shared!)
- didPrepareGL: renderPrepareGL(RenderVM.shared!)
- items: RenderVM.shared!.items = c.items
- pointerDownPos: hstSet(F.pointerDownPos, c.pointerDownPos)
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
@@ -716,15 +716,13 @@ fun renderRegisterEffects(ctrl: DialectController) {
registerOneliners(ctrl, arrayOf(
F.cameraPosition, { c: RenderContext -> RenderVM.shared!!.cameraPosition = c.cameraPosition },
F.cameraZoom, { c: RenderContext -> RenderVM.shared!!.cameraZoom = c.cameraZoom },
F.didPrepareGL, { c: RenderContext -> renderInit(RenderVM.shared!!) },
F.didPrepareGL, { c: RenderContext -> RenderVM.shared!!.didPrepareGL = true },
F.didPrepareGL, { c: RenderContext -> renderStartTimer(RenderVM.shared!!) },
F.didPrepareGL, { c: RenderContext -> renderPrepareGL(RenderVM.shared!!) },
F.items, { c: RenderContext -> RenderVM.shared!!.items = c.items },
F.pointerDownPos, { c: RenderContext -> hstSet(F.pointerDownPos, c.pointerDownPos) },
F.pixelSize, { c: RenderContext -> RenderVM.shared!!.pixelSize = c.pixelSize },
F.selectedItemId, { c: RenderContext -> RenderVM.shared!!.selectedItemId = c.selectedItemId },
F.pixelSize, { c: RenderContext -> RenderVM.shared!!.pixelSize = c.pixelSize },
F.selectedItemId, { c: RenderContext -> RenderVM.shared!!.selectedItemId = c.selectedItemId },
F.willDeinit, { c: RenderContext -> renderDeinit(RenderVM.shared!!) },
F.willRecreateSurface, { c: RenderContext -> renderRecreateSurface(RenderVM.shared) },
F.willRecreateSurface, { c: RenderContext -> renderRecreateSurface(RenderVM.shared!!) },
))
}
@@ -6,7 +6,7 @@ object RenderVM {
var androidContext: Context? = null
var cameraPosition = arrayOf<Float>()
var cameraZoom = 0f
@Volatile var didPrepareGL = false
var didPrepareGL = false
var glView: RenderGLView? = null
var items = arrayOf<HSTItem>()
@Volatile var pixelSize = arrayOf<Int>()
@@ -718,9 +718,7 @@ func renderRegisterEffects(_ ctrl: DialectController) {
let _: RenderContext? = registerOneliners(ctrl, [
F.cameraPosition, { (c: RenderContext) in RenderVM.shared!.cameraPosition = c.cameraPosition },
F.cameraZoom, { (c: RenderContext) in RenderVM.shared!.cameraZoom = c.cameraZoom },
F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) },
F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true },
F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
F.didPrepareGL, { (c: RenderContext) in renderPrepareGL(RenderVM.shared!) },
F.items, { (c: RenderContext) in RenderVM.shared!.items = c.items },
F.pointerDownPos, { (c: RenderContext) in hstSet(F.pointerDownPos, c.pointerDownPos) },
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },