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

Commit

Permalink
Improve KorgeAndroidView
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jun 9, 2022
1 parent fde2b50 commit ece3619
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,53 +33,55 @@ open class KorgeAndroidView(
private val renderEvent = RenderEvent()
private val initEvent = InitEvent()

private var moduleLoaded = false
var moduleLoaded = false ; private set

fun unloadModule() {
if (moduleLoaded) {
if (!moduleLoaded) return

gameWindow?.dispatchDestroyEvent()
gameWindow?.coroutineContext = null
gameWindow?.close()
gameWindow?.exit()
mGLView = null
gameWindow = null
agOpenGl = null
cleanUpResourcesVfs()
gameWindow?.dispatchDestroyEvent()
gameWindow?.coroutineContext = null
gameWindow?.close()
gameWindow?.exit()
mGLView = null
gameWindow = null
agOpenGl = null
cleanUpResourcesVfs()

CoroutineScope(Dispatchers.Main).launch {
mGLView?.let { removeView(it) }
}

moduleLoaded = false
CoroutineScope(Dispatchers.Main).launch {
mGLView?.let { removeView(it) }
}

moduleLoaded = false
}

fun loadModule(module: Module) {
if (!moduleLoaded) {
agOpenGl = AndroidAGOpengl(context, agCheck = false) { mGLView }
gameWindow = AndroidGameWindowNoActivity(module.windowSize.width, module.windowSize.height, agOpenGl!!, context, config) { mGLView!! }
mGLView = com.soywiz.korgw.KorgwSurfaceView(this, context, gameWindow!!)
loadModule(Korge.Config(module))
}

addView(mGLView)
fun loadModule(config: Korge.Config) {
unloadModule() // Unload module if already loaded

gameWindow?.let { gameWindow ->
agOpenGl = AndroidAGOpengl(context, agCheck = false) { mGLView }
gameWindow = AndroidGameWindowNoActivity(config.windowSize.width, config.windowSize.height, agOpenGl!!, context, this.config) { mGLView!! }
mGLView = com.soywiz.korgw.KorgwSurfaceView(this, context, gameWindow!!)

Korio(context) {
try {
withAndroidContext(context) {
withContext(coroutineContext + gameWindow) {
Korge(Korge.Config(module = module))
}
addView(mGLView)

gameWindow?.let { gameWindow ->
Korio(context) {
try {
withAndroidContext(context) {
withContext(coroutineContext + gameWindow) {
Korge(config)
}
} finally {
println("${javaClass.name} completed!")
}
} finally {
println("${javaClass.name} completed!")
}
}

moduleLoaded = true
}

moduleLoaded = true
}

fun queueEvent(runnable: Runnable) {
Expand Down
4 changes: 2 additions & 2 deletions korge/src/commonMain/kotlin/com/soywiz/korge/Korge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ object Korge {
val gameId: String = DEFAULT_GAME_ID,
val settingsFolder: String? = null,
val batchMaxQuads: Int = BatchBuilder2D.DEFAULT_BATCH_QUADS,
val virtualSize: ISizeInt? = null,
val windowSize: ISizeInt? = null,
val virtualSize: ISizeInt = module.size,
val windowSize: ISizeInt = module.windowSize,
val scaleMode: ScaleMode? = null,
val scaleAnchor: Anchor? = null,
val clipBorders: Boolean? = null,
Expand Down

0 comments on commit ece3619

Please sign in to comment.