From 971eb34a41ab7563d74fa21f4c5553da4418d585 Mon Sep 17 00:00:00 2001 From: soywiz Date: Sat, 15 May 2021 11:24:50 +0200 Subject: [PATCH] Update to Korge 2.1.1.1 --- gradle.properties | 5 +- gradle/wrapper/gradle-wrapper.properties | 2 +- samples/box2d/build.gradle.kts | 2 +- samples/bunnymark-fast/.gitignore | 1 + samples/bunnymark-fast/build.gradle | 7 + .../src/commonMain/kotlin/main.kt | 167 ++++++++++++++++++ .../src/commonMain/resources/bunnys.png | Bin 0 -> 1887 bytes .../bunnymark/src/commonMain/kotlin/main.kt | 4 +- .../coroutine/src/commonMain/kotlin/main.kt | 1 + .../polyphonic/src/commonMain/kotlin/main.kt | 2 +- samples/ui/src/commonMain/kotlin/SampleUi.kt | 25 ++- settings.gradle | 2 - 12 files changed, 196 insertions(+), 22 deletions(-) create mode 100644 samples/bunnymark-fast/.gitignore create mode 100644 samples/bunnymark-fast/build.gradle create mode 100644 samples/bunnymark-fast/src/commonMain/kotlin/main.kt create mode 100644 samples/bunnymark-fast/src/commonMain/resources/bunnys.png diff --git a/gradle.properties b/gradle.properties index 4a9a43e..4372330 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,9 @@ -korgePluginVersion=2.0.9.1 +korgePluginVersion=2.1.1.1 +#korgePluginVersion=2.0.0.999 web.bind.port=8080 -org.gradle.jvmargs=-Xmx3g +org.gradle.jvmargs=-Xmx5g org.gradle.parallel=true org.gradle.parallel.intra=true org.gradle.configureondemand=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 442d913..0f80bbf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/samples/box2d/build.gradle.kts b/samples/box2d/build.gradle.kts index ca82b84..0713afb 100644 --- a/samples/box2d/build.gradle.kts +++ b/samples/box2d/build.gradle.kts @@ -11,7 +11,7 @@ korge { //admob("ca-app-pub-xxxxxxxx~yyyyyy") - bundle("https://github.com/korlibs/korge-bundles.git::korge-box2d::73daf015ca725cc2717fa74213bc870e770ee2cd##fb2e67184e3374a53ba3ab43c28bbe78eeca070a76c3df4f565df169bbede60b") + bundle("https://github.com/korlibs/korge-bundles.git::korge-box2d::7439e5c7de7442f2cd33a1944846d44aea31af0a##9fd9d54abd8abc4736fd3439f0904141d9b6a26e9e2f1e1f8e2ed10c51f490fd") targetDefault() } diff --git a/samples/bunnymark-fast/.gitignore b/samples/bunnymark-fast/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/samples/bunnymark-fast/.gitignore @@ -0,0 +1 @@ +/build diff --git a/samples/bunnymark-fast/build.gradle b/samples/bunnymark-fast/build.gradle new file mode 100644 index 0000000..c769576 --- /dev/null +++ b/samples/bunnymark-fast/build.gradle @@ -0,0 +1,7 @@ +import com.soywiz.korge.gradle.* + +apply plugin: KorgeGradlePlugin + +korge { + targetDefault() +} diff --git a/samples/bunnymark-fast/src/commonMain/kotlin/main.kt b/samples/bunnymark-fast/src/commonMain/kotlin/main.kt new file mode 100644 index 0000000..0bafbcd --- /dev/null +++ b/samples/bunnymark-fast/src/commonMain/kotlin/main.kt @@ -0,0 +1,167 @@ +import com.soywiz.kds.* +import com.soywiz.kmem.* +import com.soywiz.korag.* +import com.soywiz.korag.shader.* +import com.soywiz.korge.* +import com.soywiz.korge.input.* +import com.soywiz.korge.render.* +import com.soywiz.korge.resources.* +import com.soywiz.korge.view.* +import com.soywiz.korim.bitmap.* +import com.soywiz.korim.bitmap.effect.* +import com.soywiz.korim.color.* +import com.soywiz.korim.font.* +import com.soywiz.korim.format.* +import com.soywiz.korio.file.std.* +import com.soywiz.korio.resources.* +import com.soywiz.korio.lang.* +import com.soywiz.korio.async.* +import com.soywiz.korma.geom.* +import kotlin.random.* +import com.soywiz.klock.* +import com.soywiz.korge.view.fast.* + +// @TODO: We could autogenerate this via gradle +val ResourcesContainer.korge_png by resourceBitmap("korge.png") + +class BunnyContainer(maxSize: Int) : FSprites(maxSize) { + val speeds = FBuffer(maxSize * Float.SIZE_BYTES * 2).f32 + var FSprite.speedXf: Float get() = speeds[index * 2 + 0] ; set(value) { speeds[index * 2 + 0] = value } + var FSprite.speedYf: Float get() = speeds[index * 2 + 1] ; set(value) { speeds[index * 2 + 1] = value } + //var FSprite.tex: BmpSlice +} + +/* +class Bunny(tex: BmpSlice) : FastSprite(tex) { + var speedXf: Float = 0f + var speedYf: Float = 0f +} +*/ + +// bunnymark ported from PIXI.js +// https://www.goodboydigital.com/pixijs/bunnymark/ +// https://www.goodboydigital.com/pixijs/bunnymark/js/bunnyBenchMark.js +suspend fun main() = Korge(width = 800, height = 600, bgcolor = Colors["#2b2b9b"], batchMaxQuads = BatchBuilder2D.MAX_BATCH_QUADS) { + println("currentThreadId=$currentThreadId") + delay(1.milliseconds) + println("currentThreadId=$currentThreadId") + println("ag.graphicExtensions=${ag.graphicExtensions}") + println("ag.isFloatTextureSupported=${ag.isFloatTextureSupported}") + println("ag.isInstancedSupported=${ag.isInstancedSupported}") +//suspend fun main() = Korge(width = 800, height = 600, bgcolor = Colors["#2b2b9b"]) { + val wabbitTexture = resourcesVfs["bunnys.png"].readBitmap() + + val bunny1 = wabbitTexture.sliceWithSize(2, 47, 26, 37) + val bunny2 = wabbitTexture.sliceWithSize(2, 86, 26, 37) + val bunny3 = wabbitTexture.sliceWithSize(2, 125, 26, 37) + val bunny4 = wabbitTexture.sliceWithSize(2, 164, 26, 37) + val bunny5 = wabbitTexture.sliceWithSize(2, 2, 26, 37) + + val startBunnyCount = 2 + //val startBunnyCount = 1_000_000 + // val startBunnyCount = 200_000 + val bunnyTextures = listOf(bunny1, bunny2, bunny3, bunny4, bunny5) + var currentTexture = bunny1 + + val bunnys = BunnyContainer(800_000) + addChild(bunnys.createView(wabbitTexture)) + + val font = DefaultTtfFont.toBitmapFont(fontSize = 16.0, effect = BitmapEffect(dropShadowX = 1, dropShadowY = 1, dropShadowRadius = 1)) + val bunnyCountText = text("", font = font, textSize = 16.0, alignment = com.soywiz.korim.text.TextAlignment.TOP_LEFT).position(16.0, 16.0) + + + val random = Random(0) + + fun addBunny(count: Int = 1) { + for (n in 0 until kotlin.math.min(count, bunnys.available)) { + bunnys.apply { + val bunny = alloc() + bunny.speedXf = random.nextFloat() * 1 + bunny.speedYf = (random.nextFloat() * 1) - 5 + bunny.setAnchor(.5f, 1f) + //bunny.width = 10f + //bunny.height = 20f + //bunny.alpha = 0.3f + random.nextFloat() * 0.7f + bunny.setTex(currentTexture) + bunny.scale(0.5f + random.nextFloat() * 0.5f) + bunny.radiansf = (random.nextFloat() - 0.5f) + } + } + bunnyCountText.text = "(WIP) KorGE Bunnymark. Bunnies: ${bunnys.size}" + } + + addBunny(startBunnyCount) + + val maxX = width.toFloat() + val minX = 0f + val maxY = height.toFloat() + val minY = 0f + val gravity = 0.5f // 1.5f + + mouse { + up { + currentTexture = bunnyTextures.random(random) + } + } + + addUpdater { + if (views.input.mouseButtons != 0) { + if (bunnys.size < 200_000) { + addBunny(2_000) + } else if (bunnys.size < bunnys.maxSize - 1000) { + addBunny(4_000) + } + } + bunnys.fastForEach { bunny -> + bunny.x += bunny.speedXf + bunny.y += bunny.speedYf + bunny.speedYf += gravity + + if (bunny.x > maxX) { + bunny.speedXf *= -1 + bunny.x = maxX + } else if (bunny.x < minX) { + bunny.speedXf *= -1 + bunny.x = minX + } + + if (bunny.y > maxY) { + bunny.speedYf *= -0.85f + bunny.y = maxY + bunny.radiansf = (random.nextFloat() - 0.5f) * 0.2f + if (random.nextFloat() > 0.5) { + bunny.speedYf -= random.nextFloat() * 6 + } + } else if (bunny.y < minY) { + bunny.speedYf = 0f + bunny.y = minY + } + } + } +} + + +/* +suspend fun main() { + //GLOBAL_CHECK_GL = true + Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"], clipBorders = false) { + gameWindow.icon = korge_png.get().bmp.toBMP32().scaled(32, 32) + val minDegrees = (-16).degrees + val maxDegrees = (+16).degrees + val image = image(korge_png) { + //val image = image(resourcesVfs["korge.png"].readbitmapslice) { + rotation = maxDegrees + anchor(.5, .5) + scale(.8) + position(256, 256) + } + addChild(MyView()) + //bindLength(image::scaledWidth) { 100.vw } + //bindLength(image::scaledHeight) { 100.vh } + while (true) { + image.tween(image::rotation[minDegrees], time = 1.seconds, easing = Easing.EASE_IN_OUT) + image.tween(image::rotation[maxDegrees], time = 1.seconds, easing = Easing.EASE_IN_OUT) + } + } +} +*/ diff --git a/samples/bunnymark-fast/src/commonMain/resources/bunnys.png b/samples/bunnymark-fast/src/commonMain/resources/bunnys.png new file mode 100644 index 0000000000000000000000000000000000000000..7010eb274c53d0108799bcadb14ac743afd767fe GIT binary patch literal 1887 zcmV-l2cY0003CP)t-s00000 z006-<)50>;hhG3?hX4SDctCE40O|h#w9){x(PoDL0P6pUU;saEhCgkF09|JQUS|ME zROLMSyM+LYy8!7y0RR902{Zoyxu^iSsQ`v}P>88OZia_*{)ck@hjagkT$-&i zx`Y6Vx&Vs1006kC09;h+K>$#RsZfZhQHiOVbN`U{|Bv?nhg<5wGSu#=0JHA^0PNKO zT~rD){{V$|UZTi^4gmiq0GV_DkN5xOJ^SW8`|hX!v+e+Ye}4dTeFR=<|3Lq=?*QsT z008UN_Oku%Mi9qYUox@dIFXdaw&d86FXRJilQx97HsBl(0u6<>-~W^J zKf6*aYbP%4qmNM{P4>5Qt~BrE(WCDsLdk=ySS*&yWp;-k0!&xg;DR7=DJ2ww1;aQ?Y@4r?Ttz>g8Kb>3>V zs?}zz^{kb`J3ITWX6vYR)NHos8gItl**O4cwbU^ zi0t1S!Fr=Dj|sQmYU|$-dw;X(I|s+$$H%lmrB>WLGO}(Te|Y=ht;QntinX5;|MZFO z?RMg&6Pau#Ym0XK`EmOeO;_Nr$OxB!Sg4e&_xZO}TXfRzYrdSq>DKsN<2S=@N ztfZ{BV_JPL68lW-JdA@t296_y<3M3j>wpFj+#JR^C^$Vj941@h{OaAXW~7CSLs1g!No=eujnI^PYp zI^PYV;Gh9lHx6=vPlet#E^|j8w!>QIz&`5JVGDBtI$6j^#u|mig9~Xe)`HX5nF~&5 zaqeH@A3C_)+45pW!{cJPoGp#aT^uE?iY}Cyf#X%B@YV{utTnCnL?TKGyRzGLg>ZYW zbUEDXxwyGq+!^Pt0%`|qjc#;%ZVwO68p~2|l7h!VV*`6VD|45#S>!_GAthRK(Kp2C;-WtigR4}E8ipHP>A{uH16?dH zmNU3;jm!xz)%QJHx;+z@+>2;B%zCDEDeul=?6UaYy357xZL`iNop-s^{=vFCiz#P~ zM$TsVMyPe1bJbRAY_H39%~gk!ciFnTZi!(2ONp)9jRzM_kFgesJWO0l;4h4G!Rg29%rX+=*Jo%Y^^aT+{>=TMh@lTA{NVry`U;TK&VUl{ij{6ml=`?81ReEq~ zQ?x`oxk?PK0;H~&rL1c$I=>hTVSJERF{kTEJkD2(%p+zAyfvgDX6R(C|3@`c)~L z*uzoY5FSO!CLUt-G{(HO!lZmPaER5>797gZ^MnXTp7a>(jl9takQ6gDz+njc5Ep~R z%d?mIZBUAV&(6*?R?5THe{j}_I`SaM!3&wLji@XV>^n^lF3%f!VsFp4EMJU9qnpIw zvMg&4Zo~LRM&;qnO?+&?70aiZDe}F9USe=r6-tTPg4lEU literal 0 HcmV?d00001 diff --git a/samples/bunnymark/src/commonMain/kotlin/main.kt b/samples/bunnymark/src/commonMain/kotlin/main.kt index e333b9f..cfd936d 100644 --- a/samples/bunnymark/src/commonMain/kotlin/main.kt +++ b/samples/bunnymark/src/commonMain/kotlin/main.kt @@ -23,7 +23,7 @@ import kotlin.random.Random class Bunny(tex: BmpSlice) : FastSprite(tex) { // Temporal placeholder until FastSpriteContainer supports rotation - var rotationRadiansf: Float = 0f + //override var rotationRadiansf: Float = 0f var speedXf: Float = 0f var speedYf: Float = 0f var spinf: Float = 0f @@ -72,7 +72,7 @@ suspend fun main() = Korge(width = 800, height = 600, bgcolor = Colors["#2b2b9b" bunny.anchorXf = .5f bunny.anchorYf = 1f //bunny.alpha = 0.3 + Math.random() * 0.7; - bunny.scalef = 0.5f + random.nextFloat() * 0.5f + bunny.scale(0.5f + random.nextFloat() * 0.5f) bunny.rotationRadiansf = (random.nextFloat() - 0.5f) //bunny.rotation = Math.random() - 0.5; //var random = random.nextInt(0, container.numChildren-2); diff --git a/samples/coroutine/src/commonMain/kotlin/main.kt b/samples/coroutine/src/commonMain/kotlin/main.kt index 6cab11f..50e8ce1 100644 --- a/samples/coroutine/src/commonMain/kotlin/main.kt +++ b/samples/coroutine/src/commonMain/kotlin/main.kt @@ -16,6 +16,7 @@ suspend fun main() = Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b" view.position(random[0, 512], random[0, 512]) frameBlock(60.timesPerSecond) { + //view.frameBlock(60.timesPerSecond) { while (true) { val targetX = random[0, 512].toDouble() val targetY = random[0, 512].toDouble() diff --git a/samples/polyphonic/src/commonMain/kotlin/main.kt b/samples/polyphonic/src/commonMain/kotlin/main.kt index 8572817..7da7935 100644 --- a/samples/polyphonic/src/commonMain/kotlin/main.kt +++ b/samples/polyphonic/src/commonMain/kotlin/main.kt @@ -397,7 +397,7 @@ fun audioOutCallback(channel: Int, buf: ShortArray, reqn: Int = buf.size, bufn: state.currentsampleIndex += state.currentsampleIncrement if (state.currentsampleIndex >= SAMPLE_COUNT) state.currentsampleIndex -= SAMPLE_COUNT.toFloat() } - val rvalue = value.clamp(Short.MIN_VALUE.toFloat(), Short.MAX_VALUE.toFloat()).toShort() + val rvalue = value.clamp(Short.MIN_VALUE.toFloat(), Short.MAX_VALUE.toFloat()).toInt().toShort() //for (n in 0 until nchannels) buf[bufn++] = value.toShort() buf[bufn++] = rvalue //buf[bufn++] = rvalue diff --git a/samples/ui/src/commonMain/kotlin/SampleUi.kt b/samples/ui/src/commonMain/kotlin/SampleUi.kt index 2fa0705..f6354fd 100644 --- a/samples/ui/src/commonMain/kotlin/SampleUi.kt +++ b/samples/ui/src/commonMain/kotlin/SampleUi.kt @@ -18,10 +18,12 @@ import com.soywiz.korma.interpolation.* suspend fun main() = Korge(quality = GameWindow.Quality.PERFORMANCE, title = "UI") { val nativeProcess = NativeProcess(views) - defaultUISkin = OtherUISkin() - defaultUIFont = resourcesVfs["uifont.fnt"].readBitmapFont() + //uiSkin = + //uiSkin = OtherUISkin().also { + // it.textFont = resourcesVfs["uifont.fnt"].readBitmapFont() + //} - uiTextButton(256.0, 32.0) { + uiButton(256.0, 32.0) { text = "Disabled Button" position(128, 128) onClick { @@ -29,7 +31,7 @@ suspend fun main() = Korge(quality = GameWindow.Quality.PERFORMANCE, title = "UI } disable() } - uiTextButton(256.0, 32.0) { + uiButton(256.0, 32.0) { text = "Enabled Button" position(128, 128 + 32) onClick { @@ -90,13 +92,10 @@ suspend fun OtherUISkin(): UISkin = OtherUISkinOnce { //val ui = resourcesVfs["korge-ui.png"].readNativeImage().toBMP32().withColorTransform(otherColorTransform) val ui = resourcesVfs["korge-ui.png"].readNativeImage() - DefaultUISkin.copy( - normal = ui.sliceWithSize(0, 0, 64, 64), - over = ui.sliceWithSize(64, 0, 64, 64), - down = ui.sliceWithSize(127, 0, 64, 64), - backColor = DefaultUISkin.backColor.transform(otherColorTransform) - //, - //font = Html.FontFace.Bitmap(getDebugBmpFontOnce()) - //font = Html.FontFace.Bitmap(resourcesVfs["uifont.fnt"].readBitmapFontWithMipmaps()) - ) + UISkin { + buttonNormal = ui.sliceWithSize(0, 0, 64, 64).asNinePatchSimpleRatio(0.25, 0.25, 0.75, 0.75) + buttonOver = ui.sliceWithSize(64, 0, 64, 64).asNinePatchSimpleRatio(0.25, 0.25, 0.75, 0.75) + buttonDown = ui.sliceWithSize(127, 0, 64, 64).asNinePatchSimpleRatio(0.25, 0.25, 0.75, 0.75) + buttonBackColor = buttonBackColor.transform(otherColorTransform) + } } diff --git a/settings.gradle b/settings.gradle index 3d29810..c620afb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,3 @@ -enableFeaturePreview("GRADLE_METADATA") - /* for (file in rootDir.listFiles()) { if (file.isDirectory() && file.name.startsWith("") && (new File(file, "build.gradle").exists() || new File(file, "build.gradle.kts").exists())) {