diff --git a/build.gradle.kts b/build.gradle.kts index ad48c3a..bba5005 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,6 @@ buildscript { mavenCentral() } dependencies { - classpath("com.soywiz:korge-gradle-plugin:1.1.0") + classpath("com.soywiz:korge-gradle-plugin:1.1.1") } } diff --git a/sample-dragonbones/src/commonMain/kotlin/main.kt b/sample-dragonbones/src/commonMain/kotlin/main.kt index 0efab00..7d0bdc5 100644 --- a/sample-dragonbones/src/commonMain/kotlin/main.kt +++ b/sample-dragonbones/src/commonMain/kotlin/main.kt @@ -1,9 +1,11 @@ import com.dragonbones.event.* import com.dragonbones.util.* import com.soywiz.klock.* +import com.soywiz.korev.* import com.soywiz.korge.* import com.soywiz.korge.dragonbones.* import com.soywiz.korge.input.* +import com.soywiz.korge.input.mouse import com.soywiz.korge.render.* import com.soywiz.korge.scene.* import com.soywiz.korge.tween.* @@ -49,7 +51,7 @@ suspend fun main(): Unit { suspend fun Stage.hello() { println("HelloScene.sceneInit[0]") - val bmp = resourcesVfs["atlas2/atlas2.png"].readBitmapOptimized() + val bmp = resourcesVfs["atlas2/atlas2.png"].readBitmap() //val bmp = Bitmap32(100, 100).apply { // context2d { // fillStyle = Context2d.Color(Colors.RED) @@ -121,42 +123,33 @@ open class MyModule : Module() { } abstract class MyBaseScene : Scene() { - fun launchAsap(callback: suspend () -> Unit) { - launchAsap(views.gameWindow.coroutineDispatcher, callback) - } - - fun async(callback: suspend () -> T): Deferred { - return async(views.gameWindow.coroutineDispatcher, callback) - } } class MyScene : MyBaseScene() { lateinit var buttonContainer: Container override suspend fun Container.sceneInit() { + addEventListener { + println("MouseEvent: ${views.nativeWidth},${views.nativeHeight} :: ${views.virtualWidth},${views.virtualHeight} :: $it") + } + val mySceneContainer = sceneContainer(views) { this.x = views.virtualWidth.toDouble() * 0.5 this.y = views.virtualHeight.toDouble() * 0.5 } buttonContainer = this this += Button("Hello") { - launchAsap { - println("Hello") - mySceneContainer.changeToDisablingButtons() - } + println("Hello") + mySceneContainer.changeToDisablingButtons() }.position(8, views.virtualHeight - 48) //this += Button("Classic") { mySceneContainer.changeToDisablingButtons() }.position(108, views.virtualHeight - 48) this += Button("Eye Tracking") { - launchAsap { - println("Eye Tracking") - mySceneContainer.changeToDisablingButtons() - } + println("Eye Tracking") + mySceneContainer.changeToDisablingButtons() }.position(200, views.virtualHeight - 48) this += Button("Skin Changing") { - launchAsap { - println("Skin Changing") - mySceneContainer.changeToDisablingButtons() - } + println("Skin Changing") + mySceneContainer.changeToDisablingButtons() }.position(600, views.virtualHeight - 48) mySceneContainer.changeToDisablingButtons() } @@ -177,7 +170,7 @@ class MyScene : MyBaseScene() { } } -class Button(text: String, handler: () -> Unit) : Container() { +class Button(text: String, handler: suspend () -> Unit) : Container() { val textField = Text(text, textSize = 32.0).apply { filtering = false } private val bounds = textField.textBounds val g = Graphics().apply { @@ -215,7 +208,11 @@ class Button(text: String, handler: () -> Unit) : Container() { over { overButton = true } out { overButton = false } } - onClick { if (enabledButton) handler() } + onClick { + stage?.views?.launchImmediately { + if (enabledButton) handler() + } + } updateState() } } @@ -223,10 +220,10 @@ class Button(text: String, handler: () -> Unit) : Container() { class HelloWorldScene : BaseDbScene() { val SCALE = 1.6 override suspend fun Container.sceneInit() { - val skeDeferred = async { Json.parse(resources["mecha_1002_101d_show/mecha_1002_101d_show_ske.json"].readString())!! } - //val skeDeferred = async { MemBufferWrap(resources["mecha_1002_101d_show/mecha_1002_101d_show_ske.dbbin"].readBytes()) } - val texDeferred = async { resources["mecha_1002_101d_show/mecha_1002_101d_show_tex.json"].readString() } - val imgDeferred = async { resources["mecha_1002_101d_show/mecha_1002_101d_show_tex.png"].readBitmapOptimized().mipmaps() } + val skeDeferred = asyncImmediately { Json.parse(resources["mecha_1002_101d_show/mecha_1002_101d_show_ske.json"].readString())!! } + //val skeDeferred = asyncImmediately { MemBufferWrap(resources["mecha_1002_101d_show/mecha_1002_101d_show_ske.dbbin"].readBytes()) } + val texDeferred = asyncImmediately { resources["mecha_1002_101d_show/mecha_1002_101d_show_tex.json"].readString() } + val imgDeferred = asyncImmediately { resources["mecha_1002_101d_show/mecha_1002_101d_show_tex.png"].readBitmap().mipmaps() } val data = factory.parseDragonBonesData(skeDeferred.await()) val atlas = factory.parseTextureAtlasData(Json.parse(texDeferred.await())!!, imgDeferred.await()) @@ -247,9 +244,9 @@ class ClassicDragonScene : BaseDbScene() { override suspend fun Container.sceneInit() { //val scale = 0.3 val scale = 0.8 - val ske = async { resources["Dragon/Dragon_ske.json"].readString() } - val tex = async { resources["Dragon/Dragon_tex.json"].readString() } - val img = async { resources["Dragon/Dragon_tex.png"].readBitmapOptimized() } + val ske = asyncImmediately { resources["Dragon/Dragon_ske.json"].readString() } + val tex = asyncImmediately { resources["Dragon/Dragon_tex.json"].readString() } + val img = asyncImmediately { resources["Dragon/Dragon_tex.png"].readBitmap() } val data = factory.parseDragonBonesData(Json.parse(ske.await())!!) @@ -283,11 +280,11 @@ class EyeTrackingScene : BaseDbScene() { "PARAM_BREATH" ) - val skeDeferred = async { resources["shizuku/shizuku_ske.json"].readString() } - val tex00Deferred = async { resources["shizuku/shizuku.1024/texture_00.png"].readBitmap().mipmaps() } - val tex01Deferred = async { resources["shizuku/shizuku.1024/texture_01.png"].readBitmap().mipmaps() } - val tex02Deferred = async { resources["shizuku/shizuku.1024/texture_02.png"].readBitmap().mipmaps() } - val tex03Deferred = async { resources["shizuku/shizuku.1024/texture_03.png"].readBitmap().mipmaps() } + val skeDeferred = asyncImmediately { resources["shizuku/shizuku_ske.json"].readString() } + val tex00Deferred = asyncImmediately { resources["shizuku/shizuku.1024/texture_00.png"].readBitmap().mipmaps() } + val tex01Deferred = asyncImmediately { resources["shizuku/shizuku.1024/texture_01.png"].readBitmap().mipmaps() } + val tex02Deferred = asyncImmediately { resources["shizuku/shizuku.1024/texture_02.png"].readBitmap().mipmaps() } + val tex03Deferred = asyncImmediately { resources["shizuku/shizuku.1024/texture_03.png"].readBitmap().mipmaps() } println("EyeTrackingScene[1]") @@ -406,15 +403,15 @@ class SkinChangingScene : BaseDbScene() { val deferreds = arrayListOf>() - deferreds += async { + deferreds += asyncImmediately { factory.parseDragonBonesData( Json.parse(resources["you_xin/body/body_ske.json"].readString())!! ) } - deferreds += async { + deferreds += asyncImmediately { val atlas = factory.parseTextureAtlasData( Json.parse(resources["you_xin/body/body_tex.json"].readString())!!, - resources["you_xin/body/body_tex.png"].readBitmapOptimized().mipmaps() + resources["you_xin/body/body_tex.png"].readBitmap().mipmaps() ) } @@ -426,11 +423,11 @@ class SkinChangingScene : BaseDbScene() { val textureAtlasJSONPath = path + "_tex.json" val textureAtlasPath = path + "_tex.png" // - deferreds += async { + deferreds += asyncImmediately { factory.parseDragonBonesData(Json.parse(resources[dragonBonesJSONPath].readString())!!) factory.parseTextureAtlasData( Json.parse(resources[textureAtlasJSONPath].readString())!!, - resources[textureAtlasPath].readBitmapOptimized().mipmaps() + resources[textureAtlasPath].readBitmap().mipmaps() ) } } diff --git a/sample-lipsync/build.gradle b/sample-lipsync/build.gradle index 93cc06b..861431b 100644 --- a/sample-lipsync/build.gradle +++ b/sample-lipsync/build.gradle @@ -2,4 +2,5 @@ apply plugin: "korge" korge { id = "com.soywiz.samples.lipsync" + dependencyMulti("com.soywiz:korau-mp3:$korauVersion") } diff --git a/sample-lipsync/src/commonMain/kotlin/main.kt b/sample-lipsync/src/commonMain/kotlin/main.kt index ee8e38b..dadbc17 100644 --- a/sample-lipsync/src/commonMain/kotlin/main.kt +++ b/sample-lipsync/src/commonMain/kotlin/main.kt @@ -26,6 +26,6 @@ suspend fun main() = Korge { resourcesVfs["002.voice.wav"].readVoice().play("lisa") { handler(it) } resourcesVfs["003.voice.wav"].readVoice().play("lisa") { handler(it) } resourcesVfs["004.voice.wav"].readVoice().play("lisa") { handler(it) } - resourcesVfs["simple.voice.wav"].readVoice().play("lisa") { handler(it) } + resourcesVfs["simple.voice.mp3"].readVoice().play("lisa") { handler(it) } } } diff --git a/sample-lipsync/src/commonMain/resources/empty.atlas b/sample-lipsync/src/commonMain/resources/empty.atlas new file mode 100644 index 0000000..e69de29 diff --git a/sample-lipsync/src/commonMain/resources/simple.voice.mp3 b/sample-lipsync/src/commonMain/resources/simple.voice.mp3 new file mode 100644 index 0000000..26d4e20 Binary files /dev/null and b/sample-lipsync/src/commonMain/resources/simple.voice.mp3 differ diff --git a/sample-lipsync/src/commonMain/resources/simple.voice.wav b/sample-lipsync/src/commonMain/resources/simple.voice.wav deleted file mode 100644 index 9a3c757..0000000 Binary files a/sample-lipsync/src/commonMain/resources/simple.voice.wav and /dev/null differ